Skip to content

Commit

Permalink
test: Add test for known case causing mfogel#124
Browse files Browse the repository at this point in the history
  • Loading branch information
macksal committed Mar 8, 2023
1 parent 2b8086c commit 4aa3423
Showing 1 changed file with 189 additions and 0 deletions.
189 changes: 189 additions & 0 deletions test/duplicate-nodes-#124.js
Original file line number Diff line number Diff line change
@@ -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()
})
})

0 comments on commit 4aa3423

Please sign in to comment.