Skip to content

Fix function _is_point_in_polygon()#19924

Merged
TurboGit merged 2 commits intodarktable-org:masterfrom
codecrusher64:fix-is-point-in-polygon
Feb 7, 2026
Merged

Fix function _is_point_in_polygon()#19924
TurboGit merged 2 commits intodarktable-org:masterfrom
codecrusher64:fix-is-point-in-polygon

Conversation

@codecrusher64
Copy link
Contributor

This is a bugfix for issue #19843.

The previous implementation of the ray casting algorithm did not handle
a special corner case correctly. If there are two consecutive line
segments of the polygon's edge represented by three consecutive corners
and the intermediate corner has the same latitude as the point to be
checked, i.e., `pt->lat == lat`, this condition was true for both line
segments. Instead, this condition should only be true for one of the two
line segments.

The condition should be

if(!(((lat1 >  pt->lat) && (lat2 >  pt->lat)) ||
     ((lat1 <= pt->lat) && (lat2 <= pt->lat))

which is equivalent to

if((lat1 > pt->lat) != (lat2 > pt-lat))

See the reference implementation of the even-odd rule at
https://en.wikipedia.org/w/index.php?title=Even%E2%80%93odd_rule&oldid=1274993919
for instance.
This modification avoids division by very small values `lat2 - lat1`, in
case `lat1 ≈ lat2`.

See the reference implementation of the even-odd rule at
https://en.wikipedia.org/w/index.php?title=Even%E2%80%93odd_rule&oldid=1274993919
for instance.
@TurboGit TurboGit added this to the 5.6 milestone Dec 15, 2025
@TurboGit TurboGit added bugfix pull request fixing a bug priority: medium core features are degraded in a way that is still mostly usable, software stutters understood: clear devs have a complete bug report with all the relevant info to start fixing scope: codebase making darktable source code easier to manage release notes: pending labels Dec 15, 2025
Copy link
Member

@TurboGit TurboGit left a comment

Choose a reason for hiding this comment

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

Thanks!

@TurboGit TurboGit merged commit b56fe5f into darktable-org:master Feb 7, 2026
5 checks passed
@TurboGit
Copy link
Member

TurboGit commented Feb 7, 2026

@codecrusher64 : Needs a release note entry, TIA.

@codecrusher64 codecrusher64 deleted the fix-is-point-in-polygon branch February 7, 2026 16:51
codecrusher64 added a commit to codecrusher64/darktable that referenced this pull request Feb 7, 2026
TurboGit pushed a commit that referenced this pull request Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix pull request fixing a bug priority: medium core features are degraded in a way that is still mostly usable, software stutters scope: codebase making darktable source code easier to manage understood: clear devs have a complete bug report with all the relevant info to start fixing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants