Modern Apps git

← Modern-Apps.git

map: dedupe stroke geometry helpers into ribbon::joins

Commit
c8191d821b41a156f63cc9dd67a86e6b43f1f1ee
Author
Vayun Mathur <[email protected]>
When
2026-12-01 20:44 UTC (4 days ago)
Parents
1ce73a3
The ribbon joins module already carried pub(crate) copies of
dedupe and segment_length, and a private copy of direction,
with bodies identical to the private copies in tess::stroke
(the tessellator the carriageway and the plain stroke both
build on). Keeping two copies meant a fix to duplicate-vertex
dropping or segment maths could land on one path and not the
other, so the two could quietly disagree about a centreline.

Delete the stroke copies and import all three helpers from
ribbon::joins; direction and the joins module become
pub(crate) to make that path visible. No function body
changes, so tessellation output is unchanged. Counted Rust
lines fall by 32 (1,655,907 to 1,655,875 in the structure
ratchet report).

Verified with cargo test -p map_renderer --locked (574
passed, 1 ignored in the library target, plus the integration
targets), cargo clippy -p map_renderer --locked
--all-targets, and cargo fmt -p map_renderer -- --check.

Diff

library/map/src/main/rust/src/tess/ribbon/joins.rs
diff --git a/library/map/src/main/rust/src/tess/ribbon/joins.rs b/library/map/src/main/rust/src/tess/ribbon/joins.rsindex d1d7ec5bc8..bc110efa6c 100644--- a/library/map/src/main/rust/src/tess/ribbon/joins.rs+++ b/library/map/src/main/rust/src/tess/ribbon/joins.rs@@ -34,7 +34,7 @@ pub(crate) fn join_normal(points: &[i32], n: usize, i: usize) -> (f32, f32) { }  /// Unit direction from point `i` to point `j`.-fn direction(points: &[i32], i: usize, j: usize) -> (f32, f32) {+pub(crate) fn direction(points: &[i32], i: usize, j: usize) -> (f32, f32) {     let dx = (points[j * 2] - points[i * 2]) as f32;     let dy = (points[j * 2 + 1] - points[i * 2 + 1]) as f32;     let len = (dx * dx + dy * dy).sqrt();
library/map/src/main/rust/src/tess/ribbon/mod.rs
diff --git a/library/map/src/main/rust/src/tess/ribbon/mod.rs b/library/map/src/main/rust/src/tess/ribbon/mod.rsindex 1ebb143795..0428d93917 100644--- a/library/map/src/main/rust/src/tess/ribbon/mod.rs+++ b/library/map/src/main/rust/src/tess/ribbon/mod.rs@@ -63,7 +63,7 @@ //! is also what holds `t = ±1` on the kerb around a bend — with a unit normal the road //! narrows into the turn and every divider slides sideways with it. -mod joins;+pub(crate) mod joins; mod taper;  #[cfg(test)]
library/map/src/main/rust/src/tess/stroke.rs
diff --git a/library/map/src/main/rust/src/tess/stroke.rs b/library/map/src/main/rust/src/tess/stroke.rsindex 4742c40de2..76a1c24971 100644--- a/library/map/src/main/rust/src/tess/stroke.rs+++ b/library/map/src/main/rust/src/tess/stroke.rs@@ -34,6 +34,8 @@ //! drawn over it. Both bands come out of one call, distinguished only by their //! `offset_mul`, so a casing costs one draw rather than two. +use crate::tess::ribbon::joins::{dedupe, direction, segment_length};+ /// Floats per vertex: `x, y, nx, ny, offset_mul, width_mul, distance, z`. /// /// `z` is the draped ground height in the same tile-local unit as `x`/`y` — `0.0`@@ -148,40 +150,6 @@ fn band(     } } -/// Unit direction from point `i` to point `j`.-fn direction(points: &[i32], i: usize, j: usize) -> (f32, f32) {-    let dx = (points[j * 2] - points[i * 2]) as f32;-    let dy = (points[j * 2 + 1] - points[i * 2 + 1]) as f32;-    let len = (dx * dx + dy * dy).sqrt();-    (dx / len, dy / len)-}--fn segment_length(points: &[i32], i: usize, j: usize) -> f32 {-    let dx = (points[j * 2] - points[i * 2]) as f32;-    let dy = (points[j * 2 + 1] - points[i * 2 + 1]) as f32;-    (dx * dx + dy * dy).sqrt()-}--/// Drop consecutive duplicate vertices.-///-/// Simplified tile geometry contains them, and a zero-length segment has no direction-/// — which would put a NaN in the normal and take the whole triangle strip off screen,-/// not just that segment.-fn dedupe(coords: &[i32]) -> Vec<i32> {-    let mut out: Vec<i32> = Vec::with_capacity(coords.len());-    let mut i = 0;-    while i + 1 < coords.len() {-        let (x, y) = (coords[i], coords[i + 1]);-        let len = out.len();-        if len == 0 || out[len - 2] != x || out[len - 1] != y {-            out.push(x);-            out.push(y);-        }-        i += 2;-    }-    out-}- #[cfg(test)] mod tests {     use super::*;