You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Negative distance and area measurements never scale to larger units (km, km², mi, acres) #1284
When measuring or formatting negative distances or areas (e.g. from signed offsets, relative coordinates, elevation or delta calculations, or reverse paths), measurements never scale to larger units. For example:
A distance of -12,500.0 m is formatted as "-12500 m" instead of "-12.5 km".
A distance of -120,000.0 m is formatted as "-120000 m" instead of "-120 km".
An area of -5,000,000.0 m² is formatted as "-5000000 m²" instead of "-5.0 km²".
Under imperial measurement units, -20,000.0 m is formatted as "-65617 ft" instead of "-12.4 mi".
An imperial area of -10,000,000.0 m² is formatted as "-107639104 ft²" instead of "-3.9 mi²".
Cause
In crates/geom/src/lib.rs (format_distance and format_area) and crates/ui-egui/src/measure_units.rs (distance and area), unit thresholds compare signed values directly against positive constants without taking the absolute magnitude into account:
Because any negative value is algebraically less than positive numbers (-12500.0 < 1000.0 is true), the comparison branches early and never reaches the larger unit branches (km, km², mi, acres). Small negative distances (mm, cm) already correctly use .abs(), but the larger thresholds were missed.
Steps to reproduce
Call format_distance(-12500.0) or format_area(-5000000.0) in rustgis_geom, or measure_units::distance(-20000.0, true) in rustgis_ui_egui.
Observe that values stay in raw metres/square metres or feet/square feet regardless of magnitude.
Expected behavior
Unit switching thresholds should check magnitude (.abs()), preserving sign so that:
Activity
fix(geom): switch measurement units for negative distances and areas (o…
fix(geom): switch measurement units for negative distances and areas (o…
fix(geom): switch measurement units for negative distances and areas (#…