aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/geo_alignedbox.cpp
diff options
context:
space:
mode:
authorGravatar Antonio Sanchez <cantonios@google.com>2020-09-30 08:21:20 -0700
committerGravatar Antonio Sanchez <cantonios@google.com>2020-09-30 08:42:03 -0700
commitd5a0d894915c19199590b32149834351b60e2fd1 (patch)
tree514a506ba166870a94664d1d60f107bc5051c74c /test/geo_alignedbox.cpp
parent30960d485ec7e45b095d3ad206b2dbcc8bc835ba (diff)
Fix alignedbox 32-bit precision test failure.
The current `test/geo_alignedbox` tests fail on 32-bit arm due to small floating-point errors. In particular, the following is not guaranteed to hold: ``` IsometryTransform identity = IsometryTransform::Identity(); BoxType transformedC; transformedC.extend(c.transformed(identity)); VERIFY(transformedC.contains(c)); ``` since `c.transformed(identity)` is ever-so-slightly different from `c`. Instead, we replace this test with one that checks an identity transform is within floating-point precision of `c`. Also updated the condition on `AlignedBox::transform(...)` to only accept `Affine`, `AffineCompact`, and `Isometry` modes explicitly. Otherwise, invalid combinations of modes would also incorrectly pass the assertion.
Diffstat (limited to 'test/geo_alignedbox.cpp')
-rw-r--r--test/geo_alignedbox.cpp20
1 files changed, 7 insertions, 13 deletions
diff --git a/test/geo_alignedbox.cpp b/test/geo_alignedbox.cpp
index 0a866a961..7ce640d81 100644
--- a/test/geo_alignedbox.cpp
+++ b/test/geo_alignedbox.cpp
@@ -47,7 +47,7 @@ template<typename BoxType> void alignedbox(const BoxType& _box)
BoxType b0(dim);
BoxType b1(VectorType::Random(dim),VectorType::Random(dim));
BoxType b2;
-
+
kill_extra_precision(b1);
kill_extra_precision(p0);
kill_extra_precision(p1);
@@ -69,7 +69,7 @@ template<typename BoxType> void alignedbox(const BoxType& _box)
BoxType box2(VectorType::Random(dim));
box2.extend(VectorType::Random(dim));
- VERIFY(box1.intersects(box2) == !box1.intersection(box2).isEmpty());
+ VERIFY(box1.intersects(box2) == !box1.intersection(box2).isEmpty());
// alignment -- make sure there is no memory alignment assertion
BoxType *bp0 = new BoxType(dim);
@@ -150,11 +150,9 @@ template<typename BoxType> void alignedboxTranslatable(const BoxType& _box)
VERIFY_IS_APPROX((c.min)(), UnitX * Scalar(9));
VERIFY_IS_APPROX((c.max)(), Ones * Scalar(18) + UnitX * Scalar(9));
- // test for roundoff errors
- IsometryTransform identity = IsometryTransform::Identity();
- BoxType transformedC;
- transformedC.extend(c.transformed(identity));
- VERIFY(transformedC.contains(c));
+ // Check identity transform within numerical precision.
+ BoxType transformedC = c.transformed(IsometryTransform::Identity());
+ VERIFY_IS_APPROX(transformedC, c);
for (size_t i = 0; i < 10; ++i)
{
@@ -335,10 +333,6 @@ template<typename BoxType, typename Rotation> void alignedboxNonIntegralRotatabl
const Index dim = _box.dim();
const VectorType Zero = VectorType::Zero();
const VectorType Ones = VectorType::Ones();
- const VectorType UnitX = VectorType::UnitX();
- const VectorType UnitY = VectorType::UnitY();
- // this is vector (0, 0, -1, -1, -1, ...), i.e. with zeros at first and second dimensions
- const VectorType UnitZ = Ones - UnitX - UnitY;
VectorType minPoint = -2 * Ones;
minPoint[1] = 1;
@@ -365,7 +359,7 @@ template<typename BoxType, typename Rotation> void alignedboxNonIntegralRotatabl
cornerBR = tf2 * cornerBR;
cornerTL = tf2 * cornerTL;
cornerTR = tf2 * cornerTR;
-
+
VectorType minCorner = Ones * Scalar(-2);
VectorType maxCorner = Zero;
minCorner[0] = (min)((min)(cornerBL[0], cornerBR[0]), (min)(cornerTL[0], cornerTR[0]));
@@ -471,7 +465,7 @@ template<typename BoxType, typename Rotation> void alignedboxNonIntegralRotatabl
template<typename BoxType>
void alignedboxCastTests(const BoxType& _box)
{
- // casting
+ // casting
typedef typename BoxType::Scalar Scalar;
typedef Matrix<Scalar, BoxType::AmbientDimAtCompileTime, 1> VectorType;