feat(drawing/drawing): Store boundaries in Drawing

This commit is contained in:
Ellen Emilia Anna Zscheile 2025-06-10 12:46:36 +02:00
parent 33eb593fe9
commit 1505513552
3 changed files with 47 additions and 2 deletions

View File

@ -7,6 +7,8 @@ use super::write::{ListWriter, WriteSes};
use crate::error::{ParseError, ParseErrorContext}; use crate::error::{ParseError, ParseErrorContext};
use crate::math::PointWithRotation; use crate::math::PointWithRotation;
use crate::ListToken; use crate::ListToken;
use geo_types::{LineString, Polygon as GeoPolygon};
use specctra_derive::{ReadDsn, WriteSes}; use specctra_derive::{ReadDsn, WriteSes};
use std::borrow::Cow; use std::borrow::Cow;
@ -160,6 +162,18 @@ impl Boundary {
Self::Rect(x) => Cow::Owned(x.coords()), Self::Rect(x) => Cow::Owned(x.coords()),
} }
} }
pub fn to_polygon(&self) -> GeoPolygon {
GeoPolygon::new(
LineString(
self.coords()
.iter()
.map(|i| geo_types::coord! { x: i.x, y: i.y })
.collect(),
),
Vec::new(),
)
}
} }
#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] #[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)]
@ -462,6 +476,20 @@ pub struct Polygon {
pub coords: Vec<Point>, pub coords: Vec<Point>,
} }
impl Polygon {
pub fn to_polygon(&self) -> GeoPolygon {
GeoPolygon::new(
LineString(
self.coords
.iter()
.map(|i| geo_types::coord! { x: i.x, y: i.y })
.collect(),
),
Vec::new(),
)
}
}
#[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)] #[derive(ReadDsn, WriteSes, Debug, Clone, PartialEq)]
pub struct Path { pub struct Path {
#[anon] #[anon]

View File

@ -4,7 +4,7 @@
use contracts_try::{debug_ensures, debug_invariant}; use contracts_try::{debug_ensures, debug_invariant};
use derive_getters::Getters; use derive_getters::Getters;
use geo::Point; use geo::{Point, Polygon};
use core::fmt; use core::fmt;
use rstar::{RTree, AABB}; use rstar::{RTree, AABB};
@ -141,6 +141,9 @@ pub struct Drawing<CW, Cel, R> {
BendIndex, BendIndex,
>, >,
rules: R, rules: R,
boundary: Polygon,
place_boundary: Polygon,
} }
impl<CW, Cel, R> Drawing<CW, Cel, R> { impl<CW, Cel, R> Drawing<CW, Cel, R> {
@ -201,10 +204,18 @@ impl<CW: Clone, Cel: Copy, R> Drawing<CW, Cel, R> {
#[debug_invariant(self.test_if_looses_dont_infringe_each_other())] #[debug_invariant(self.test_if_looses_dont_infringe_each_other())]
impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> { impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
pub fn new(rules: R, layer_count: usize) -> Self { pub fn new(
rules: R,
layer_count: usize,
boundary: Polygon,
place_boundary: Option<Polygon>,
) -> Self {
let place_boundary = place_boundary.unwrap_or_else(|| boundary.clone());
Self { Self {
recording_geometry_with_rtree: RecordingGeometryWithRtree::new(layer_count), recording_geometry_with_rtree: RecordingGeometryWithRtree::new(layer_count),
rules, rules,
boundary,
place_boundary,
} }
} }

View File

@ -184,6 +184,12 @@ impl SpecctraDesign {
let mut board = Board::new(Layout::new(Drawing::new( let mut board = Board::new(Layout::new(Drawing::new(
mesadata, mesadata,
self.pcb.structure.layers.len(), self.pcb.structure.layers.len(),
self.pcb.structure.boundary.to_polygon(),
self.pcb
.structure
.place_boundary
.as_ref()
.map(|i| i.to_polygon()),
))); )));
// mapping of pin -> net prepared for adding pins // mapping of pin -> net prepared for adding pins