Skip to content

Fixed simplify to not get stuck in an infinite loop on certain geometries#2830

Merged
smallsaucepan merged 2 commits intoTurfjs:masterfrom
smallsaucepan:simplify-infinite
May 15, 2025
Merged

Fixed simplify to not get stuck in an infinite loop on certain geometries#2830
smallsaucepan merged 2 commits intoTurfjs:masterfrom
smallsaucepan:simplify-infinite

Conversation

@smallsaucepan
Copy link
Copy Markdown
Member

simplify was getting stuck in an infinite loop when it couldn't reduce the tolerance far enough to generate a valid polygon. This often happened with very small rings e.g. couple of centimetres to a side.

Resolves #1788

Please provide the following when creating a PR:

  • Meaningful title, including the name of the package being modified.
  • Summary of the changes.
  • Heads up if this is a breaking change.
  • Any issues this resolves.
  • Inclusion of your details in the contributors field of package.json - you've earned it! 👏
  • Confirmation you've read the steps for preparing a pull request.

Copy link
Copy Markdown
Collaborator

@mfedderly mfedderly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

## nearestNeighborAnalysis

Nearest Neighbor Analysis calculates an index based the average distances
Nearest Neighbor Analysis calculates an index based on the average distances
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this was already in the index.ts comment, just not populated into the readme. I thought we had pre-commit hooks to make sure that didn't happen. Oh well.


// If simplified ring isn't valid (has been over simplified) reduce the
// tolerance by 1% and try again.
while (!checkValidity(simpleRing) && ringTolerance >= Number.EPSILON) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was worried about this leaving impossibly tiny polygons with a large number of points, but EPSILON is so much smaller than any meaningful coordinate delta that this is probably a nonissue.

> area({type: "Polygon", coordinates: [[0,0], [0, Number.EPSILON], [Number.EPSILON, Number.EPSILON], [Number.EPSILON, 0], [0, 0]]})
0

@smallsaucepan smallsaucepan merged commit 11ec0a8 into Turfjs:master May 15, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@turf/simplify gets stuck in an infinite loop on certain geometries

2 participants