Skip to content

lib/vector: improve numerical stability for point-in-polygon calculations#7333

Open
metzm wants to merge 2 commits intoOSGeo:mainfrom
metzm:v.overlay_topoerror
Open

lib/vector: improve numerical stability for point-in-polygon calculations#7333
metzm wants to merge 2 commits intoOSGeo:mainfrom
metzm:v.overlay_topoerror

Conversation

@metzm
Copy link
Copy Markdown
Contributor

@metzm metzm commented Apr 18, 2026

What this PR does:

  • fix and synchronise intersection calculations in dig_x_intersect(), Vect__intersect_x_line_with_poly() and Vect__intersect_y_line_with_poly()
  • use Vect_point_in_poly() whenever possible for consistency and to reduce code maintenance burden
  • avoid floating point precision errors with changed calculations

The motivation for this PR arises from two issues:

  • Vect_get_point_in_poly_isl() fails for very small or very thin areas. This PR improves this fn by successfully calculating centroid's coordinates for more very small or very thin areas. However, because of fp precision limits, it is technically not possible to calculate centroid's coordinates for too small or too thin areas. In these cases it can not be guaranteed that the centroid is really inside the area.
  • Even if tests in Vect_get_point_in_poly_isl() confirm that the calculated centroid's coordinates are indeed inside the given area, Vect_find_area() might in extreme cases later on assign this centroid to a different area, causing problems with both duplicate centroids and missing centroids.

I am not sure if this PR should be regarded as a bug fix or as an enhancement. Suggestions welcome!

Please excuse the many changes in this single PR, but they really belong together.

@metzm metzm added this to the 8.6.0 milestone Apr 18, 2026
@metzm metzm requested a review from echoix April 18, 2026 17:48
@metzm metzm added enhancement New feature or request vector Related to vector data processing C Related code is in C libraries labels Apr 18, 2026
@metzm metzm force-pushed the v.overlay_topoerror branch from ee3e17e to ca061ca Compare April 19, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C enhancement New feature or request libraries vector Related to vector data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant