From 1505513552c1225b6e7fb70e52f9357d8154fa95 Mon Sep 17 00:00:00 2001 From: Ellen Emilia Anna Zscheile Date: Tue, 10 Jun 2025 12:46:36 +0200 Subject: [PATCH] feat(drawing/drawing): Store boundaries in Drawing --- crates/specctra-core/src/structure.rs | 28 +++++++++++++++++++++++++++ src/drawing/drawing.rs | 15 ++++++++++++-- src/specctra/design.rs | 6 ++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/crates/specctra-core/src/structure.rs b/crates/specctra-core/src/structure.rs index e57bab9..6f21ae5 100644 --- a/crates/specctra-core/src/structure.rs +++ b/crates/specctra-core/src/structure.rs @@ -7,6 +7,8 @@ use super::write::{ListWriter, WriteSes}; use crate::error::{ParseError, ParseErrorContext}; use crate::math::PointWithRotation; use crate::ListToken; + +use geo_types::{LineString, Polygon as GeoPolygon}; use specctra_derive::{ReadDsn, WriteSes}; use std::borrow::Cow; @@ -160,6 +162,18 @@ impl Boundary { 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)] @@ -462,6 +476,20 @@ pub struct Polygon { pub coords: Vec, } +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)] pub struct Path { #[anon] diff --git a/src/drawing/drawing.rs b/src/drawing/drawing.rs index 17f83a5..3442dff 100644 --- a/src/drawing/drawing.rs +++ b/src/drawing/drawing.rs @@ -4,7 +4,7 @@ use contracts_try::{debug_ensures, debug_invariant}; use derive_getters::Getters; -use geo::Point; +use geo::{Point, Polygon}; use core::fmt; use rstar::{RTree, AABB}; @@ -141,6 +141,9 @@ pub struct Drawing { BendIndex, >, rules: R, + + boundary: Polygon, + place_boundary: Polygon, } impl Drawing { @@ -201,10 +204,18 @@ impl Drawing { #[debug_invariant(self.test_if_looses_dont_infringe_each_other())] impl Drawing { - pub fn new(rules: R, layer_count: usize) -> Self { + pub fn new( + rules: R, + layer_count: usize, + boundary: Polygon, + place_boundary: Option, + ) -> Self { + let place_boundary = place_boundary.unwrap_or_else(|| boundary.clone()); Self { recording_geometry_with_rtree: RecordingGeometryWithRtree::new(layer_count), rules, + boundary, + place_boundary, } } diff --git a/src/specctra/design.rs b/src/specctra/design.rs index dbe31bb..8c0c027 100644 --- a/src/specctra/design.rs +++ b/src/specctra/design.rs @@ -184,6 +184,12 @@ impl SpecctraDesign { let mut board = Board::new(Layout::new(Drawing::new( mesadata, 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