@@ -117,3 +117,243 @@ test("turf-difference - complete overlap", (t) => {
117117 t . deepEqual ( result , null , "difference should be null" ) ;
118118 t . end ( ) ;
119119} ) ;
120+
121+ test ( "difference - unable to complete output ring - issue 2409" , ( t ) => {
122+ // Test examples copied from https://github.com/Turfjs/turf/issues/2409
123+ const area1 = polygon ( [
124+ [
125+ [ 11.79926 , 59.307999 ] ,
126+ [ 18.80383 , 60.15596 ] ,
127+ [ 18.73765340635914 , 60.23951348693759 ] ,
128+ [ 18.58133 , 60.34301 ] ,
129+ [ 11.79926 , 59.307999 ] ,
130+ ] ,
131+ ] ) ;
132+
133+ const area1_subtract = polygon ( [
134+ [
135+ [ 11.79926 , 59.307999 ] ,
136+ [ 18.80383 , 60.15596 ] ,
137+ [
138+ 18.73765340635913 , // Subtract 1 to final digit
139+ 60.23951348693759 ,
140+ ] ,
141+ [ 18.58133 , 60.34301 ] ,
142+ [ 11.79926 , 59.307999 ] ,
143+ ] ,
144+ ] ) ;
145+
146+ const area1_add = polygon ( [
147+ [
148+ [ 11.79926 , 59.307999 ] ,
149+ [ 18.80383 , 60.15596 ] ,
150+ [
151+ 18.73765340635915 , // Add 1 to final digit
152+ 60.23951348693759 ,
153+ ] ,
154+ [ 18.58133 , 60.34301 ] ,
155+ [ 11.79926 , 59.307999 ] ,
156+ ] ,
157+ ] ) ;
158+
159+ const area2 = polygon ( [
160+ [
161+ [ 18.35554 , 60.35768 ] ,
162+ [ 18.58133 , 60.34301 ] ,
163+ [ 18.75959 , 60.22499 ] ,
164+ [ 18.80383 , 60.15596 ] ,
165+ [ 18.35554 , 60.35768 ] ,
166+ ] ,
167+ ] ) ;
168+
169+ t . doesNotThrow (
170+ ( ) => difference ( featureCollection ( [ area1 , area2 ] ) ) ,
171+ "[area1, area2] should not throw"
172+ ) ;
173+ t . doesNotThrow (
174+ ( ) => difference ( featureCollection ( [ area1_subtract , area2 ] ) ) ,
175+ "[area1_subtract, area2] should not throw"
176+ ) ;
177+ t . doesNotThrow (
178+ ( ) => difference ( featureCollection ( [ area1_add , area2 ] ) ) ,
179+ "[area1_add, area2] should not throw"
180+ ) ;
181+
182+ t . end ( ) ;
183+ } ) ;
184+
185+ test ( "difference - unable to complete output ring - issue 2277" , ( t ) => {
186+ // Test example copied from https://github.com/Turfjs/turf/issues/2277
187+ const poly1 = polygon ( [
188+ [
189+ [ 54.56658645236534 , 24.445194105819738 ] ,
190+ [ 54.56658654953498 , 24.441605817571325 ] ,
191+ [ 54.57000000000001 , 24.43981171174874 ] ,
192+ [ 54.57341345046501 , 24.441605817571325 ] ,
193+ [ 54.573413547634665 , 24.445194105819738 ] ,
194+ [ 54.57000000000001 , 24.44698828825126 ] ,
195+ [ 54.56658645236534 , 24.445194105819738 ] ,
196+ ] ,
197+ [
198+ [ 54.56795530519258 , 24.44447467409078 ] ,
199+ [ 54.57000000000001 , 24.4455493756693 ] ,
200+ [ 54.57204469480743 , 24.44447467409078 ] ,
201+ [ 54.57204465994316 , 24.442325298422087 ] ,
202+ [ 54.57000000000001 , 24.441250624330703 ] ,
203+ [ 54.56795534005685 , 24.442325298422087 ] ,
204+ [ 54.56795530519258 , 24.44447467409078 ] ,
205+ ] ,
206+ ] ) ;
207+
208+ const poly2 = polygon ( [
209+ [
210+ [ 54.569778932416476 , 24.441366817541834 ] ,
211+ [ 54.56977894449294 , 24.441074136738756 ] ,
212+ [ 54.57000000000001 , 24.441190327160086 ] ,
213+ [ 54.57084694057397 , 24.440745161222193 ] ,
214+ [ 54.57084693745136 , 24.44028034081218 ] ,
215+ [ 54.571147760242575 , 24.44043845608456 ] ,
216+ [ 54.57114771720956 , 24.441853864959285 ] ,
217+ [ 54.57080496898934 , 24.4416737163564 ] ,
218+ [ 54.57080502276297 , 24.441026402022757 ] ,
219+ [ 54.57074511559248 , 24.441057889217532 ] ,
220+ [ 54.57074509421786 , 24.441642246152345 ] ,
221+ [ 54.57000000000001 , 24.441250624330703 ] ,
222+ [ 54.569778932416476 , 24.441366817541834 ] ,
223+ ] ,
224+ ] ) ;
225+
226+ t . doesNotThrow (
227+ ( ) => difference ( featureCollection ( [ poly1 , poly2 ] ) ) ,
228+ "[poly1, poly2] should not throw"
229+ ) ;
230+
231+ t . end ( ) ;
232+ } ) ;
233+
234+ test ( "difference - maximum call stack size exceeded - issue 2479" , ( t ) => {
235+ // Test example copied from https://github.com/Turfjs/turf/issues/2479
236+ const poly1 = polygon ( [
237+ [
238+ [ 49.93317115095019 , 20.170898437500004 ] ,
239+ [ 49.93927561914192 , 20.16278743743897 ] ,
240+ [ 49.941126142253154 , 20.165448188781742 ] ,
241+ [ 49.934096538617936 , 20.174009799957275 ] ,
242+ [ 49.93317115095019 , 20.170898437500004 ] ,
243+ ] ,
244+ ] ) ;
245+
246+ const poly2 = polygon ( [
247+ [
248+ [ 49.93317115095019 , 20.170898437500004 ] ,
249+ [ 49.933680058500165 , 20.170222252607346 ] ,
250+ [ 49.933758735535065 , 20.170222252607346 ] ,
251+ [ 49.933803934349285 , 20.170152112841606 ] ,
252+ [ 49.933803934349285 , 20.170057658905122 ] ,
253+ [ 49.934306839656294 , 20.169389449185992 ] ,
254+ [ 49.93434632011994 , 20.16945071518421 ] ,
255+ [ 49.93434632011994 , 20.16959099471569 ] ,
256+ [ 49.93448191656261 , 20.16980141401291 ] ,
257+ [ 49.93457231419105 , 20.16980141401291 ] ,
258+ [ 49.93466271181949 , 20.16966113448143 ] ,
259+ [ 49.93484350707638 , 20.16966113448143 ] ,
260+ [ 49.93520509759015 , 20.169100016355515 ] ,
261+ [ 49.93529549521859 , 20.169100016355515 ] ,
262+ [ 49.935928278617695 , 20.168118059635166 ] ,
263+ [ 49.936018676246135 , 20.168118059635166 ] ,
264+ [ 49.93660626083101 , 20.167206242680553 ] ,
265+ [ 49.93660626083101 , 20.167065963149074 ] ,
266+ [ 49.9367870560879 , 20.166785404086117 ] ,
267+ [ 49.9367870560879 , 20.166645124554638 ] ,
268+ [ 49.93714864660167 , 20.166084006428722 ] ,
269+ [ 49.93714864660167 , 20.165613543475054 ] ,
270+ [ 49.93742361679489 , 20.16524819088677 ] ,
271+ [ 49.93755543592966 , 20.165452748537067 ] ,
272+ [ 49.938504611028314 , 20.16397981345654 ] ,
273+ [ 49.938504611028314 , 20.163811875057462 ] ,
274+ [ 49.93927561914192 , 20.16278743743897 ] ,
275+ [ 49.941126142253154 , 20.165448188781742 ] ,
276+ [ 49.93988364085967 , 20.16696147663808 ] ,
277+ [ 49.93981537664073 , 20.166855543851856 ] ,
278+ [ 49.93958938256963 , 20.167206242680553 ] ,
279+ [ 49.93958938256963 , 20.167319864563666 ] ,
280+ [ 49.934096538617936 , 20.174009799957275 ] ,
281+ [ 49.93317115095019 , 20.170898437500004 ] ,
282+ ] ,
283+ ] ) ;
284+
285+ t . doesNotThrow (
286+ ( ) => difference ( featureCollection ( [ poly1 , poly2 ] ) ) ,
287+ "[poly1, poly2] should not throw"
288+ ) ;
289+
290+ t . end ( ) ;
291+ } ) ;
292+
293+ test ( "difference - unable to find segment - issue 2306" , ( t ) => {
294+ // Test example copied from https://github.com/Turfjs/turf/issues/2306
295+ const poly1 = polygon ( [
296+ [
297+ [ 10.299138347373786 , 48.460352133145804 ] ,
298+ [ 10.299142854373908 , 48.46034913552448 ] ,
299+ [ 10.299142854373908 , 48.460339214732976 ] ,
300+ [ 10.299225267807545 , 48.46033958029495 ] ,
301+ [ 10.29927355737747 , 48.46034017606536 ] ,
302+ [ 10.29927355737747 , 48.46034613790316 ] ,
303+ [ 10.299266796877285 , 48.46035363195647 ] ,
304+ [ 10.299257782877039 , 48.46035363195647 ] ,
305+ [ 10.299251022376856 , 48.46035812838846 ] ,
306+ [ 10.299251022376856 , 48.46036507625937 ] ,
307+ [ 10.299195961284822 , 48.4603647734974 ] ,
308+ [ 10.299201445375504 , 48.46036112600978 ] ,
309+ [ 10.29919468487532 , 48.460356629577795 ] ,
310+ [ 10.299187924375136 , 48.46035812838846 ] ,
311+ [ 10.299187924375136 , 48.46036112600978 ] ,
312+ [ 10.299193387184792 , 48.460364759343314 ] ,
313+ [ 10.299138347373786 , 48.460364456698365 ] ,
314+ [ 10.299138347373786 , 48.460352133145804 ] ,
315+ ] ,
316+ [
317+ [ 10.299142854373908 , 48.46035812838846 ] ,
318+ [ 10.299145107873969 , 48.46035962719912 ] ,
319+ [ 10.2991608823744 , 48.46035812838846 ] ,
320+ [ 10.299158628874338 , 48.46035363195647 ] ,
321+ [ 10.299149614874093 , 48.46035363195647 ] ,
322+ [ 10.299142854373908 , 48.46035812838846 ] ,
323+ ] ,
324+ ] ) ;
325+
326+ const poly2 = polygon ( [
327+ [
328+ [ 10.299138347373786 , 48.46036049139952 ] ,
329+ [ 10.299187924375136 , 48.46036028454162 ] ,
330+ [ 10.299187924375136 , 48.46036112600978 ] ,
331+ [ 10.29919468487532 , 48.46036562244176 ] ,
332+ [ 10.299201445375504 , 48.46036112600978 ] ,
333+ [ 10.299200103800315 , 48.46036023372349 ] ,
334+ [ 10.299208777179729 , 48.46036019753419 ] ,
335+ [ 10.299209806197382 , 48.46031596598246 ] ,
336+ [ 10.299250947482829 , 48.460316111877646 ] ,
337+ [ 10.299251022376856 , 48.460316161689924 ] ,
338+ [ 10.299251022376856 , 48.46031915931125 ] ,
339+ [ 10.299257677970186 , 48.46032358596932 ] ,
340+ [ 10.299256707063519 , 48.46035434748375 ] ,
341+ [ 10.299251022376856 , 48.46035812838846 ] ,
342+ [ 10.299251022376856 , 48.4603761141164 ] ,
343+ [ 10.299246515376732 , 48.46037911173772 ] ,
344+ [ 10.299246515376732 , 48.4603872476338 ] ,
345+ [ 10.29919425093356 , 48.460374326689575 ] ,
346+ [ 10.299190177875197 , 48.460371617684416 ] ,
347+ [ 10.299188312254989 , 48.46037285851485 ] ,
348+ [ 10.299138347373786 , 48.460360506074 ] ,
349+ [ 10.299138347373786 , 48.46036049139952 ] ,
350+ ] ,
351+ ] ) ;
352+
353+ t . doesNotThrow (
354+ ( ) => difference ( featureCollection ( [ poly1 , poly2 ] ) ) ,
355+ "[poly1, poly2] should not throw"
356+ ) ;
357+
358+ t . end ( ) ;
359+ } ) ;
0 commit comments