Turfjs / Turfjs/turf

unkinkPolygon cant deal with duplicate coordinates

Open
#2,912 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

@turf/unkink-polygon
Dominant language
TypeScript
Stars
10.5k
Forks
1k
Avg merge
1h 11m
Merged PRs (30d)
4

Description

This is basically a re-opening of:

  • #1679

As that was closed by the author without any fix 6 years ago.

unkinkPolygon throws an error The input polygon may not have duplicate vertices (except for the first and last vertex of each ring) when run on a polygon with duplicate vertices.

Reproduction using an hourglass shape, where the center has 2 stacked vertices:

const hourglass = turf.polygon( [[
    [0,0],
    [1,1], // center
    [2,2],
    [0,2],
    [1,1], // center
    [2,0],
    [0,0]
]]);

// all of these error
turf.unkinkPolygon(hourglass)
turf.unkinkPolygon(turf.cleanCoords(hourglass))
turf.unkinkPolygon(turf.simplify(hourglass, {tolerance: 0.5}))
turf.unkinkPolygon(turf.simplify(hourglass, {tolerance: 0.5, highQuality: true}))
Image of the shape

Image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the unkinkPolygon entry point and run the supplied hourglass reproduction, including the variants using cleanCoords and simplify. Trace where duplicate vertices are rejected and define the expected result for this self-intersecting polygon; done means the reproduction no longer throws solely because of the stacked center coordinates.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.