geometry: store some layer data in `GeometryWithRtree`

This commit is contained in:
Mikolaj Wielgus 2024-03-14 13:15:35 +00:00
parent 9730ff215e
commit 93381f39fb
3 changed files with 29 additions and 15 deletions

View File

@ -13,6 +13,18 @@ pub trait ShapeTrait {
fn envelope(&self, margin: f64) -> AABB<[f64; 2]>; fn envelope(&self, margin: f64) -> AABB<[f64; 2]>;
fn width(&self) -> f64; fn width(&self) -> f64;
fn length(&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)] #[enum_dispatch(ShapeTrait)]

View File

@ -7,7 +7,7 @@ use rstar::{primitives::GeomWithData, RTree, RTreeObject};
use crate::{ use crate::{
graph::{GenericIndex, GetNodeIndex}, graph::{GenericIndex, GetNodeIndex},
layout::graph::Retag, layout::graph::{GetLayer, Retag},
}; };
use super::{ use super::{
@ -19,10 +19,10 @@ type BboxedShapeAndIndex<GI> = GeomWithData<Shape, GI>;
#[derive(Debug)] #[derive(Debug)]
pub struct GeometryWithRtree< pub struct GeometryWithRtree<
GW: GetWidth + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<GI> + Copy, GW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<GI> + Copy,
DW: DotWeightTrait<GW> + Copy, DW: DotWeightTrait<GW> + GetLayer + Copy,
SW: SegWeightTrait<GW> + Copy, SW: SegWeightTrait<GW> + GetLayer + Copy,
BW: BendWeightTrait<GW> + Copy, BW: BendWeightTrait<GW> + GetLayer + Copy,
GI: GetNodeIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Copy, GI: GetNodeIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Copy,
DI: GetNodeIndex + Into<GI> + Copy, DI: GetNodeIndex + Into<GI> + Copy,
SI: GetNodeIndex + Into<GI> + Copy, SI: GetNodeIndex + Into<GI> + Copy,
@ -30,6 +30,7 @@ pub struct GeometryWithRtree<
> { > {
geometry: Geometry<GW, DW, SW, BW, GI, DI, SI, BI>, geometry: Geometry<GW, DW, SW, BW, GI, DI, SI, BI>,
rtree: RTree<BboxedShapeAndIndex<GI>>, rtree: RTree<BboxedShapeAndIndex<GI>>,
layer_count: u64,
weight_marker: PhantomData<GW>, weight_marker: PhantomData<GW>,
dot_weight_marker: PhantomData<DW>, dot_weight_marker: PhantomData<DW>,
seg_weight_marker: PhantomData<SW>, seg_weight_marker: PhantomData<SW>,
@ -43,20 +44,21 @@ pub struct GeometryWithRtree<
#[debug_invariant(self.test_envelopes())] #[debug_invariant(self.test_envelopes())]
#[debug_invariant(self.geometry.graph().node_count() == self.rtree.size())] #[debug_invariant(self.geometry.graph().node_count() == self.rtree.size())]
impl< impl<
GW: GetWidth + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<GI> + Copy, GW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<GI> + Copy,
DW: DotWeightTrait<GW> + Copy, DW: DotWeightTrait<GW> + GetLayer + Copy,
SW: SegWeightTrait<GW> + Copy, SW: SegWeightTrait<GW> + GetLayer + Copy,
BW: BendWeightTrait<GW> + Copy, BW: BendWeightTrait<GW> + GetLayer + Copy,
GI: GetNodeIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + PartialEq + Copy, GI: GetNodeIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + PartialEq + Copy,
DI: GetNodeIndex + Into<GI> + Copy, DI: GetNodeIndex + Into<GI> + Copy,
SI: GetNodeIndex + Into<GI> + Copy, SI: GetNodeIndex + Into<GI> + Copy,
BI: GetNodeIndex + Into<GI> + Copy, BI: GetNodeIndex + Into<GI> + Copy,
> GeometryWithRtree<GW, DW, SW, BW, GI, DI, SI, BI> > GeometryWithRtree<GW, DW, SW, BW, GI, DI, SI, BI>
{ {
pub fn new() -> Self { pub fn new(layer_count: u64) -> Self {
Self { Self {
geometry: Geometry::<GW, DW, SW, BW, GI, DI, SI, BI>::new(), geometry: Geometry::<GW, DW, SW, BW, GI, DI, SI, BI>::new(),
rtree: RTree::new(), rtree: RTree::new(),
layer_count,
weight_marker: PhantomData, weight_marker: PhantomData,
dot_weight_marker: PhantomData, dot_weight_marker: PhantomData,
seg_weight_marker: PhantomData, seg_weight_marker: PhantomData,
@ -206,10 +208,10 @@ impl<
} }
impl< impl<
GW: GetWidth + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<GI> + Copy, GW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<GI> + Copy,
DW: DotWeightTrait<GW> + Copy, DW: DotWeightTrait<GW> + GetLayer + Copy,
SW: SegWeightTrait<GW> + Copy, SW: SegWeightTrait<GW> + GetLayer + Copy,
BW: BendWeightTrait<GW> + Copy, BW: BendWeightTrait<GW> + GetLayer + Copy,
GI: GetNodeIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + PartialEq + Copy, GI: GetNodeIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + PartialEq + Copy,
DI: GetNodeIndex + Into<GI> + Copy, DI: GetNodeIndex + Into<GI> + Copy,
SI: GetNodeIndex + Into<GI> + Copy, SI: GetNodeIndex + Into<GI> + Copy,

View File

@ -82,7 +82,7 @@ pub struct Layout<R: RulesTrait> {
impl<R: RulesTrait> Layout<R> { impl<R: RulesTrait> Layout<R> {
pub fn new(rules: R) -> Self { pub fn new(rules: R) -> Self {
Self { Self {
geometry_with_rtree: GeometryWithRtree::new(), geometry_with_rtree: GeometryWithRtree::new(2),
rules, rules,
} }
} }