Revert "Store primitive id for each navpolygon to go back from navmesh to board"

This reverts commit 269e14645e.
This commit is contained in:
Mikolaj Wielgus 2026-03-16 22:28:25 +01:00
parent 269e14645e
commit 41dd0a91f8
2 changed files with 20 additions and 55 deletions

View File

@ -6,15 +6,15 @@ use dearcut::RecordingTriangulator;
use derive_getters::Getters; use derive_getters::Getters;
use crate::{ use crate::{
Board, math, math,
primitives::{Joint, JointId, Polygon, PolygonId, PrimitiveId, Segment, SegmentId, Via, ViaId}, Board,
primitives::{Joint, JointId, Polygon, PolygonId, Segment, SegmentId, Via, ViaId},
}; };
#[derive(Clone, Debug, Getters)] #[derive(Clone, Debug, Getters)]
pub struct LayerNavmesher { pub struct LayerNavmesher {
boundary: Vec<[i64; 2]>, boundary: Vec<[i64; 2]>,
navmeshes: Vec<RecordingTriangulator<i64>>, navmeshes: Vec<RecordingTriangulator<i64>>,
navpolygon_primitive_ids: Vec<PrimitiveId>,
inflation_factors: Vec<f64>, inflation_factors: Vec<f64>,
} }
@ -23,16 +23,11 @@ impl LayerNavmesher {
Self { Self {
boundary: boundary.into_iter().collect(), boundary: boundary.into_iter().collect(),
navmeshes: vec![RecordingTriangulator::new()], navmeshes: vec![RecordingTriangulator::new()],
navpolygon_primitive_ids: vec![],
inflation_factors: vec![0.0], inflation_factors: vec![0.0],
} }
} }
pub fn insert_navpolygon( pub fn insert_polygon(&mut self, polygon: impl IntoIterator<Item = [i64; 2]>) {
&mut self,
primitive_id: PrimitiveId,
polygon: impl IntoIterator<Item = [i64; 2]>,
) {
let polygon: Vec<[i64; 2]> = polygon.into_iter().collect(); let polygon: Vec<[i64; 2]> = polygon.into_iter().collect();
for i in 0..self.navmeshes.len() { for i in 0..self.navmeshes.len() {
@ -41,8 +36,6 @@ impl LayerNavmesher {
self.boundary.clone(), self.boundary.clone(),
); );
} }
self.navpolygon_primitive_ids.push(primitive_id);
} }
fn inflate_polygon( fn inflate_polygon(
@ -94,13 +87,8 @@ impl Navmesher {
} }
} }
pub fn insert_navpolygon( pub fn insert_polygon(&mut self, layer: usize, polygon: impl IntoIterator<Item = [i64; 2]>) {
&mut self, self.layers[layer].insert_polygon(polygon);
layer: usize,
primitive_id: PrimitiveId,
polygon: impl IntoIterator<Item = [i64; 2]>,
) {
self.layers[layer].insert_navpolygon(primitive_id, polygon);
} }
} }
@ -117,36 +105,28 @@ impl NavmesherBoard {
*board.layout().layer_count(), *board.layout().layer_count(),
); );
for (i, joint) in board.layout().joints().collection() { for (_, joint) in board.layout().joints().collection() {
Self::insert_joint_in_navmesher(&mut navmesher, JointId::new(i), *joint); Self::insert_joint_in_navmesher(&mut navmesher, *joint);
} }
for (i, segment) in board.layout().segments().collection() { for (i, segment) in board.layout().segments().collection() {
Self::insert_segment_in_navmesher(&mut navmesher, &board, SegmentId::new(i), *segment); Self::insert_segment_in_navmesher(&mut navmesher, &board, SegmentId::new(i), *segment);
} }
// TODO: vias. for (_, polygon) in board.layout().polygons().collection() {
Self::insert_polygon_in_navmesher(&mut navmesher, polygon.clone());
for (i, polygon) in board.layout().polygons().collection() {
Self::insert_polygon_in_navmesher(&mut navmesher, PolygonId::new(i), polygon.clone());
} }
Self { navmesher, board } Self { navmesher, board }
} }
pub fn insert_joint(&mut self, joint: Joint) -> JointId { pub fn insert_joint(&mut self, joint: Joint) -> JointId {
let joint_id = self.board.add_joint(joint); Self::insert_joint_in_navmesher(&mut self.navmesher, joint);
Self::insert_joint_in_navmesher(&mut self.navmesher, joint_id, joint); self.board.add_joint(joint)
joint_id
} }
fn insert_joint_in_navmesher(navmesher: &mut Navmesher, joint_id: JointId, joint: Joint) { fn insert_joint_in_navmesher(navmesher: &mut Navmesher, joint: Joint) {
navmesher.insert_navpolygon( navmesher.insert_polygon(joint.layer, Self::joint_circumscribed_octagon(joint));
joint.layer,
PrimitiveId::Joint(joint_id),
Self::joint_circumscribed_octagon(joint),
);
} }
fn joint_circumscribed_octagon(joint: Joint) -> [[i64; 2]; 8] { fn joint_circumscribed_octagon(joint: Joint) -> [[i64; 2]; 8] {
@ -181,9 +161,8 @@ impl NavmesherBoard {
) { ) {
let endpoints = board.layout().segment_endpoints(segment_id); let endpoints = board.layout().segment_endpoints(segment_id);
navmesher.insert_navpolygon( navmesher.insert_polygon(
segment.layer, segment.layer,
PrimitiveId::Segment(segment_id),
math::inflated_segment( math::inflated_segment(
endpoints[0].x, endpoints[0].x,
endpoints[0].y, endpoints[0].y,
@ -202,20 +181,13 @@ impl NavmesherBoard {
} }
pub fn insert_polygon(&mut self, polygon: Polygon) -> PolygonId { pub fn insert_polygon(&mut self, polygon: Polygon) -> PolygonId {
let polygon_id = self.board.add_polygon(polygon.clone()); Self::insert_polygon_in_navmesher(&mut self.navmesher, polygon.clone());
Self::insert_polygon_in_navmesher(&mut self.navmesher, polygon_id, polygon); self.board.add_polygon(polygon)
polygon_id
} }
fn insert_polygon_in_navmesher( fn insert_polygon_in_navmesher(navmesher: &mut Navmesher, polygon: Polygon) {
navmesher: &mut Navmesher, navmesher.insert_polygon(
polygon_id: PolygonId,
polygon: Polygon,
) {
navmesher.insert_navpolygon(
polygon.layer, polygon.layer,
PrimitiveId::Polygon(polygon_id),
polygon.vertices.into_iter().map(Into::into), polygon.vertices.into_iter().map(Into::into),
); );
} }

View File

@ -9,16 +9,9 @@ use serde::{Deserialize, Serialize};
use crate::{ use crate::{
Vector2, Vector2,
layout::{NetId, PinId}, layout::{NetId, PinId},
selection::PinSelector,
}; };
#[derive(Clone, Copy, Debug)]
pub enum PrimitiveId {
Joint(JointId),
Segment(SegmentId),
Via(ViaId),
Polygon(PolygonId),
}
#[derive( #[derive(
Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize, Clone, Constructor, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize,
)] )]