Wrap `NavmesherBoard` inside new `Router` struct

This commit is contained in:
Mikolaj Wielgus 2026-03-21 11:52:55 +01:00
parent fa6c1ca522
commit fc3857072c
9 changed files with 107 additions and 6 deletions

View File

@ -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]

View File

@ -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()

View File

@ -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());
}
}

View File

@ -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,
}
}

View File

@ -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
}
}

18
topola/src/drawer.rs Normal file
View File

@ -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 }
}
}

View File

@ -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;

18
topola/src/pathfinder.rs Normal file
View File

@ -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 }
}
}

26
topola/src/router.rs Normal file
View File

@ -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(),
}
}
}