Skip to content

Instantly share code, notes, and snippets.

@twolfson
Last active November 10, 2021 20:39
Show Gist options
  • Save twolfson/bfd03b9e4b254374c32a6d91427f36df to your computer and use it in GitHub Desktop.
Save twolfson/bfd03b9e4b254374c32a6d91427f36df to your computer and use it in GitHub Desktop.
polygon-clipping: "Unable to complete output ring" reproduction script
const polygonClipping = require('polygon-clipping');
const poly1 = [
[
[-89.6913437618266, 32.5917775294804],
[-89.6913424001509, 32.5873713360798],
[-89.6913420772531, 32.5863246737333],
[-89.6932638650491, 32.5863115360137],
[-89.6932452075745, 32.5843574521187],
[-89.6951228354689, 32.584358882942],
[-89.6956487351547, 32.5843592787172],
[-89.6956469103875, 32.5846430395785],
[-89.6956459379237, 32.5847943300606],
[-89.6956249346706, 32.588061138283],
[-89.695601135812, 32.5917629957181],
[-89.6913437618266, 32.5917775294804],
],
];
const poly2 = [
[
[-89.6871254313303, 32.5917917879984],
[-89.6913437618266, 32.5917775294802],
[-89.6956011358121, 32.591762995718],
[-89.6955858465406, 32.5963553861461],
[-89.695574663872, 32.5963569579772],
[-89.6954373654101, 32.5963740205835],
[-89.6952992464608, 32.5963853878873],
[-89.6950573710177, 32.5963984695039],
[-89.6948152632906, 32.5964079903863],
[-89.6945729967697, 32.5964139464221],
[-89.6940781773675, 32.5964190256726],
[-89.6939482026362, 32.5964176590706],
[-89.6938183501485, 32.5964126989754],
[-89.6936887584518, 32.5964041507506],
[-89.6936268455706, 32.5963966340367],
[-89.6935660787993, 32.5963840912762],
[-89.6935070270342, 32.5963666394082],
[-89.6934502425756, 32.5963444423769],
[-89.6930532000114, 32.5961666917628],
[-89.6926584918214, 32.5959852547359],
[-89.6920612385483, 32.5957097575597],
[-89.6919165738243, 32.5956422151488],
[-89.6917733921706, 32.5955724450618],
[-89.6917057625651, 32.595535839428],
[-89.6916421918065, 32.5954943483666],
[-89.6915831697605, 32.5954482922609],
[-89.6915291536051, 32.5953980268859],
[-89.6914805592838, 32.5953439407609],
[-89.6914049427734, 32.5952469649753],
[-89.6913345769162, 32.5951471975717],
[-89.6912696063737, 32.5950448413635],
[-89.6912101620266, 32.5949401064723],
[-89.691156367315, 32.5948332048731],
[-89.6911083297683, 32.5947243558632],
[-89.6909825939814, 32.5944340602622],
[-89.6908493509681, 32.5941461747012],
[-89.6908180104286, 32.594087790075],
[-89.6907809815121, 32.5940318428859],
[-89.6907385257929, 32.5939787308136],
[-89.6906909429728, 32.5939288287337],
[-89.6906385719724, 32.5938824914161],
[-89.6905817834148, 32.5938400472638],
[-89.6905209795994, 32.5938017956081],
[-89.690319516595, 32.5936817031788],
[-89.6901228499412, 32.5935560437431],
[-89.6899680767473, 32.5934580080482],
[-89.689808642776, 32.5933654792848],
[-89.6896448222109, 32.593278616076],
[-89.689348175316, 32.5931258813037],
[-89.6890542896415, 32.5929693676637],
[-89.6888089926937, 32.5928344987501],
[-89.6885659211617, 32.5926967737229],
[-89.6883251211161, 32.5925562193334],
[-89.6880968074965, 32.5924229115574],
[-89.6878663837976, 32.5922922318485],
[-89.6877252388135, 32.5922103481556],
[-89.6875875235841, 32.5921243813537],
[-89.6874534020566, 32.5920344331377],
[-89.6873230371788, 32.5919406124233],
[-89.6871965823362, 32.5918430308969],
[-89.6871254313303, 32.5917917879984],
],
];
console.log(polygonClipping.difference(poly1, poly2));
const polygonClipping = require('polygon-clipping');
const poly1 = [
[
[-89.6913437618266, 32.5917775294804],
[-89.6913420772531, 32.5863246737333],
[-89.6932638650491, 32.5863115360137],
[-89.6913437618266, 32.5917775294804], // Technically not needed, will fail still without this line
],
];
const poly2 = [
[
[-89.6871254313303, 32.5917917879984],
[-89.6913437618266, 32.5917775294802],
[-89.6956011358121, 32.591762995718], // Technically not needed, will fail still without this line
[-89.6871254313303, 32.5917917879984], // Technically not needed, will fail still without this line
],
];
console.log(polygonClipping.difference(poly1, poly2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment