mirror of https://codeberg.org/topola/topola.git
Wrap `NavmesherBoard` inside new `Router` struct
This commit is contained in:
parent
fa6c1ca522
commit
fc3857072c
|
|
@ -34,7 +34,7 @@ impl Display {
|
||||||
viewport: &Viewport,
|
viewport: &Viewport,
|
||||||
workspace: &Workspace,
|
workspace: &Workspace,
|
||||||
) {
|
) {
|
||||||
let board = workspace.autorouter.navmesher_board().board();
|
let board = workspace.autorouter.router().navmesher_board().board();
|
||||||
let layout = board.layout();
|
let layout = board.layout();
|
||||||
|
|
||||||
// Start from the bottom layer so that top layers are drawn on top.
|
// Start from the bottom layer so that top layers are drawn on top.
|
||||||
|
|
@ -166,7 +166,7 @@ impl Display {
|
||||||
viewport: &Viewport,
|
viewport: &Viewport,
|
||||||
workspace: &Workspace,
|
workspace: &Workspace,
|
||||||
) {
|
) {
|
||||||
let board = workspace.autorouter.navmesher_board().board();
|
let board = workspace.autorouter.router().navmesher_board().board();
|
||||||
let layout = board.layout();
|
let layout = board.layout();
|
||||||
|
|
||||||
for layer in (0..*layout.layer_count()).rev() {
|
for layer in (0..*layout.layer_count()).rev() {
|
||||||
|
|
@ -235,6 +235,7 @@ impl Display {
|
||||||
) {
|
) {
|
||||||
for layer in 0..*workspace
|
for layer in 0..*workspace
|
||||||
.autorouter
|
.autorouter
|
||||||
|
.router()
|
||||||
.navmesher_board()
|
.navmesher_board()
|
||||||
.board()
|
.board()
|
||||||
.layout()
|
.layout()
|
||||||
|
|
@ -243,6 +244,7 @@ impl Display {
|
||||||
if workspace.appearance_panel.visible[layer] {
|
if workspace.appearance_panel.visible[layer] {
|
||||||
for navmesh in workspace
|
for navmesh in workspace
|
||||||
.autorouter
|
.autorouter
|
||||||
|
.router()
|
||||||
.navmesher_board()
|
.navmesher_board()
|
||||||
.navmesher()
|
.navmesher()
|
||||||
.layer_navmeshers()[layer]
|
.layer_navmeshers()[layer]
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ impl Viewport {
|
||||||
if response.clicked() {
|
if response.clicked() {
|
||||||
if let Some(pin_selector) = workspace
|
if let Some(pin_selector) = workspace
|
||||||
.autorouter
|
.autorouter
|
||||||
|
.router()
|
||||||
.navmesher_board()
|
.navmesher_board()
|
||||||
.board()
|
.board()
|
||||||
.point_pin_selector(
|
.point_pin_selector(
|
||||||
|
|
@ -118,6 +119,7 @@ impl Viewport {
|
||||||
fn boundary_bounding_box(workspace: &Workspace) -> egui::Rect {
|
fn boundary_bounding_box(workspace: &Workspace) -> egui::Rect {
|
||||||
let first = workspace
|
let first = workspace
|
||||||
.autorouter
|
.autorouter
|
||||||
|
.router()
|
||||||
.navmesher_board()
|
.navmesher_board()
|
||||||
.board()
|
.board()
|
||||||
.layout()
|
.layout()
|
||||||
|
|
@ -130,6 +132,7 @@ impl Viewport {
|
||||||
|
|
||||||
for point in workspace
|
for point in workspace
|
||||||
.autorouter
|
.autorouter
|
||||||
|
.router()
|
||||||
.navmesher_board()
|
.navmesher_board()
|
||||||
.board()
|
.board()
|
||||||
.layout()
|
.layout()
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,6 @@ impl Workspace {
|
||||||
|
|
||||||
pub fn update_appearance_panel(&mut self, ctx: &egui::Context) {
|
pub fn update_appearance_panel(&mut self, ctx: &egui::Context) {
|
||||||
self.appearance_panel
|
self.appearance_panel
|
||||||
.update(ctx, &self.autorouter.navmesher_board().board());
|
.update(ctx, &self.autorouter.router().navmesher_board().board());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@
|
||||||
|
|
||||||
use derive_getters::Getters;
|
use derive_getters::Getters;
|
||||||
|
|
||||||
use crate::{Board, Ratsnest, navmesher::NavmesherBoard};
|
use crate::{Board, Ratsnest, router::Router};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Getters)]
|
#[derive(Clone, Debug, Getters)]
|
||||||
pub struct Autorouter {
|
pub struct Autorouter {
|
||||||
navmesher_board: NavmesherBoard,
|
|
||||||
ratsnest: Ratsnest,
|
ratsnest: Ratsnest,
|
||||||
|
router: Router,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Autorouter {
|
impl Autorouter {
|
||||||
|
|
@ -17,7 +17,7 @@ impl Autorouter {
|
||||||
let ratsnest = Ratsnest::new(&board);
|
let ratsnest = Ratsnest::new(&board);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
navmesher_board: NavmesherBoard::new(board),
|
router: Router::new(board),
|
||||||
ratsnest,
|
ratsnest,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,11 +4,14 @@
|
||||||
|
|
||||||
mod autorouter;
|
mod autorouter;
|
||||||
mod board;
|
mod board;
|
||||||
|
mod drawer;
|
||||||
mod layout;
|
mod layout;
|
||||||
mod math;
|
mod math;
|
||||||
mod navmesher;
|
mod navmesher;
|
||||||
|
mod pathfinder;
|
||||||
mod primitives;
|
mod primitives;
|
||||||
mod ratsnest;
|
mod ratsnest;
|
||||||
|
mod router;
|
||||||
mod selection;
|
mod selection;
|
||||||
mod specctra;
|
mod specctra;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue