Skip to content

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
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 release notes: pending 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