luizbarboza / polyclip-ts

MIT License
28 stars 10 forks source link

unable to complete output ring starting at #5

Open MitchellMonaghan opened 1 year ago

MitchellMonaghan commented 1 year ago

Doing a intersect on these two shapes seems to produce the unable to complete output ring starting at error

{
        type: 'Feature',
        properties: {},
        geometry: {
          type: 'Polygon',
          coordinates: [
            [
              [
                -94.01653361819794,
                44.91274384567805
              ],
              [
                -94.01648672631458,
                44.91275462177405
              ],
              [
                -94.01653344003874,
                44.91275386419229
              ],
              [
                -94.01653361819794,
                44.91274384567805
              ]
            ]
          ]
        }
      }
      {
        type: 'Feature',
        properties: {},
        geometry: {
          type: 'Polygon',
          coordinates: [
            [
              [
                -94.01654779292787,
                44.91274058822198
              ],
              [
                -94.0164867263146,
                44.91275462177405
              ],
              [
                -94.01650378031933,
                44.91275434520002
              ],
              [
                -94.01654762526815,
                44.912753634142746
              ],
              [
                -94.01654779292787,
                44.91274058822198
              ]
            ]
          ]
        }
      }
luizbarboza commented 9 months ago

This issue can be resolved by setting the precision to something like 1e-12 before performing the operation.

For example:

polyclip.setPrecision(1e-12)

polyclip.intersection(poly1, poly2)

will give the following result:

[
  [ -94.01653361819794, 44.91274384567805 ],
  [ -94.01648672631458, 44.91275462177405 ],
  [ -94.01653344003874, 44.91275386419229 ],
  [ -94.01653361819794, 44.91274384567805 ]
]

map1 map2