@@ -344,6 +344,13 @@ class EarClip {
344
344
// it finds a clear geometric result. In the vast majority of cases the loop
345
345
// will only need one or two iterations.
346
346
bool IsConvex (float precision) const {
347
+ const int convexity = CCW (left->pos , pos, right->pos , precision);
348
+ if (convexity != 0 ) {
349
+ return convexity > 0 ;
350
+ }
351
+ if (glm::dot (left->pos - pos, right->pos - pos) <= 0 ) {
352
+ return true ;
353
+ }
347
354
return left->InsideEdge (left->right , precision, true );
348
355
}
349
356
@@ -363,8 +370,8 @@ class EarClip {
363
370
const auto none = std::make_pair (left, false );
364
371
if (pos.y < start.y && right->pos .y >= start.y ) {
365
372
return std::make_pair (left->right , true );
366
- } else if (pos. x > start. x - precision && pos.y > start.y - precision &&
367
- pos.y < start.y + precision &&
373
+ } else if (onTop != 0 && pos.x > start.x - precision &&
374
+ pos.y > start. y - precision && pos. y < start.y + precision &&
368
375
Interior (start, precision) >= 0 ) {
369
376
if (onTop > 0 && left->pos .x < pos.x &&
370
377
left->pos .y > start.y - precision) {
@@ -433,7 +440,7 @@ class EarClip {
433
440
float totalCost = glm::dot (left->rightDir , rightDir) - 1 - precision;
434
441
if (CCW (pos, left->pos , right->pos , precision) == 0 ) {
435
442
// Clip folded ears first
436
- return totalCost < - 1 ? kBest : 0 ;
443
+ return totalCost;
437
444
}
438
445
439
446
Vec<Box> earBox;
@@ -611,7 +618,7 @@ class EarClip {
611
618
areaCompensation += (area - t1) + area1;
612
619
area = t1;
613
620
614
- if (!v-> IsConvex (precision_) && v->pos .x > maxX) {
621
+ if (v->pos .x > maxX) {
615
622
maxX = v->pos .x ;
616
623
start = v;
617
624
}
@@ -754,6 +761,8 @@ class EarClip {
754
761
} else if (v->IsConvex (precision_)) {
755
762
v->cost = v->EarCost (precision_, collider);
756
763
v->ear = earsQueue_.insert (v);
764
+ } else {
765
+ v->cost = 1 ; // not used, but marks reflex verts for debug
757
766
}
758
767
}
759
768
@@ -852,6 +861,15 @@ class EarClip {
852
861
std::cout << " [" << v->pos .x << " , " << v->pos .y << " ],# " << v->mesh_idx
853
862
<< std::endl;
854
863
std::cout << " ]))" << std::endl;
864
+
865
+ v = start;
866
+ std::cout << " polys.push_back({" << std::setprecision (9 ) << std::endl;
867
+ do {
868
+ std::cout << " {" << v->pos .x << " , " << v->pos .y << " }, //"
869
+ << std::endl;
870
+ v = v->right ;
871
+ } while (v != start);
872
+ std::cout << " });" << std::endl;
855
873
#endif
856
874
}
857
875
};
@@ -875,23 +893,25 @@ namespace manifold {
875
893
std::vector<glm::ivec3> TriangulateIdx (const PolygonsIdx &polys,
876
894
float precision) {
877
895
std::vector<glm::ivec3> triangles;
896
+ float updatedPrecision = precision;
878
897
try {
879
898
EarClip triangulator (polys, precision);
899
+ updatedPrecision = triangulator.GetPrecision ();
880
900
triangles = triangulator.Triangulate ();
881
901
#ifdef MANIFOLD_DEBUG
882
902
if (params.intermediateChecks ) {
883
903
CheckTopology (triangles, polys);
884
904
if (!params.processOverlaps ) {
885
- CheckGeometry (triangles, polys, 2 * triangulator. GetPrecision () );
905
+ CheckGeometry (triangles, polys, 2 * updatedPrecision );
886
906
}
887
907
}
888
908
} catch (const geometryErr &e) {
889
909
if (!params.suppressErrors ) {
890
- PrintFailure (e, polys, triangles, precision );
910
+ PrintFailure (e, polys, triangles, updatedPrecision );
891
911
}
892
912
throw ;
893
913
} catch (const std::exception &e) {
894
- PrintFailure (e, polys, triangles, precision );
914
+ PrintFailure (e, polys, triangles, updatedPrecision );
895
915
throw ;
896
916
#else
897
917
} catch (const std::exception &e) {
0 commit comments