Skip to content

fix(geom): show nonfinite measurements as unavailable - #960

Merged
giswqs merged 1 commit into
opengeos:mainfrom
choupeanut:fix/938-nonfinite-measurement-formatting
Oct 26, 2026
Merged

giswqs merged 1 commit into
opengeos:mainfrom
choupeanut:fix/938-nonfinite-measurement-formatting

Conversation

@choupeanut

@choupeanut choupeanut commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Non-finite measurements and coordinates were displayed as numeric values such as NaN km, inf km² or NaN° E. The shared distance, area, decimal-degree and DMS formatters now return — for NaN or either infinity. If either coordinate is invalid, the whole coordinate pair is unavailable.

The measurement panel's imperial distance/area paths use the same fallback, so changing units cannot bring the invalid numeric text back. Finite-value formatting remains unchanged; there are no new dependencies or API changes.

Testing

  • Regression reproduced NaN km before the fix.
  • cargo test -p rustgis-geom: 17 passed.
  • Focused UI regression passed for metric/imperial NaN, ±infinity, zero and finite imperial values.
  • cargo xtask ci: 2,404 passed, 0 failed, 16 ignored; layers passed.
  • uvx pre-commit run --all-files
  • cargo build --locked --target wasm32-unknown-unknown -p rustgis-web
  • Headless metric/imperial distance measurements; screenshots inspected locally (not committed).

Related issue

Closes #938.

Summary by CodeRabbit

  • Bug Fixes
    • Non-finite distances, areas, and coordinates now display as an em dash instead of an invalid numeric value.
    • This behavior is consistent across metric and imperial units. Valid measurements retain their existing formatting, including imperial zero and one-unit values.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: b86ed80b-d249-4b4f-a997-b5b4e0ec9241
Commits

Reviewing files that changed from the base of the PR and between b5ead75 and e1d201d.

Files selected for processing: 2
  • crates/geom/src/lib.rs
  • crates/ui-egui/src/measure_units.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Walkthrough

Non-finite distances, areas, and coordinates now display as an em dash. The unit helpers also use the unavailable-value formatting in imperial mode. Tests cover non-finite inputs and representative finite formatting.

Changes: Measurement formatting

Layer / File(s) Summary
Handle non-finite geometry values
crates/geom/src/lib.rs
The distance, area, longitude/latitude, and DMS formatters return an em dash for non-finite inputs. Tests cover these cases and representative finite values.
Apply unavailable formatting across unit systems
crates/ui-egui/src/measure_units.rs
Distance and area use metric formatters for non-finite values in both unit systems. Tests also check imperial zero and one-unit formatting.

Priority: Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related issues

  • opengeos/RustGIS#937 — This change hides non-finite measurement output but does not address haversine_m producing a finite distance from a NaN coordinate.

Suggested reviewers: mavrick-f

Merge Risk: Minimal · up to e1d20

The non-finite measurement display behavior is covered across metric and imperial paths, with no material merge-blocking risk identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 58.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: displaying non-finite measurements as unavailable.
Description check Passed The description includes all required sections. It explains the change, documents comprehensive testing, and references the related issue.
Linked Issues check Passed Issue #938 requires non-finite distances, areas, and coordinates to avoid numeric-looking output. crates/geom/src/lib.rs returns — for NaN and both infinities in format_distance and `format_area…
Out of Scope Changes check Passed The changes stay within issue #938. The formatter guards, imperial measurement fallback, documentation updates, and regression tests directly support consistent handling of non-finite measurements and…
Full details: Linked Issues check

Explanation

Issue #938 requires non-finite distances, areas, and coordinates to avoid numeric-looking output. crates/geom/src/lib.rs returns — for NaN and both infinities in format_distance and format_area. It also returns — when either coordinate is non-finite in format_lonlat and format_dms. Tests cover all three non-finite values, each invalid coordinate position, and representative finite values. crates/ui-egui/src/measure_units.rs applies the metric fallback in imperial mode and tests both unit systems.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #938. The formatter guards, imperial measurement fallback, documentation updates, and regression tests directly support consistent handling of non-finite measurements and coordinates. No unrelated production behavior or dependency changes are shown.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the numbers on the trail,
An em dash greets each value gone astray.
The miles and acres join the metric line,
While finite measures keep their proper sign.
The rabbit hops along beneath the moon.

Comment @coderabbitai help to get the list of available commands.

Comment thread crates/geom/src/lib.rs
Comment on lines 382 to +392
@@ -376,6 +387,9 @@ pub fn format_dms(c: Coord) -> String {
let s = (tenths % 600.0) / 10.0;
format!("{d:.0}°{m:02.0}′{s:04.1}″")
}
if !c.is_finite() {
return "—".to_string();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the non-finite guard sits after the nested dms helper here, while format_distance, format_area and format_lonlat check first. Moving it to the top of the function reads more consistently and keeps the early return next to the signature.

Suggested change
pub fn format_dms(c: Coord) -> String {
if !c.is_finite() {
return "—".to_string();
}
fn dms(v: f64) -> String {
let tenths = (v.abs() * 36_000.0).round();
let d = (tenths / 36_000.0).floor();
let m = ((tenths % 36_000.0) / 600.0).floor();
let s = (tenths % 600.0) / 10.0;
format!("{d:.0}°{m:02.0}′{s:04.1}″")
}

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs

  • None found. I checked the new test expectations by reading them against the formatters (format_area(0.0), the format_lonlat sign and spacing, whole_or_small(1.0) and whole_or_small(0.0) in the imperial tests), and they hold. I did not run cargo test, since this review had no build tool.

Security

  • None found. The change adds no parsing, I/O, or unsafe code.

Performance

  • None found. The added checks are constant-time.

Quality

  • Nit, high confidence: in format_dms (crates/geom/src/lib.rs), the non-finite guard sits after the nested dms helper, while the other three formatters check first. Inline comment posted with a suggestion to move it up.
  • Low confidence: measure_units::elevation still formats non-finite input as NaN/inf. The only caller is the elevation-profile labels in workspacepanes.rs, and those values come from JSON, which cannot carry NaN or infinity, so this is probably unreachable. Not posted.
  • Observation outside the diff: crates/tiles/src/routing.rs:356 has its own format_distance, which still maps NaN to "0 m". The test at line 543 pins that behaviour. Directions and measurements therefore disagree on how to show invalid distances. I left it alone because it is outside this change.

AGENTS.md

  • No unwrap, expect, panic, or unsafe added. Each formatter has a regression test, which is what the crash-fix rule asks for.
  • The new "—" literals are not wrapped in tl!. That is acceptable: geom is below L6 and cannot use i18n, and the em dash is a symbol rather than language text.
  • No new dependencies, so no licence or notices step is needed. The change touches no wasm-only code paths.

Confidence: high that the change is correct as written. The only actionable item is the nit above.

Change size

Compared with the base branch: the whole PR against main (merge base a5f50ce to PR head e1d201d).

Files changed Added Modified Removed Renamed
2 0 2 0 0
Size before Size after Total change
28.2 KB 30.0 KB +1.8 KB
Path Size before Size after Size change
crates/geom/src/lib.rs 25.6 KB 26.7 KB +1.1 KB
crates/ui-egui/src/measure_units.rs 2.7 KB 3.3 KB +671 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-960/
Web app https://preview.rustgis.app/pr-960/app/
Commit e1d201d

GitHub Pages takes a minute or two to publish a new commit.

@giswqs
giswqs merged commit d779339 into opengeos:main Oct 26, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Non-finite distances, areas and coordinates display as "NaN km", "inf km", "-inf m", "NaN° E NaN° N"

2 participants