From 3f6073af0332dd346ed4951d87a2494071e68b59 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Thu, 12 Mar 2026 18:52:24 +0100 Subject: [PATCH] Use board boundary as navmesh superpolygon instead of generating it --- topola/src/navmesher.rs | 23 +++++++++++++++-------- topola/src/specctra.rs | 2 ++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/topola/src/navmesher.rs b/topola/src/navmesher.rs index bb73ec6..4f0a079 100644 --- a/topola/src/navmesher.rs +++ b/topola/src/navmesher.rs @@ -12,13 +12,15 @@ use crate::{ #[derive(Clone, Debug, Getters)] pub struct LayerNavmesher { + boundary: Vec<[i64; 2]>, navmeshes: Vec>, inflation_factors: Vec, } impl LayerNavmesher { - pub fn new() -> Self { + pub fn new(boundary: impl IntoIterator) -> Self { Self { + boundary: boundary.into_iter().collect(), navmeshes: vec![RecordingTriangulator::new()], inflation_factors: vec![0.0], } @@ -28,10 +30,10 @@ impl LayerNavmesher { let polygon: Vec<[i64; 2]> = polygon.into_iter().collect(); for i in 0..self.navmeshes.len() { - self.navmeshes[i].insert_polygon_and_rebuild(Self::inflate_polygon( - polygon.clone(), - self.inflation_factors[i], - )); + self.navmeshes[i].insert_polygon_and_rebuild( + Self::inflate_polygon(polygon.clone(), self.inflation_factors[i]), + self.boundary.clone(), + ); } } @@ -74,9 +76,11 @@ pub struct Navmesher { } impl Navmesher { - pub fn new(layer_count: usize) -> Self { + pub fn new(boundary: impl IntoIterator, layer_count: usize) -> Self { + let boundary: Vec<[i64; 2]> = boundary.into_iter().collect(); + Self { - layers: std::iter::repeat_with(LayerNavmesher::new) + layers: std::iter::repeat_with(|| LayerNavmesher::new(boundary.clone())) .take(layer_count) .collect(), } @@ -95,7 +99,10 @@ pub struct NavmesherBoard { impl NavmesherBoard { pub fn with_board(board: Board) -> Self { - let mut navmesher = Navmesher::new(*board.layout().layer_count()); + let mut navmesher = Navmesher::new( + board.layout().boundary().clone(), + *board.layout().layer_count(), + ); for (_, joint) in board.layout().joints().collection() { Self::insert_joint_in_navmesher(&mut navmesher, *joint); diff --git a/topola/src/specctra.rs b/topola/src/specctra.rs index e094864..8a7d8e3 100644 --- a/topola/src/specctra.rs +++ b/topola/src/specctra.rs @@ -50,6 +50,8 @@ impl Board { .coords() .into_owned() .into_iter() + .skip(1) + .rev() .map(|p| [p.x as i64, p.y as i64]) .collect(), dsn.pcb.structure.layers.len(),