turf icon indicating copy to clipboard operation
turf copied to clipboard

turf.difference doesn't terminate (infinite loop)

Open JordanHe opened this issue 8 months ago • 1 comments

When I try and calculate the difference it never terminates.

im using "@turf/helpers": "^6.5.0", "@turf/turf": "^6.5.0",

import * as turf from '@turf/turf';

const p1 = [[[-2.4088388, 57.02108101], [-2.40733, 57.02113], [-2.40337, 57.02057], [-2.4008, 57.02051], [-2.39572, 57.01933], [-2.3951, 57.01895], [-2.3938, 57.01755], [-2.39381, 57.01601], [-2.39353, 57.01523], [-2.39137528, 57.01553031], [-2.3897149916781157, 57.015854809672014], [-2.3896572772518754, 57.01586853945717], [-2.3874634642189916, 57.01639043215956], [-2.38626, 57.01684], [-2.38369, 57.01729], [-2.383683464226125, 57.01728966021971], [-2.38364, 57.0173], [-2.3827601824004376, 57.01724217161317], [-2.38194, 57.0172], [-2.38185992, 57.017183], [-2.3818708985842703, 57.0171837210337], [-2.38151, 57.01716], [-2.378985055244997, 57.01656905548287], [-2.3791523, 57.0166082], [-2.37836, 57.01644], [-2.37820405, 57.01638627], [-2.37625018, 57.01592898], [-2.37423793, 57.01570798], [-2.37477, 57.01586], [-2.37588, 57.01686], [-2.37596, 57.01724], [-2.37564, 57.01765], [-2.37557, 57.01773], [-2.37374, 57.01859], [-2.37294, 57.01915], [-2.37254, 57.01978], [-2.37049, 57.02082], [-2.36717, 57.02165], [-2.36581, 57.02152], [-2.36271, 57.02252], [-2.36237, 57.02277], [-2.36269, 57.02351], [-2.36252, 57.02367], [-2.35839, 57.02454], [-2.35265, 57.02682], [-2.35061, 57.02723], [-2.34828, 57.02737], [-2.34726, 57.0276], [-2.34298, 57.03002], [-2.34446, 57.03045], [-2.34458217, 57.03052922], [-2.34475, 57.03058], [-2.3475143, 57.03213979], [-2.34574, 57.03128], [-2.34801, 57.03238], [-2.34853049, 57.03284266], [-2.34891, 57.03314], [-2.35054, 57.03391], [-2.35193, 57.03512], [-2.35292, 57.03557], [-2.35272178, 57.03568916], [-2.35262, 57.03588], [-2.35174585, 57.03627584], [-2.35119, 57.03661], [-2.35125296, 57.03673242], [-2.35268, 57.03758], [-2.35237738, 57.03740026], [-2.35272, 57.03755], [-2.35248, 57.03824], [-2.35252819, 57.03839805], [-2.35242, 57.03819], [-2.35281, 57.03894], [-2.35260437, 57.03985146], [-2.35253, 57.04032], [-2.35273, 57.04076], [-2.35338, 57.04131], [-2.35482167, 57.04213896], [-2.35527, 57.04237], [-2.35537, 57.0425], [-2.35511068, 57.04304642], [-2.35502, 57.04299], [-2.35547, 57.04327], [-2.35567, 57.04376], [-2.35547285, 57.04327697], [-2.35552, 57.0433], [-2.3558921, 57.04390806], [-2.35597, 57.04396], [-2.35681, 57.04387], [-2.35763, 57.04446], [-2.35949, 57.04408], [-2.35953943, 57.0441584], [-2.35971, 57.0442], [-2.35975, 57.04438], [-2.35970446, 57.04442018], [-2.35978, 57.04454], [-2.36252897, 57.04361154], [-2.36283376, 57.04350397], [-2.36518, 57.04239], [-2.37104494, 57.04072454], [-2.37184, 57.04045], [-2.37301478, 57.03987996], [-2.37433269, 57.03921316], [-2.37575, 57.03821], [-2.37733551, 57.03765041], [-2.37802, 57.03708], [-2.37763224, 57.03740313], [-2.37782, 57.03719], [-2.37901, 57.03648], [-2.37918685, 57.03643284], [-2.37921, 57.03642], [-2.37936007, 57.03638665], [-2.37991, 57.03624], [-2.38017805, 57.0363051], [-2.3807391, 57.03640711], [-2.38182812, 57.03638273], [-2.38203, 57.03637], [-2.38197001, 57.03637378], [-2.38240368, 57.03623905], [-2.3832, 57.03596], [-2.38304832, 57.03601315], [-2.38438, 57.0351], [-2.38908, 57.03249], [-2.38982, 57.03175], [-2.39054, 57.03032], [-2.39184, 57.02949], [-2.39531636, 57.02782056], [-2.39542766, 57.02776381], [-2.39542987, 57.02776268], [-2.40343, 57.02338], [-2.4088388, 57.02108101], [-2.4088388, 57.02108101]]]
const p2 = [[[[-2.37587, 57.01742], [-2.3758410130102297, 57.01739245208064], [-2.3757818255578083, 57.01746828600406], [-2.37587, 57.01742]]], [[[-2.3732632505643276, 57.018923724604974], [-2.37294, 57.01915], [-2.37255369772802, 57.01975842607837], [-2.37274, 57.01967], [-2.3732632505643276, 57.018923724604974]]], [[[-2.370124677419359, 57.02091133064516], [-2.369055000000011, 57.02117875], [-2.36998, 57.02098], [-2.370124677419359, 57.02091133064516]]], [[[-2.3669566675201605, 57.02162960792472], [-2.36581, 57.02152], [-2.36271, 57.02252], [-2.3626675973728397, 57.022551178402324], [-2.3669566675201605, 57.02162960792472]]], [[[-2.36268, 57.02337], [-2.362502196721306, 57.02307570491802], [-2.3626398125285775, 57.023393941472335], [-2.36268, 57.02337]]], [[[-2.362531957585644, 57.02265091353997], [-2.36237, 57.02277], [-2.362408452674896, 57.0228589218107], [-2.362531957585644, 57.02265091353997]]], [[[-2.3490715734114063, 57.0273224376491], [-2.34828, 57.02737], [-2.3474695358863706, 57.027552751711895], [-2.3490715734114063, 57.0273224376491]]]]

const poly1 = turf.polygon(p1);
const poly2 = turf.multiPolygon(p2);

console.log("trying....")
const difference = turf.difference(turf.truncate(poly1, { precision: 8 }), turf.truncate(poly2, { precision: 8 }));

console.log("Difference:", JSON.stringify(difference, null, 2));

JordanHe avatar May 27 '25 10:05 JordanHe

Hi @JordanHe. Thanks for reporting. Are you able to try with Turf 7.2.0?

smallsaucepan avatar Jun 03 '25 08:06 smallsaucepan