Skip to content

Commit 39b0b80

Browse files
committed
ugly hack to work around #502
1 parent 7facd0e commit 39b0b80

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

src/polygon/src/polygon.cpp

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,13 @@ using namespace manifold;
3434

3535
ExecutionParams params;
3636

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
4239
bool OverlapAssert(bool condition, const char *file, int line,
4340
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);
4644
}
4745
return condition;
4846
}
@@ -66,6 +64,11 @@ bool OverlapAssert(bool condition, const char *file, int line,
6664
if (!OverlapAssert(condition, __FILE__, __LINE__, #condition, msg)) \
6765
return true;
6866

67+
#ifdef MANIFOLD_DEBUG
68+
struct PolyEdge {
69+
int startVert, endVert;
70+
};
71+
6972
#define PRINT(msg) \
7073
if (params.verbose) std::cout << msg << std::endl;
7174

@@ -188,8 +191,7 @@ void PrintFailure(const std::exception &e, const PolygonsIdx &polys,
188191
}
189192
}
190193
#else
191-
#define OVERLAP_ASSERT(condition, msg) \
192-
if (!(condition)) return true;
194+
// #define OVERLAP_ASSERT(condition, msg) if (!(condition)) return true;
193195
#define PRINT(msg)
194196
#endif
195197

@@ -199,7 +201,14 @@ void PrintFailure(const std::exception &e, const PolygonsIdx &polys,
199201
*/
200202
class Monotones {
201203
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+
203212
VertItr start, last, current;
204213
float bound = 0;
205214
for (const SimplePolygonIdx &poly : polys) {
@@ -1071,7 +1080,19 @@ std::vector<glm::ivec3> TriangulateIdx(const PolygonsIdx &polys,
10711080
float precision) {
10721081
std::vector<glm::ivec3> triangles;
10731082
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+
}
10751096
monotones.Triangulate(triangles);
10761097
#ifdef MANIFOLD_DEBUG
10771098
if (params.intermediateChecks) {

src/utilities/include/public.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#include <unordered_map>
2525
#include <vector>
2626

27-
#ifdef MANIFOLD_DEBUG
2827
#include <iomanip>
28+
#ifdef MANIFOLD_DEBUG
2929
#include <iostream>
3030
#include <sstream>
3131
#endif
@@ -414,14 +414,15 @@ class Quality {
414414
* Exceptions are only thrown if the MANIFOLD_EXCEPTIONS flag is set. Import and
415415
* Export of 3D models is only supported with the MANIFOLD_EXPORT flag, which
416416
* also requires linking in the Assimp dependency.
417+
*
418+
* FIXME: temporarily moved out of MANIFOLD_DEBUG guard for #502
417419
* @{
418420
*/
419421

420422
/** @defgroup Exceptions
421423
* @brief Custom Exceptions
422424
* @{
423425
*/
424-
#ifdef MANIFOLD_DEBUG
425426
struct userErr : public virtual std::runtime_error {
426427
using std::runtime_error::runtime_error;
427428
};
@@ -432,7 +433,6 @@ struct geometryErr : public virtual std::runtime_error {
432433
using std::runtime_error::runtime_error;
433434
};
434435
using logicErr = std::logic_error;
435-
#endif
436436
/** @} */
437437

438438
/**

0 commit comments

Comments
 (0)