diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-14 08:30:58 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-14 08:30:58 +0300 |
| commit | acc5af7cc79a5ee2132c5d10528ca1cf06186832 (patch) | |
| tree | 8be00a773fec66584acb94be963d6c3e05e7c0aa /crates/fparkan-terrain/src | |
| parent | 6c8d9b2dce43a0e8b559785f73a7631935f11132 (diff) | |
| download | fparkan-acc5af7cc79a5ee2132c5d10528ca1cf06186832.tar.xz fparkan-acc5af7cc79a5ee2132c5d10528ca1cf06186832.zip | |
feat(runtime): route AutoDemo patrols through terrain areas
Diffstat (limited to 'crates/fparkan-terrain/src')
| -rw-r--r-- | crates/fparkan-terrain/src/lib.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/crates/fparkan-terrain/src/lib.rs b/crates/fparkan-terrain/src/lib.rs index 64e68144..33d7dfe9 100644 --- a/crates/fparkan-terrain/src/lib.rs +++ b/crates/fparkan-terrain/src/lib.rs @@ -244,6 +244,12 @@ impl TerrainWorld { .iter() .map(|vertex| [vertex[0], vertex[1]]) .collect(), + edge_neighbors: areal + .links + .iter() + .take(areal.vertices.len()) + .map(|link| link.area_ref) + .collect(), }); } @@ -406,6 +412,20 @@ impl TerrainWorld { self.areals.len() } + /// Returns the midpoint of the boundary edge linking two consecutive areas. + /// Links through polygon slots have no boundary midpoint. + #[must_use] + pub fn route_crossing(&self, from: ArealId, to: ArealId) -> Option<[f32; 2]> { + let area = self.areals.get(from.0 as usize)?; + let edge = area + .edge_neighbors + .iter() + .position(|neighbor| *neighbor == Some(to.0))?; + let a = area.polygon[edge]; + let b = area.polygon[(edge + 1) % area.polygon.len()]; + Some([(a[0] + b[0]) * 0.5, (a[1] + b[1]) * 0.5]) + } + /// Returns the number of surface triangles. #[must_use] pub fn surface_count(&self) -> usize { @@ -889,6 +909,7 @@ impl RuntimeTriangle { struct RuntimeAreal { id: ArealId, polygon: Vec<[f32; 2]>, + edge_neighbors: Vec<Option<u32>>, } impl RuntimeAreal { @@ -1189,6 +1210,10 @@ mod tests { assert_eq!(world.areal_count(), 2); assert_eq!( + world.route_crossing(ArealId(0), ArealId(1)), + Some([1.0, 0.5]) + ); + assert_eq!( world.locate_areal([0.25, 0.25, 41.0]).expect("locate"), Some(ArealId(0)) ); |
