Fix geographic intersection calculation in sjoberg_intersection when a segment lies on the equator#1483
Open
fbriol wants to merge 1 commit into
Open
Fix geographic intersection calculation in sjoberg_intersection when a segment lies on the equator#1483fbriol wants to merge 1 commit into
sjoberg_intersection when a segment lies on the equator#1483fbriol wants to merge 1 commit into
Conversation
…rsection Multiply the longitude offset term by `sign_lon_diff` when calculating equator crossings in `sjoberg_geodesic::lon_of_equator_intersection()`. Without this multiplication, when `sign_lon_diff` is negative, the offset is applied in the wrong direction, leading to a wrong intersection longitude (e.g. returning a coordinate outside of the segments' bounds). This in turn causes overlay/intersection algorithms to miss crossings on the boundary. Fixes boostorg#1482
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.
PR Description
Description
This PR fixes a bug in the geographic intersection algorithm where the longitude crossing of the equator is calculated incorrectly when one of the segments lies exactly along the equator.
The root cause is in
boost/geometry/formulas/sjoberg_intersection.hppundersjoberg_geodesic::lon_of_equator_intersection(). The formula calculates the offset of longitude from the start pointlonjusing- asin_tj_t0j + dLj, but forgets to multiply this offset bysign_lon_diff. As a result, whensign_lon_diffis-1, the offset is added in the wrong direction, causing a completely incorrect intersection longitude.This incorrect coordinate causes overlay algorithms (like clipping or set operations) to fail to detect that a linestring crosses the boundary of a polygon containing equatorial segments.
Fixes #1482
Proposed Changes
Multiply the longitude offset term by
sign_lon_diffinlon_of_equator_intersection():Reproduction Example
lon (deg): 3.41489(incorrect, outside segment range).lon (deg): 3.27082(correct).