diff --git a/topola-egui/src/display.rs b/topola-egui/src/display.rs index b36e99c..d34b3f9 100644 --- a/topola-egui/src/display.rs +++ b/topola-egui/src/display.rs @@ -34,7 +34,7 @@ impl Display { viewport: &Viewport, workspace: &Workspace, ) { - let board = workspace.autorouter.navmesher_board().board(); + let board = workspace.autorouter.router().navmesher_board().board(); let layout = board.layout(); // Start from the bottom layer so that top layers are drawn on top. @@ -166,7 +166,7 @@ impl Display { viewport: &Viewport, workspace: &Workspace, ) { - let board = workspace.autorouter.navmesher_board().board(); + let board = workspace.autorouter.router().navmesher_board().board(); let layout = board.layout(); for layer in (0..*layout.layer_count()).rev() { @@ -235,6 +235,7 @@ impl Display { ) { for layer in 0..*workspace .autorouter + .router() .navmesher_board() .board() .layout() @@ -243,6 +244,7 @@ impl Display { if workspace.appearance_panel.visible[layer] { for navmesh in workspace .autorouter + .router() .navmesher_board() .navmesher() .layer_navmeshers()[layer] diff --git a/topola-egui/src/viewport.rs b/topola-egui/src/viewport.rs index 36f9dad..d5920b2 100644 --- a/topola-egui/src/viewport.rs +++ b/topola-egui/src/viewport.rs @@ -55,6 +55,7 @@ impl Viewport { if response.clicked() { if let Some(pin_selector) = workspace .autorouter + .router() .navmesher_board() .board() .point_pin_selector( @@ -118,6 +119,7 @@ impl Viewport { fn boundary_bounding_box(workspace: &Workspace) -> egui::Rect { let first = workspace .autorouter + .router() .navmesher_board() .board() .layout() @@ -130,6 +132,7 @@ impl Viewport { for point in workspace .autorouter + .router() .navmesher_board() .board() .layout() diff --git a/topola-egui/src/workspace.rs b/topola-egui/src/workspace.rs index 38941f1..254248e 100644 --- a/topola-egui/src/workspace.rs +++ b/topola-egui/src/workspace.rs @@ -25,6 +25,6 @@ impl Workspace { pub fn update_appearance_panel(&mut self, ctx: &egui::Context) { self.appearance_panel - .update(ctx, &self.autorouter.navmesher_board().board()); + .update(ctx, &self.autorouter.router().navmesher_board().board()); } } diff --git a/topola/src/autorouter.rs b/topola/src/autorouter.rs index 7a7697b..a2a15e8 100644 --- a/topola/src/autorouter.rs +++ b/topola/src/autorouter.rs @@ -4,12 +4,12 @@ use derive_getters::Getters; -use crate::{Board, Ratsnest, navmesher::NavmesherBoard}; +use crate::{Board, Ratsnest, router::Router}; #[derive(Clone, Debug, Getters)] pub struct Autorouter { - navmesher_board: NavmesherBoard, ratsnest: Ratsnest, + router: Router, } impl Autorouter { @@ -17,7 +17,7 @@ impl Autorouter { let ratsnest = Ratsnest::new(&board); Self { - navmesher_board: NavmesherBoard::new(board), + router: Router::new(board), ratsnest, } } diff --git a/topola/src/connectivity.rs b/topola/src/connectivity.rs new file mode 100644 index 0000000..605ca83 --- /dev/null +++ b/topola/src/connectivity.rs @@ -0,0 +1,31 @@ +// SPDX-FileCopyrightText: 2026 Topola contributors +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use polygon_unionfind::UnionFind; + +use crate::Board; + +pub struct Connectivity { + joints_unionfind: UnionFind, + segments_unionfind: UnionFind, + polygons_unionfind: UnionFind, +} + +impl Connectivity { + pub fn new(board: &Board) -> Self { + let mut this = Connectivity { + joints_unionfind: UnionFind::with_len( + board.layout().joints().collection().num_elements(), + ), + segments_unionfind: UnionFind::with_len( + board.layout().segments().collection().num_elements(), + ), + polygons_unionfind: UnionFind::with_len( + board.layout().polygons().collection().num_elements(), + ), + }; + + TODO + } +} diff --git a/topola/src/drawer.rs b/topola/src/drawer.rs new file mode 100644 index 0000000..e1e6f42 --- /dev/null +++ b/topola/src/drawer.rs @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2026 Topola contributors +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use derive_getters::Getters; + +use crate::navmesher::NavmesherBoard; + +#[derive(Clone, Debug, Getters)] +pub struct Drawer { + navmesher_board: NavmesherBoard, +} + +impl Drawer { + pub fn new(navmesher_board: NavmesherBoard) -> Self { + Self { navmesher_board } + } +} diff --git a/topola/src/lib.rs b/topola/src/lib.rs index c37f5ad..4376b1a 100644 --- a/topola/src/lib.rs +++ b/topola/src/lib.rs @@ -4,11 +4,14 @@ mod autorouter; mod board; +mod drawer; mod layout; mod math; mod navmesher; +mod pathfinder; mod primitives; mod ratsnest; +mod router; mod selection; mod specctra; diff --git a/topola/src/pathfinder.rs b/topola/src/pathfinder.rs new file mode 100644 index 0000000..d1873eb --- /dev/null +++ b/topola/src/pathfinder.rs @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2026 Topola contributors +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use derive_getters::Getters; + +use crate::navmesher::NavmesherBoard; + +#[derive(Clone, Debug, Getters)] +pub struct Pathfinder { + navmesher_board: NavmesherBoard, +} + +impl Pathfinder { + pub fn new(navmesher_board: NavmesherBoard) -> Self { + Self { navmesher_board } + } +} diff --git a/topola/src/router.rs b/topola/src/router.rs new file mode 100644 index 0000000..68427e0 --- /dev/null +++ b/topola/src/router.rs @@ -0,0 +1,26 @@ +// SPDX-FileCopyrightText: 2026 Topola contributors +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use crate::{Board, drawer::Drawer, navmesher::NavmesherBoard, pathfinder::Pathfinder}; + +#[derive(Clone, Debug)] +pub enum Router { + Resting(NavmesherBoard), + Pathfinder(Pathfinder), + Drawer(Drawer), +} + +impl Router { + pub fn new(board: Board) -> Self { + Self::Resting(NavmesherBoard::new(board)) + } + + pub fn navmesher_board(&self) -> &NavmesherBoard { + match self { + Router::Resting(navmesher_board) => navmesher_board, + Router::Pathfinder(pathfinder) => pathfinder.navmesher_board(), + Router::Drawer(drawer) => drawer.navmesher_board(), + } + } +}