always retry geometry operations upon encountering TopologyExceptions
diff --git a/index.js b/index.js
index 3c4f184..23fb26a 100644
--- a/index.js
+++ b/index.js
@@ -27,9 +27,17 @@
})
}
-var debugGeo = function (op, a, b) {
+var debugGeo = function (op, a, b, reducePrecision) {
var result
+ if (reducePrecision) {
+ var precisionModel = new jsts.geom.PrecisionModel(10000)
+ var precisionReducer = new jsts.precision.GeometryPrecisionReducer(precisionModel)
+
+ a = precisionReducer.reduce(a)
+ b = precisionReducer.reduce(b)
+ }
+
try {
switch (op) {
case 'union':
@@ -42,28 +50,17 @@
result = a.intersects(b)
break
case 'diff':
- try {
- result = a.difference(b)
- } catch (e) {
- if (e.name === 'TopologyException') {
- console.log('retry with GeometryPrecisionReducer')
- var precisionModel = new jsts.geom.PrecisionModel(10000)
- var precisionReducer = new jsts.precision.GeometryPrecisionReducer(precisionModel)
-
- a = precisionReducer.reduce(a)
- b = precisionReducer.reduce(b)
-
- result = a.difference(b)
- } else {
- throw e
- }
- }
+ result = a.difference(b)
break
default:
var err = new Error('invalid op: ' + op)
throw err
}
} catch (e) {
+ if (e.name === 'TopologyException') {
+ console.log('Encountered TopologyException, retry with GeometryPrecisionReducer')
+ return debugGeo(op, a, b, true)
+ }
console.log('op err')
console.log(e)
console.log(e.stack)