diff --git a/src/geometry/shape.rs b/src/geometry/shape.rs index 671b471..cf68147 100644 --- a/src/geometry/shape.rs +++ b/src/geometry/shape.rs @@ -13,6 +13,18 @@ pub trait ShapeTrait { fn envelope(&self, margin: f64) -> AABB<[f64; 2]>; fn width(&self) -> f64; fn length(&self) -> f64; + + fn flat_envelope_3d(&self, margin: f64, layer_count: u64) -> AABB<[f64; 3]> { + let envelope = self.envelope(margin); + AABB::from_corners( + [envelope.lower()[0], envelope.lower()[1], 0.0], + [ + envelope.upper()[0], + envelope.upper()[1], + (layer_count - 1) as f64, + ], + ) + } } #[enum_dispatch(ShapeTrait)] diff --git a/src/geometry/with_rtree.rs b/src/geometry/with_rtree.rs index 6333eae..c901b47 100644 --- a/src/geometry/with_rtree.rs +++ b/src/geometry/with_rtree.rs @@ -7,7 +7,7 @@ use rstar::{primitives::GeomWithData, RTree, RTreeObject}; use crate::{ graph::{GenericIndex, GetNodeIndex}, - layout::graph::Retag, + layout::graph::{GetLayer, Retag}, }; use super::{ @@ -19,10 +19,10 @@ type BboxedShapeAndIndex = GeomWithData; #[derive(Debug)] pub struct GeometryWithRtree< - GW: GetWidth + TryInto + TryInto + TryInto + Retag + Copy, - DW: DotWeightTrait + Copy, - SW: SegWeightTrait + Copy, - BW: BendWeightTrait + Copy, + GW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, + DW: DotWeightTrait + GetLayer + Copy, + SW: SegWeightTrait + GetLayer + Copy, + BW: BendWeightTrait + GetLayer + Copy, GI: GetNodeIndex + TryInto + TryInto + TryInto + Copy, DI: GetNodeIndex + Into + Copy, SI: GetNodeIndex + Into + Copy, @@ -30,6 +30,7 @@ pub struct GeometryWithRtree< > { geometry: Geometry, rtree: RTree>, + layer_count: u64, weight_marker: PhantomData, dot_weight_marker: PhantomData, seg_weight_marker: PhantomData, @@ -43,20 +44,21 @@ pub struct GeometryWithRtree< #[debug_invariant(self.test_envelopes())] #[debug_invariant(self.geometry.graph().node_count() == self.rtree.size())] impl< - GW: GetWidth + TryInto + TryInto + TryInto + Retag + Copy, - DW: DotWeightTrait + Copy, - SW: SegWeightTrait + Copy, - BW: BendWeightTrait + Copy, + GW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, + DW: DotWeightTrait + GetLayer + Copy, + SW: SegWeightTrait + GetLayer + Copy, + BW: BendWeightTrait + GetLayer + Copy, GI: GetNodeIndex + TryInto + TryInto + TryInto + PartialEq + Copy, DI: GetNodeIndex + Into + Copy, SI: GetNodeIndex + Into + Copy, BI: GetNodeIndex + Into + Copy, > GeometryWithRtree { - pub fn new() -> Self { + pub fn new(layer_count: u64) -> Self { Self { geometry: Geometry::::new(), rtree: RTree::new(), + layer_count, weight_marker: PhantomData, dot_weight_marker: PhantomData, seg_weight_marker: PhantomData, @@ -206,10 +208,10 @@ impl< } impl< - GW: GetWidth + TryInto + TryInto + TryInto + Retag + Copy, - DW: DotWeightTrait + Copy, - SW: SegWeightTrait + Copy, - BW: BendWeightTrait + Copy, + GW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, + DW: DotWeightTrait + GetLayer + Copy, + SW: SegWeightTrait + GetLayer + Copy, + BW: BendWeightTrait + GetLayer + Copy, GI: GetNodeIndex + TryInto + TryInto + TryInto + PartialEq + Copy, DI: GetNodeIndex + Into + Copy, SI: GetNodeIndex + Into + Copy, diff --git a/src/layout/layout.rs b/src/layout/layout.rs index 2f837c3..904c2d7 100644 --- a/src/layout/layout.rs +++ b/src/layout/layout.rs @@ -82,7 +82,7 @@ pub struct Layout { impl Layout { pub fn new(rules: R) -> Self { Self { - geometry_with_rtree: GeometryWithRtree::new(), + geometry_with_rtree: GeometryWithRtree::new(2), rules, } }