Skip to content

Commit

Permalink
triangulator fix (elalish#509)
Browse files Browse the repository at this point in the history
* added tests

* revert param changes

* fixed Precision3 and Hole

* revert test change
  • Loading branch information
elalish authored Jul 31, 2023
1 parent 7c454dc commit abff7e8
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"-DMANIFOLD_EXPORT=ON",
"-DMANIFOLD_DEBUG=ON",
"-DMANIFOLD_USE_CUDA=OFF",
"-DMANIFOLD_PAR=NONE",
"-DMANIFOLD_PAR=TBB",
"-DCODE_COVERAGE=OFF",
"-DCMAKE_CXX_FLAGS=''" //'-fsanitize=address,undefined'"
],
Expand Down
4 changes: 2 additions & 2 deletions src/manifold/src/manifold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace {
using namespace manifold;
using namespace thrust::placeholders;

ExecutionParams params;
ExecutionParams manifoldParams;

struct MakeTri {
const Halfedge* halfedges;
Expand Down Expand Up @@ -775,7 +775,7 @@ Manifold Manifold::TrimByPlane(glm::vec3 normal, float originOffset) const {
return *this ^ Halfspace(BoundingBox(), normal, originOffset);
}

ExecutionParams& ManifoldParams() { return params; }
ExecutionParams& ManifoldParams() { return manifoldParams; }

/**
* Compute the convex hull of a set of points. If the given points are fewer
Expand Down
8 changes: 5 additions & 3 deletions src/polygon/src/polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
namespace {
using namespace manifold;

ExecutionParams params;
static ExecutionParams params;

#ifdef MANIFOLD_DEBUG
struct PolyEdge {
Expand Down Expand Up @@ -548,7 +548,8 @@ class Monotones {
return Skip;
}
} else {
if (!eastPair->vEast->right->IsPast(vert, precision_) &&
if (!vert->IsPast(vert->right, precision_) &&
!eastPair->vEast->right->IsPast(vert, precision_) &&
vert->IsPast(eastPair->vEast, precision_) &&
vert->pos.x > eastPair->vEast->right->pos.x + precision_) {
PRINT("Skip WEST");
Expand All @@ -560,7 +561,8 @@ class Monotones {
}
} else {
if (vert->left->Processed()) {
if (!westPair->vWest->left->IsPast(vert, precision_) &&
if (!vert->IsPast(vert->left, precision_) &&
!westPair->vWest->left->IsPast(vert, precision_) &&
vert->IsPast(westPair->vWest, precision_) &&
vert->pos.x < westPair->vWest->left->pos.x - precision_) {
PRINT("Skip EAST");
Expand Down
78 changes: 72 additions & 6 deletions test/polygon_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,10 +847,6 @@ TEST(Polygon, Precision) {
};

TEST(Polygon, Precision2) {
PolygonParams().processOverlaps = true;
const bool intermediateChecks = PolygonParams().intermediateChecks;
PolygonParams().intermediateChecks = false;

Polygons polys;
polys.push_back({
{4.98093176, -0.2479388121113}, //
Expand All @@ -873,9 +869,79 @@ TEST(Polygon, Precision2) {
{4.95041943, -0.2417418967819}, //
});
TestPoly(polys, 8);
};

TEST(Polygon, Precision3) {
Polygons polys;
polys.push_back({
{0.630340576, 1.6097908}, //
{0.777489543, 1.58760202}, //
{0.890084028, 1.60028839}, //
{1.05917394, 1.65945554}, //
{1.06027794, 1.65984178}, //
});
TestPoly(polys, 3, 0.00068);
};

TEST(Polygon, DISABLED_Sweep) {
Polygons polys;
polys.push_back({
{0, 0.637057483}, //
{0, 0.637057483}, //
{1.72745752, 4.72425699}, //
{1.72745752, 4.72425699}, //
{1.72745752, 4.72425699}, //
{1.7274611, 4.72425747}, //
{0, 0.637057483}, //
{2.5, 4.82678747}, //
{1.72745752, 4.72425747}, //
{0, 0.637057483}, //
{0, 0.637057483}, //
{0, 0.637057483}, //
{0, 0.637057483}, //
{0, 0.637057483}, //
});
TestPoly(polys, 12);
}

PolygonParams().processOverlaps = false;
PolygonParams().intermediateChecks = intermediateChecks;
TEST(Polygon, Hole) {
Polygons polys;
polys.push_back({
{0.5, -0.5}, //
{0.5, 0.5}, //
{-0.5, 0.5}, //
{-0.5, 0.5}, //
{-0.5, 0.5}, //
{-0, 0.5}, //
{-0.25, 0.25}, //
{0.25, -0.25}, //
{0.5, 0}, //
{0.5, 0}, //
{0.5, -0.5}, //
{0.5, -0.5}, //
{0.5, -0.5}, //
});
polys.push_back({
{0.5, 0}, //
{-0, 0.5}, //
{-0, 0.5}, //
{0.5, 0.5}, //
{0.5, 0.5}, //
{0.5, 0.5}, //
});
TestPoly(polys, 19);
}

TEST(Polygon, DISABLED_Small) {
Polygons polys;
polys.push_back({
{-0.487163663, 0.00357927009}, //
{-0.49125129, 0.244737789}, //
{-0.491251856, 0.24427411}, //
{-0.491260529, 0.245025411}, //
{-0.49067378, 6.32605588e-05}, //
});
TestPoly(polys, 3, 0.0001);
};

TEST(Polygon, Comb) {
Expand Down

0 comments on commit abff7e8

Please sign in to comment.