Skip to content

Commit

Permalink
ConvexHull unit tests: Add a test for tetrahedron
Browse files Browse the repository at this point in the history
Added this due to a tiny (0 bytes alloc) memory leak in convhull_3d,
just to test if the generated hulls are ok (they are).

See:
leomccormack/convhull_3d#20
leomccormack/convhull_3d#21

Will commit a fix to the memory leak in a separate commit soon.
  • Loading branch information
GNSS-Stylist committed Nov 19, 2024
1 parent 67b1865 commit e199bb5
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
53 changes: 53 additions & 0 deletions UnitTests/tst_convexhull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,59 @@ void TestConvexHull::cubeInTheOrigin()
}
}


void TestConvexHull::tetrahedron()
{
ConvexHull hull;
ConvexHull::Filter filter;

Eigen::Vector3d vertices[4] =
{
{ 0, 0, -1 },
{-1, -1, 1 },
{-1, 1, 1 },
{ 1, 0, 1 }
};

for (int i = 0; i < 4; i++)
{
hull.addPoint(vertices[i]);
}

QVERIFY((hull.getFilter(filter)));
QVERIFY((filter.isValid()));
QCOMPARE(hull.getNumOfUniquePoints(), 4U);

// Test some points that should definitely be inside the hull

QVERIFY(filter.isInside(Eigen::Vector3d(0, 0, 0)));
QVERIFY(filter.isInside(Eigen::Vector3d(0, 0, -0.5)));
QVERIFY(filter.isInside(Eigen::Vector3d(0, 0, 0.5)));

// Test some points that should definitely be outside the hull

QVERIFY(!filter.isInside(Eigen::Vector3d(0, 0, -2)));
QVERIFY(!filter.isInside(Eigen::Vector3d(0, 0, -20)));
QVERIFY(!filter.isInside(Eigen::Vector3d(0, 0, 2)));
QVERIFY(!filter.isInside(Eigen::Vector3d(-2, 0, 0)));
QVERIFY(!filter.isInside(Eigen::Vector3d(2, 0, 0)));
QVERIFY(!filter.isInside(Eigen::Vector3d(0, 2, 0)));
QVERIFY(!filter.isInside(Eigen::Vector3d(0, -2, 0)));

// Close to vertices themselves ("close calls"):

QVERIFY(filter.isInside(0.999999 * vertices[0]));
QVERIFY(filter.isInside(0.999999 * vertices[1]));
QVERIFY(filter.isInside(0.999999 * vertices[2]));
QVERIFY(filter.isInside(0.999999 * vertices[3]));

QVERIFY(!filter.isInside(1.000001 * vertices[0]));
QVERIFY(!filter.isInside(1.000001 * vertices[1]));
QVERIFY(!filter.isInside(1.000001 * vertices[2]));
QVERIFY(!filter.isInside(1.000001 * vertices[3]));
}


void TestConvexHull::randomCubes()
{
const double lowLimit_Hull = -10;
Expand Down
1 change: 1 addition & 0 deletions UnitTests/tst_convexhull.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ private slots:
void cleanupTestCase();
void uninitialized();
void pointCountCheck();
void tetrahedron();
void cubeInTheOrigin();
void randomCubes();
void randomSpheres();
Expand Down

0 comments on commit e199bb5

Please sign in to comment.