mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 21:46:49 +00:00
0246e5c317
haversineKm in src/utils/geo.ts answered NaN for some near antipodal pairs, for example 47.3812, -10.8827 and -47.3812001, 169.1173. Rounding pushed the haversine term a hair past 1, and asin of a value above 1 is NaN, which then spread into route sums and range checks. Cause: unlike the Studio legKm and the roadtrip haversineKm in @trek/shared, the shared client helper had no clamp before Math.asin. Fix: clamp with Math.min(1, ...) before Math.asin. With the clamp the helper runs exactly the operations of Studio legKm in the same order (2 * 6371 is 12742), so Studio now uses haversineKm and legKm goes, with its cases carried into the new geo tests. The roadtrip variant multiplies its terms in another order and gives different last bits, so it stays as it is. Red test: src/utils/geo.test.ts FE-UTIL-GEO-002 failed on the unfixed code with "AssertionError: expected NaN to be close to 20015.086796020572, received difference is NaN, but expected 0.0005". Removed tests: src/components/Studio/legKm.test.ts went with legKm. Its four cases (zero for one point, a degree of latitude about 111.19 km, the same both ways between 8700 and 8900 km, 0,0 to 0,180 equal to 12742 * PI / 2) now run against haversineKm as FE-UTIL-GEO-001, 003 and 004.