@@ -34,15 +34,13 @@ using namespace manifold;
34
34
35
35
ExecutionParams params;
36
36
37
- #ifdef MANIFOLD_DEBUG
38
- struct PolyEdge {
39
- int startVert, endVert;
40
- };
41
-
37
+ // FIXME: temporary hack to avoid a bug (#502) in the triangulator
38
+ // should be guarded by MANIFOLD_DEBUG if the workaround can be removed
42
39
bool OverlapAssert (bool condition, const char *file, int line,
43
40
const std::string &cond, const std::string &msg) {
44
- if (!params.processOverlaps ) {
45
- ASSERT (condition, geometryErr, msg);
41
+ if (!params.processOverlaps && !condition) {
42
+ throw geometryErr (msg);
43
+ // ASSERT(condition, geometryErr, msg);
46
44
}
47
45
return condition;
48
46
}
@@ -66,6 +64,11 @@ bool OverlapAssert(bool condition, const char *file, int line,
66
64
if (!OverlapAssert(condition, __FILE__, __LINE__, #condition, msg)) \
67
65
return true ;
68
66
67
+ #ifdef MANIFOLD_DEBUG
68
+ struct PolyEdge {
69
+ int startVert, endVert;
70
+ };
71
+
69
72
#define PRINT (msg ) \
70
73
if (params.verbose) std::cout << msg << std::endl;
71
74
@@ -188,8 +191,7 @@ void PrintFailure(const std::exception &e, const PolygonsIdx &polys,
188
191
}
189
192
}
190
193
#else
191
- #define OVERLAP_ASSERT (condition, msg ) \
192
- if (!(condition)) return true ;
194
+ // #define OVERLAP_ASSERT(condition, msg) if (!(condition)) return true;
193
195
#define PRINT (msg )
194
196
#endif
195
197
@@ -199,7 +201,14 @@ void PrintFailure(const std::exception &e, const PolygonsIdx &polys,
199
201
*/
200
202
class Monotones {
201
203
public:
202
- Monotones (const PolygonsIdx &polys, float precision) : precision_(precision) {
204
+ Monotones () {}
205
+ void Init (const PolygonsIdx &polys, float precision) {
206
+ // reset monotones
207
+ precision_ = precision;
208
+ monotones_.clear ();
209
+ activePairs_.clear ();
210
+ inactivePairs_.clear ();
211
+
203
212
VertItr start, last, current;
204
213
float bound = 0 ;
205
214
for (const SimplePolygonIdx &poly : polys) {
@@ -1071,7 +1080,19 @@ std::vector<glm::ivec3> TriangulateIdx(const PolygonsIdx &polys,
1071
1080
float precision) {
1072
1081
std::vector<glm::ivec3> triangles;
1073
1082
try {
1074
- Monotones monotones (polys, precision);
1083
+ Monotones monotones;
1084
+ if (params.processOverlaps ) {
1085
+ params.processOverlaps = false ;
1086
+ try {
1087
+ monotones.Init (polys, 0 );
1088
+ } catch (geometryErr &e) {
1089
+ params.processOverlaps = true ;
1090
+ monotones.Init (polys, precision);
1091
+ }
1092
+ params.processOverlaps = true ;
1093
+ } else {
1094
+ monotones.Init (polys, precision);
1095
+ }
1075
1096
monotones.Triangulate (triangles);
1076
1097
#ifdef MANIFOLD_DEBUG
1077
1098
if (params.intermediateChecks ) {
0 commit comments