Fix function _is_point_in_polygon()#19924
Merged
TurboGit merged 2 commits intodarktable-org:masterfrom Feb 7, 2026
Merged
Conversation
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.
Member
|
@codecrusher64 : Needs a release note entry, TIA. |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a bugfix for issue #19843.