Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed triangulation bug #180

Merged
merged 1 commit into from
Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/manifold/src/manifold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ struct MakeTri {
}
};

struct GetMeshID {
__host__ __device__ void operator()(thrust::tuple<int&, BaryRef> inOut) {
thrust::get<0>(inOut) = thrust::get<1>(inOut).meshID;
}
};

Manifold Halfspace(Box bBox, glm::vec3 normal, float originOffset) {
normal = glm::normalize(normal);
Manifold cutter =
Expand Down
9 changes: 8 additions & 1 deletion src/polygon/src/polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ class Monotones {
#endif
}

float GetPrecision() const { return precision_; }

private:
struct VertAdj;
typedef std::list<VertAdj>::iterator VertItr;
Expand Down Expand Up @@ -812,7 +814,10 @@ class Monotones {
SetVEast(newPair, vert);
const int hole = IsHole(vert);
if (hole == 0 && IsColinearPoly(vert)) {
PRINT("Skip colinear polygon");
SkipPoly(vert);
activePairs_.erase(newPair);
continue;
}
isHole = hole > 0;
}
Expand Down Expand Up @@ -1032,7 +1037,9 @@ std::vector<glm::ivec3> Triangulate(const Polygons &polys, float precision) {
#ifdef MANIFOLD_DEBUG
if (params.intermediateChecks) {
CheckTopology(triangles, polys);
CheckGeometry(triangles, polys, precision);
if (!params.processOverlaps) {
CheckGeometry(triangles, polys, 2 * monotones.GetPrecision());
}
}
} catch (const geometryErr &e) {
if (!params.suppressErrors) {
Expand Down
5 changes: 1 addition & 4 deletions test/mesh_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,6 @@ TEST(Boolean, Subtract) {

TEST(Boolean, Close) {
PolygonParams().processOverlaps = true;
const bool intermediateChecks = PolygonParams().intermediateChecks;
PolygonParams().intermediateChecks = false;

const float r = 10;
Manifold a = Manifold::Sphere(r, 256);
Expand All @@ -1022,13 +1020,12 @@ TEST(Boolean, Close) {
EXPECT_TRUE(result.IsManifold());
}
auto prop = result.GetProperties();
const float tol = 0.002;
const float tol = 0.004;
EXPECT_NEAR(prop.volume, (4.0f / 3.0f) * glm::pi<float>() * r * r * r,
tol * r * r * r);
EXPECT_NEAR(prop.surfaceArea, 4 * glm::pi<float>() * r * r, tol * r * r);

if (options.exportModels) ExportMesh("close.glb", result.GetMesh(), {});

PolygonParams().processOverlaps = false;
PolygonParams().intermediateChecks = intermediateChecks;
}
94 changes: 94 additions & 0 deletions test/polygon_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,100 @@ TEST(Polygon, Merges) {
TestPoly(polys, 9);
}

TEST(Polygon, ExtraTriangle) {
Polygons polys;
polys.push_back({
{glm::vec2(1.23141634, -0.493547261), 0}, //
{glm::vec2(1.23142254, -0.493540883), 1}, //
{glm::vec2(1.23088336, -0.457464248), 2}, //
});
polys.push_back({
{glm::vec2(1.23146737, -0.493494928), 3}, //
{glm::vec2(1.47253549, -0.24623163), 4}, //
{glm::vec2(1.47253144, -0.246230021), 5}, //
{glm::vec2(1.47166216, -0.246238187), 6}, //
{glm::vec2(1.46963537, -0.24623026), 7}, //
{glm::vec2(1.46811843, -0.246224999), 8}, //
{glm::vec2(1.46594918, -0.246223733), 9}, //
{glm::vec2(1.46594965, -0.246232167), 10}, //
{glm::vec2(1.46594965, -0.246232241), 11}, //
{glm::vec2(1.46594083, -0.246223733), 12}, //
{glm::vec2(1.46591508, -0.246223718), 13}, //
{glm::vec2(1.46594179, -0.246231437), 14}, //
{glm::vec2(1.46585774, -0.246223688), 15}, //
{glm::vec2(1.46577716, -0.246223629), 16}, //
{glm::vec2(1.46590662, -0.246231213), 17}, //
{glm::vec2(1.46550393, -0.246223465), 18}, //
{glm::vec2(1.46081161, -0.246220738), 19}, //
{glm::vec2(1.46407437, -0.246228904), 20}, //
{glm::vec2(1.45568836, -0.246227756), 21}, //
{glm::vec2(1.42199826, -0.260253757), 22}, //
{glm::vec2(1.40801644, -0.246204734), 23}, //
{glm::vec2(1.40688479, -0.24620308), 24}, //
{glm::vec2(1.38571239, -0.246184081), 25}, //
{glm::vec2(1.30817795, -0.246158242), 26}, //
{glm::vec2(1.28997684, -0.328056872), 27}, //
{glm::vec2(1.30974603, -0.315009534), 28}, //
{glm::vec2(1.31756043, -0.364917517), 29}, //
});
TestPoly(polys, 26);
}

TEST(Polygon, DISABLED_SpongeThin) {
Polygons polys;
polys.push_back({
{glm::vec2(-0.5, -0.475308657), 11}, //
{glm::vec2(-0.487654328, -0.475461066), 12}, //
{glm::vec2(-0.487654328, -0.475308657), 13}, //
{glm::vec2(-0.487654328, -0.475308657), 14}, //
{glm::vec2(-0.487654328, -0.475308657), 15}, //
{glm::vec2(-0.475308657, -0.475308657), 16}, //
{glm::vec2(-0.475308657, -0.475613475), 17}, //
{glm::vec2(-0.462962985, -0.475765914), 18}, //
{glm::vec2(-0.462962985, -0.475308657), 19}, //
});
polys.push_back({
{glm::vec2(0.42592591, -0.475308657), 20}, //
{glm::vec2(0.351851851, -0.475308657), 21}, //
{glm::vec2(0.351851851, -0.475308657), 22}, //
{glm::vec2(0.351851851, -0.48582533), 23}, //
{glm::vec2(0.364197552, -0.485977769), 24}, //
{glm::vec2(0.364197552, -0.475308657), 25}, //
{glm::vec2(0.364197552, -0.475308657), 26}, //
{glm::vec2(0.364197552, -0.475308657), 27}, //
{glm::vec2(0.376543224, -0.475308657), 28}, //
{glm::vec2(0.376543224, -0.486130178), 29}, //
{glm::vec2(0.401234567, -0.486434996), 30}, //
{glm::vec2(0.401234567, -0.475308657), 31}, //
{glm::vec2(0.401234567, -0.475308657), 32}, //
{glm::vec2(0.401234567, -0.475308657), 33}, //
{glm::vec2(0.413580239, -0.475308657), 34}, //
{glm::vec2(0.413580239, -0.486587405), 35}, //
{glm::vec2(0.42592591, -0.486739844), 36}, //
});
polys.push_back({
{glm::vec2(0.314814806, -0.475308657), 37}, //
{glm::vec2(0.240740761, -0.475308657), 38}, //
{glm::vec2(0.240740761, -0.475308657), 39}, //
{glm::vec2(0.240740761, -0.484453589), 40}, //
{glm::vec2(0.253086448, -0.484606028), 41}, //
{glm::vec2(0.253086448, -0.475308657), 42}, //
{glm::vec2(0.253086448, -0.475308657), 43}, //
{glm::vec2(0.253086448, -0.475308657), 44}, //
{glm::vec2(0.265432119, -0.475308657), 45}, //
{glm::vec2(0.265432119, -0.484758437), 46}, //
{glm::vec2(0.290123463, -0.485063255), 47}, //
{glm::vec2(0.290123463, -0.475308657), 48}, //
{glm::vec2(0.290123463, -0.475308657), 49}, //
{glm::vec2(0.290123463, -0.475308657), 50}, //
{glm::vec2(0.302469134, -0.475308657), 51}, //
{glm::vec2(0.302469134, -0.485215664), 52}, //
{glm::vec2(0.314814806, -0.485368103), 53}, //
{glm::vec2(0.314814806, -0.475308657), 54}, //
});
TestPoly(polys, 7);
}

TEST(Polygon, ColinearY) {
Polygons polys;
polys.push_back({
Expand Down