fix(formulas): geographic intersection calculation in sjoberg_intersection when a segment lies on the equator

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.

Including regression test for sjoberg_intersection

Fixes #1482
This commit is contained in:
Frédéric BRIOL
2026-07-09 20:04:41 +02:00
committed by GitHub
parent 0925991e94
commit 480e9cf0f6
2 changed files with 15 additions and 1 deletions
@@ -566,7 +566,7 @@ public:
{
CT const c0 = 0;
CT const dLj = d_lambda(c0);
return lonj - asin_tj_t0j + dLj;
return lonj + sign_lon_diff * (-asin_tj_t0j + dLj);
}
CT d_lambda(CT const& sin_beta) const
+14
View File
@@ -185,6 +185,20 @@ void test_bugs()
check_one("issue 612", lon, -0.087266500535674751);
check_one("issue 612", lat, 1.5892499139622920e-07);
}
// https://github.com/boostorg/geometry/issues/1482
{
double const d2r = bg::math::d2r<double>();
double lon, lat;
bg::formula::sjoberg_intersection<double, bg::formula::andoyer_inverse, 4>
::apply(3.268218994140625 * d2r, 0.01789649948477745 * d2r,
3.3428595066070557 * d2r, -0.4950112998485565 * d2r,
4.0 * d2r, 0.0 * d2r,
3.0 * d2r, 0.0 * d2r,
lon, lat, bg::srs::spheroid<double>());
check_one("issue 1482", lon, 0.057086634437951006005);
check_one("issue 1482", lat, 0.0);
}
}
void test_special_cases()