From 4aa34230fdc033aeb31cc6fb6de70eacd732fb1b Mon Sep 17 00:00:00 2001 From: Mackenzie Salisbury Date: Wed, 8 Mar 2023 14:27:26 +1000 Subject: [PATCH] test: Add test for known case causing #124 --- test/duplicate-nodes-#124.js | 189 +++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 test/duplicate-nodes-#124.js diff --git a/test/duplicate-nodes-#124.js b/test/duplicate-nodes-#124.js new file mode 100644 index 0000000..bc7bb33 --- /dev/null +++ b/test/duplicate-nodes-#124.js @@ -0,0 +1,189 @@ +/* eslint-env jest */ + +import * as polygonclip from "../src" + +describe("polygon-clipping #124", () => { + test("doesn't throw with a case known to cause a stack overflow", () => { + const geom = [ + [ + [0, 0], + [4000, 0], + [4000, 1500], + [0, 1500], + [0, 0], + ], + ] + const geoms = [ + [ + [ + [4000, 182093], + [4000, 183750], + [0, 183750], + [-91875, 91875], + [-86218, 91875], + [4000, 182093], + ], + ], + [ + [ + [-86218, 91875], + [-91875, 91875], + [0, 0], + [4000, 0], + [4000, 1657], + [-86218, 91875], + ], + ], + [ + [ + [-868, 182882], + [3900, 182882], + [3900, 183750], + [0, 183750], + [-868, 182882], + ], + ], + [ + [ + [-1868, 181882], + [3789, 181882], + [3900, 181993], + [3900, 182882], + [-868, 182882], + [-1868, 181882], + ], + ], + [ + [ + [-91743, 92007], + [-86086, 92007], + [3789, 181882], + [-1868, 181882], + [-91743, 92007], + ], + ], + [ + [ + [3900, 868], + [-868, 868], + [0, 0], + [3900, 0], + [3900, 868], + ], + ], + [ + [ + [3900, 868], + [3900, 1757], + [3789, 1868], + [-1868, 1868], + [-868, 868], + [3900, 868], + ], + ], + [ + [ + [-91743, 91743], + [-1868, 1868], + [3789, 1868], + [-86086, 91743], + [-91743, 91743], + ], + ], + [ + [ + [3132, 182882], + [3998, 183750], + [0, 183750], + [-868, 182882], + [3132, 182882], + ], + ], + [ + [ + [3132, 182882], + [-868, 182882], + [-1500, 182250], + [2500, 182250], + [3132, 182882], + ], + ], + [ + [ + [0, 0], + [3998, 0], + [3132, 868], + [-868, 868], + [0, 0], + ], + ], + [ + [ + [-868, 868], + [3132, 868], + [2500, 1500], + [-1500, 1500], + [-868, 868], + ], + ], + [ + [ + [4000, 182882], + [4000, 183750], + [0, 183750], + [-868, 182882], + [4000, 182882], + ], + ], + [ + [ + [4000, 182093], + [4000, 182882], + [-868, 182882], + [-1868, 181882], + [3789, 181882], + [4000, 182093], + ], + ], + [ + [ + [3789, 181882], + [-1868, 181882], + [-20000, 163750], + [-14343, 163750], + [3789, 181882], + ], + ], + [ + [ + [4000, 868], + [-868, 868], + [0, 0], + [4000, 0], + [4000, 868], + ], + ], + [ + [ + [4000, 868], + [4000, 1657], + [3789, 1868], + [-1868, 1868], + [-868, 868], + [4000, 868], + ], + ], + [ + [ + [-1868, 1868], + [3789, 1868], + [-14343, 20000], + [-20000, 20000], + [-1868, 1868], + ], + ], + ] + + expect(() => polygonclip.union(geom, ...geoms)).not.toThrow() + }) +})