mirror of https://codeberg.org/topola/topola.git
geometry,drawing: rename grouping to compound, node to node weight
This commit is contained in:
parent
13dd000dba
commit
bad487f6af
|
|
@ -9,12 +9,12 @@ use super::{
|
|||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Collect<'a, GW: Copy, R: RulesTrait> {
|
||||
drawing: &'a Drawing<GW, R>,
|
||||
pub struct Collect<'a, CW: Copy, R: RulesTrait> {
|
||||
drawing: &'a Drawing<CW, R>,
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> Collect<'a, GW, R> {
|
||||
pub fn new(drawing: &'a Drawing<GW, R>) -> Self {
|
||||
impl<'a, CW: Copy, R: RulesTrait> Collect<'a, CW, R> {
|
||||
pub fn new(drawing: &'a Drawing<CW, R>) -> Self {
|
||||
Self { drawing }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ use crate::drawing::{
|
|||
SeqLooseSegIndex, SeqLooseSegWeight,
|
||||
},
|
||||
};
|
||||
use crate::geometry::grouping::GroupingManagerTrait;
|
||||
use crate::geometry::compound::CompoundManagerTrait;
|
||||
use crate::geometry::with_rtree::BboxedIndex;
|
||||
use crate::geometry::Node;
|
||||
use crate::geometry::NodeWeight;
|
||||
use crate::geometry::{
|
||||
primitive::{PrimitiveShape, PrimitiveShapeTrait},
|
||||
with_rtree::GeometryWithRtree,
|
||||
|
|
@ -70,13 +70,13 @@ pub struct Collision(pub PrimitiveShape, pub PrimitiveIndex);
|
|||
pub struct AlreadyConnected(pub usize, pub PrimitiveIndex);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Drawing<GW: Copy, R: RulesTrait> {
|
||||
pub struct Drawing<CW: Copy, R: RulesTrait> {
|
||||
geometry_with_rtree: GeometryWithRtree<
|
||||
PrimitiveWeight,
|
||||
DotWeight,
|
||||
SegWeight,
|
||||
BendWeight,
|
||||
GW,
|
||||
CW,
|
||||
PrimitiveIndex,
|
||||
DotIndex,
|
||||
SegIndex,
|
||||
|
|
@ -85,7 +85,7 @@ pub struct Drawing<GW: Copy, R: RulesTrait> {
|
|||
rules: R,
|
||||
}
|
||||
|
||||
impl<GW: Copy, R: RulesTrait> Drawing<GW, R> {
|
||||
impl<CW: Copy, R: RulesTrait> Drawing<CW, R> {
|
||||
pub fn new(rules: R) -> Self {
|
||||
Self {
|
||||
geometry_with_rtree: GeometryWithRtree::new(2),
|
||||
|
|
@ -639,7 +639,7 @@ impl<GW: Copy, R: RulesTrait> Drawing<GW, R> {
|
|||
.rtree()
|
||||
.iter()
|
||||
.filter_map(|wrapper| {
|
||||
if let Node::Primitive(primitive_node) = wrapper.data {
|
||||
if let NodeWeight::Primitive(primitive_node) = wrapper.data {
|
||||
Some(primitive_node)
|
||||
} else {
|
||||
None
|
||||
|
|
@ -655,7 +655,7 @@ impl<GW: Copy, R: RulesTrait> Drawing<GW, R> {
|
|||
[f64::INFINITY, f64::INFINITY, layer as f64],
|
||||
))
|
||||
.filter_map(|wrapper| {
|
||||
if let Node::Primitive(primitive_node) = wrapper.data {
|
||||
if let NodeWeight::Primitive(primitive_node) = wrapper.data {
|
||||
Some(primitive_node)
|
||||
} else {
|
||||
None
|
||||
|
|
@ -668,7 +668,7 @@ impl<GW: Copy, R: RulesTrait> Drawing<GW, R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<GW: Copy, R: RulesTrait> Drawing<GW, R> {
|
||||
impl<CW: Copy, R: RulesTrait> Drawing<CW, R> {
|
||||
#[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))]
|
||||
#[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
|
||||
pub fn move_dot(&mut self, dot: DotIndex, to: Point) -> Result<(), Infringement> {
|
||||
|
|
@ -750,7 +750,7 @@ impl<GW: Copy, R: RulesTrait> Drawing<GW, R> {
|
|||
.rtree()
|
||||
.locate_in_envelope_intersecting(&limiting_shape.full_height_envelope_3d(0.0, 2))
|
||||
.filter_map(|wrapper| {
|
||||
if let Node::Primitive(primitive_node) = wrapper.data {
|
||||
if let NodeWeight::Primitive(primitive_node) = wrapper.data {
|
||||
Some(primitive_node)
|
||||
} else {
|
||||
None
|
||||
|
|
@ -785,7 +785,7 @@ impl<GW: Copy, R: RulesTrait> Drawing<GW, R> {
|
|||
.rtree()
|
||||
.locate_in_envelope_intersecting(&shape.full_height_envelope_3d(0.0, 2))
|
||||
.filter_map(|wrapper| {
|
||||
if let Node::Primitive(primitive_node) = wrapper.data {
|
||||
if let NodeWeight::Primitive(primitive_node) = wrapper.data {
|
||||
Some(primitive_node)
|
||||
} else {
|
||||
None
|
||||
|
|
@ -812,7 +812,7 @@ impl<GW: Copy, R: RulesTrait> Drawing<GW, R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<GW: Copy, R: RulesTrait> Drawing<GW, R> {
|
||||
impl<CW: Copy, R: RulesTrait> Drawing<CW, R> {
|
||||
#[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))]
|
||||
#[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
|
||||
pub fn geometry(
|
||||
|
|
@ -822,7 +822,7 @@ impl<GW: Copy, R: RulesTrait> Drawing<GW, R> {
|
|||
DotWeight,
|
||||
SegWeight,
|
||||
BendWeight,
|
||||
GW,
|
||||
CW,
|
||||
PrimitiveIndex,
|
||||
DotIndex,
|
||||
SegIndex,
|
||||
|
|
@ -833,7 +833,7 @@ impl<GW: Copy, R: RulesTrait> Drawing<GW, R> {
|
|||
|
||||
#[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))]
|
||||
#[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
|
||||
pub fn rtree(&self) -> &RTree<BboxedIndex<Node<PrimitiveIndex, GenericIndex<GW>>>> {
|
||||
pub fn rtree(&self) -> &RTree<BboxedIndex<NodeWeight<PrimitiveIndex, GenericIndex<CW>>>> {
|
||||
self.geometry_with_rtree.rtree()
|
||||
}
|
||||
|
||||
|
|
@ -845,50 +845,50 @@ impl<GW: Copy, R: RulesTrait> Drawing<GW, R> {
|
|||
|
||||
#[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))]
|
||||
#[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
|
||||
pub fn guide(&self) -> Guide<GW, R> {
|
||||
pub fn guide(&self) -> Guide<CW, R> {
|
||||
Guide::new(self)
|
||||
}
|
||||
|
||||
#[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))]
|
||||
#[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
|
||||
pub fn collect(&self) -> Collect<GW, R> {
|
||||
pub fn collect(&self) -> Collect<CW, R> {
|
||||
Collect::new(self)
|
||||
}
|
||||
|
||||
#[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))]
|
||||
#[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
|
||||
pub fn primitive<W>(&self, index: GenericIndex<W>) -> GenericPrimitive<W, GW, R> {
|
||||
pub fn primitive<W>(&self, index: GenericIndex<W>) -> GenericPrimitive<W, CW, R> {
|
||||
GenericPrimitive::new(index, self)
|
||||
}
|
||||
|
||||
#[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))]
|
||||
#[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
|
||||
pub fn wraparoundable(&self, index: WraparoundableIndex) -> Wraparoundable<GW, R> {
|
||||
pub fn wraparoundable(&self, index: WraparoundableIndex) -> Wraparoundable<CW, R> {
|
||||
Wraparoundable::new(index, self)
|
||||
}
|
||||
|
||||
#[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))]
|
||||
#[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
|
||||
pub fn loose(&self, index: LooseIndex) -> Loose<GW, R> {
|
||||
pub fn loose(&self, index: LooseIndex) -> Loose<CW, R> {
|
||||
Loose::new(index, self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<GW: Copy, R: RulesTrait> GroupingManagerTrait<GW, GenericIndex<GW>> for Drawing<GW, R> {
|
||||
fn add_grouping(&mut self, weight: GW) -> GenericIndex<GW> {
|
||||
self.geometry_with_rtree.add_grouping(weight)
|
||||
impl<CW: Copy, R: RulesTrait> CompoundManagerTrait<CW, GenericIndex<CW>> for Drawing<CW, R> {
|
||||
fn add_compound(&mut self, weight: CW) -> GenericIndex<CW> {
|
||||
self.geometry_with_rtree.add_compound(weight)
|
||||
}
|
||||
|
||||
fn remove_grouping(&mut self, grouping: GenericIndex<GW>) {
|
||||
self.geometry_with_rtree.remove_grouping(grouping);
|
||||
fn remove_compound(&mut self, compound: GenericIndex<CW>) {
|
||||
self.geometry_with_rtree.remove_compound(compound);
|
||||
}
|
||||
|
||||
fn assign_to_grouping<W>(&mut self, primitive: GenericIndex<W>, grouping: GenericIndex<GW>) {
|
||||
fn add_to_compound<W>(&mut self, primitive: GenericIndex<W>, compound: GenericIndex<CW>) {
|
||||
self.geometry_with_rtree
|
||||
.assign_to_grouping(primitive, grouping);
|
||||
.add_to_compound(primitive, compound);
|
||||
}
|
||||
|
||||
fn groupings<W>(&self, node: GenericIndex<W>) -> impl Iterator<Item = GenericIndex<GW>> {
|
||||
self.geometry_with_rtree.groupings(node)
|
||||
fn compounds<W>(&self, node: GenericIndex<W>) -> impl Iterator<Item = GenericIndex<CW>> {
|
||||
self.geometry_with_rtree.compounds(node)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ pub trait GetMaybeNet {
|
|||
|
||||
#[enum_dispatch]
|
||||
pub trait MakePrimitive {
|
||||
fn primitive<'a, GW: Copy, R: RulesTrait>(
|
||||
fn primitive<'a, CW: Copy, R: RulesTrait>(
|
||||
&self,
|
||||
drawing: &'a Drawing<GW, R>,
|
||||
) -> Primitive<'a, GW, R>;
|
||||
drawing: &'a Drawing<CW, R>,
|
||||
) -> Primitive<'a, CW, R>;
|
||||
}
|
||||
|
||||
macro_rules! impl_weight {
|
||||
|
|
@ -61,10 +61,10 @@ macro_rules! impl_weight {
|
|||
pub type $index_struct = GenericIndex<$weight_struct>;
|
||||
|
||||
impl MakePrimitive for $index_struct {
|
||||
fn primitive<'a, GW: Copy, R: RulesTrait>(
|
||||
fn primitive<'a, CW: Copy, R: RulesTrait>(
|
||||
&self,
|
||||
drawing: &'a Drawing<GW, R>,
|
||||
) -> Primitive<'a, GW, R> {
|
||||
drawing: &'a Drawing<CW, R>,
|
||||
) -> Primitive<'a, CW, R> {
|
||||
Primitive::$weight_variant(GenericPrimitive::new(*self, drawing))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,12 +56,12 @@ impl HeadTrait for SegbendHead {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Guide<'a, GW: Copy, R: RulesTrait> {
|
||||
drawing: &'a Drawing<GW, R>,
|
||||
pub struct Guide<'a, CW: Copy, R: RulesTrait> {
|
||||
drawing: &'a Drawing<CW, R>,
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> Guide<'a, GW, R> {
|
||||
pub fn new(drawing: &'a Drawing<GW, R>) -> Self {
|
||||
impl<'a, CW: Copy, R: RulesTrait> Guide<'a, CW, R> {
|
||||
pub fn new(drawing: &'a Drawing<CW, R>) -> Self {
|
||||
Self { drawing }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,15 +41,15 @@ impl From<LooseIndex> for PrimitiveIndex {
|
|||
}
|
||||
|
||||
#[enum_dispatch(GetNextLoose, GetDrawing, GetNodeIndex)]
|
||||
pub enum Loose<'a, GW: Copy, R: RulesTrait> {
|
||||
Dot(LooseDot<'a, GW, R>),
|
||||
LoneSeg(LoneLooseSeg<'a, GW, R>),
|
||||
SeqSeg(SeqLooseSeg<'a, GW, R>),
|
||||
Bend(LooseBend<'a, GW, R>),
|
||||
pub enum Loose<'a, CW: Copy, R: RulesTrait> {
|
||||
Dot(LooseDot<'a, CW, R>),
|
||||
LoneSeg(LoneLooseSeg<'a, CW, R>),
|
||||
SeqSeg(SeqLooseSeg<'a, CW, R>),
|
||||
Bend(LooseBend<'a, CW, R>),
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> Loose<'a, GW, R> {
|
||||
pub fn new(index: LooseIndex, drawing: &'a Drawing<GW, R>) -> Self {
|
||||
impl<'a, CW: Copy, R: RulesTrait> Loose<'a, CW, R> {
|
||||
pub fn new(index: LooseIndex, drawing: &'a Drawing<CW, R>) -> Self {
|
||||
match index {
|
||||
LooseIndex::Dot(dot) => drawing.primitive(dot).into(),
|
||||
LooseIndex::LoneSeg(seg) => drawing.primitive(seg).into(),
|
||||
|
|
@ -59,7 +59,7 @@ impl<'a, GW: Copy, R: RulesTrait> Loose<'a, GW, R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetNextLoose for LooseDot<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetNextLoose for LooseDot<'a, CW, R> {
|
||||
fn next_loose(&self, maybe_prev: Option<LooseIndex>) -> Option<LooseIndex> {
|
||||
let bend = self.bend();
|
||||
let Some(prev) = maybe_prev else {
|
||||
|
|
@ -74,13 +74,13 @@ impl<'a, GW: Copy, R: RulesTrait> GetNextLoose for LooseDot<'a, GW, R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetNextLoose for LoneLooseSeg<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetNextLoose for LoneLooseSeg<'a, CW, R> {
|
||||
fn next_loose(&self, _maybe_prev: Option<LooseIndex>) -> Option<LooseIndex> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetNextLoose for SeqLooseSeg<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetNextLoose for SeqLooseSeg<'a, CW, R> {
|
||||
fn next_loose(&self, maybe_prev: Option<LooseIndex>) -> Option<LooseIndex> {
|
||||
let ends = self.joints();
|
||||
let Some(prev) = maybe_prev else {
|
||||
|
|
@ -98,7 +98,7 @@ impl<'a, GW: Copy, R: RulesTrait> GetNextLoose for SeqLooseSeg<'a, GW, R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetNextLoose for LooseBend<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetNextLoose for LooseBend<'a, CW, R> {
|
||||
fn next_loose(&self, maybe_prev: Option<LooseIndex>) -> Option<LooseIndex> {
|
||||
let ends = self.joints();
|
||||
let Some(prev) = maybe_prev else {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ use crate::{
|
|||
},
|
||||
Drawing,
|
||||
},
|
||||
geometry::Node,
|
||||
geometry::NodeWeight,
|
||||
};
|
||||
|
||||
#[enum_dispatch]
|
||||
|
|
@ -117,8 +117,8 @@ pub trait GetInnerOuter<'a, R: RulesTrait>: GetDrawing<'a, R> + GetBendIndex {
|
|||
|
||||
macro_rules! impl_primitive {
|
||||
($primitive_struct:ident, $weight_struct:ident) => {
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetWeight<$weight_struct>
|
||||
for $primitive_struct<'a, GW, R>
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetWeight<$weight_struct>
|
||||
for $primitive_struct<'a, CW, R>
|
||||
{
|
||||
fn weight(&self) -> $weight_struct {
|
||||
if let PrimitiveWeight::$primitive_struct(weight) = self.tagged_weight() {
|
||||
|
|
@ -129,13 +129,13 @@ macro_rules! impl_primitive {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetLayer for $primitive_struct<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetLayer for $primitive_struct<'a, CW, R> {
|
||||
fn layer(&self) -> u64 {
|
||||
self.weight().layer()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetMaybeNet for $primitive_struct<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetMaybeNet for $primitive_struct<'a, CW, R> {
|
||||
fn maybe_net(&self) -> Option<usize> {
|
||||
self.weight().maybe_net()
|
||||
}
|
||||
|
|
@ -164,29 +164,29 @@ macro_rules! impl_loose_primitive {
|
|||
GetLimbs,
|
||||
GetConditions
|
||||
)]
|
||||
pub enum Primitive<'a, GW: Copy, R: RulesTrait> {
|
||||
FixedDot(FixedDot<'a, GW, R>),
|
||||
LooseDot(LooseDot<'a, GW, R>),
|
||||
FixedSeg(FixedSeg<'a, GW, R>),
|
||||
LoneLooseSeg(LoneLooseSeg<'a, GW, R>),
|
||||
SeqLooseSeg(SeqLooseSeg<'a, GW, R>),
|
||||
FixedBend(FixedBend<'a, GW, R>),
|
||||
LooseBend(LooseBend<'a, GW, R>),
|
||||
pub enum Primitive<'a, CW: Copy, R: RulesTrait> {
|
||||
FixedDot(FixedDot<'a, CW, R>),
|
||||
LooseDot(LooseDot<'a, CW, R>),
|
||||
FixedSeg(FixedSeg<'a, CW, R>),
|
||||
LoneLooseSeg(LoneLooseSeg<'a, CW, R>),
|
||||
SeqLooseSeg(SeqLooseSeg<'a, CW, R>),
|
||||
FixedBend(FixedBend<'a, CW, R>),
|
||||
LooseBend(LooseBend<'a, CW, R>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GenericPrimitive<'a, W, GW: Copy, R: RulesTrait> {
|
||||
pub struct GenericPrimitive<'a, W, CW: Copy, R: RulesTrait> {
|
||||
pub index: GenericIndex<W>,
|
||||
drawing: &'a Drawing<GW, R>,
|
||||
drawing: &'a Drawing<CW, R>,
|
||||
}
|
||||
|
||||
impl<'a, W, GW: Copy, R: RulesTrait> GenericPrimitive<'a, W, GW, R> {
|
||||
pub fn new(index: GenericIndex<W>, drawing: &'a Drawing<GW, R>) -> Self {
|
||||
impl<'a, W, CW: Copy, R: RulesTrait> GenericPrimitive<'a, W, CW, R> {
|
||||
pub fn new(index: GenericIndex<W>, drawing: &'a Drawing<CW, R>) -> Self {
|
||||
Self { index, drawing }
|
||||
}
|
||||
|
||||
fn tagged_weight(&self) -> PrimitiveWeight {
|
||||
if let Node::Primitive(weight) = *self
|
||||
if let NodeWeight::Primitive(weight) = *self
|
||||
.drawing
|
||||
.geometry()
|
||||
.graph()
|
||||
|
|
@ -199,43 +199,43 @@ impl<'a, W, GW: Copy, R: RulesTrait> GenericPrimitive<'a, W, GW, R> {
|
|||
}
|
||||
}
|
||||
|
||||
fn primitive<WW>(&self, index: GenericIndex<WW>) -> GenericPrimitive<WW, GW, R> {
|
||||
fn primitive<WW>(&self, index: GenericIndex<WW>) -> GenericPrimitive<WW, CW, R> {
|
||||
GenericPrimitive::new(index, &self.drawing)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, W, GW: Copy, R: RulesTrait> GetInterior<PrimitiveIndex>
|
||||
for GenericPrimitive<'a, W, GW, R>
|
||||
impl<'a, W, CW: Copy, R: RulesTrait> GetInterior<PrimitiveIndex>
|
||||
for GenericPrimitive<'a, W, CW, R>
|
||||
{
|
||||
fn interior(&self) -> Vec<PrimitiveIndex> {
|
||||
vec![self.tagged_weight().retag(self.index.node_index())]
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, W, GW: Copy, R: RulesTrait> GetDrawing<'a, R> for GenericPrimitive<'a, W, GW, R> {
|
||||
impl<'a, W, CW: Copy, R: RulesTrait> GetDrawing<'a, R> for GenericPrimitive<'a, W, CW, R> {
|
||||
fn drawing(&self) -> &Drawing<impl Copy, R> {
|
||||
self.drawing
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, W, GW: Copy, R: RulesTrait> GetNodeIndex for GenericPrimitive<'a, W, GW, R> {
|
||||
impl<'a, W, CW: Copy, R: RulesTrait> GetNodeIndex for GenericPrimitive<'a, W, CW, R> {
|
||||
fn node_index(&self) -> NodeIndex<usize> {
|
||||
self.index.node_index()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, W: GetWidth, GW: Copy, R: RulesTrait> GetWidth for GenericPrimitive<'a, W, GW, R>
|
||||
impl<'a, W: GetWidth, CW: Copy, R: RulesTrait> GetWidth for GenericPrimitive<'a, W, CW, R>
|
||||
where
|
||||
GenericPrimitive<'a, W, GW, R>: GetWeight<W>,
|
||||
GenericPrimitive<'a, W, CW, R>: GetWeight<W>,
|
||||
{
|
||||
fn width(&self) -> f64 {
|
||||
self.weight().width()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, W, GW: Copy, R: RulesTrait> GetConditions for GenericPrimitive<'a, W, GW, R>
|
||||
impl<'a, W, CW: Copy, R: RulesTrait> GetConditions for GenericPrimitive<'a, W, CW, R>
|
||||
where
|
||||
GenericPrimitive<'a, W, GW, R>: GetMaybeNet,
|
||||
GenericPrimitive<'a, W, CW, R>: GetMaybeNet,
|
||||
{
|
||||
fn conditions(&self) -> Conditions {
|
||||
Conditions {
|
||||
|
|
@ -246,10 +246,10 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub type FixedDot<'a, GW, R> = GenericPrimitive<'a, FixedDotWeight, GW, R>;
|
||||
pub type FixedDot<'a, CW, R> = GenericPrimitive<'a, FixedDotWeight, CW, R>;
|
||||
impl_fixed_primitive!(FixedDot, FixedDotWeight);
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> FixedDot<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> FixedDot<'a, CW, R> {
|
||||
pub fn first_loose(&self, _band: BandIndex) -> Option<LooseIndex> {
|
||||
self.drawing
|
||||
.geometry()
|
||||
|
|
@ -262,9 +262,15 @@ impl<'a, GW: Copy, R: RulesTrait> FixedDot<'a, GW, R> {
|
|||
.graph()
|
||||
.node_weight(ni.node_index())
|
||||
.unwrap();
|
||||
if matches!(weight, Node::Primitive(PrimitiveWeight::LoneLooseSeg(..))) {
|
||||
if matches!(
|
||||
weight,
|
||||
NodeWeight::Primitive(PrimitiveWeight::LoneLooseSeg(..))
|
||||
) {
|
||||
Some(LoneLooseSegIndex::new(ni.node_index()).into())
|
||||
} else if matches!(weight, Node::Primitive(PrimitiveWeight::SeqLooseSeg(..))) {
|
||||
} else if matches!(
|
||||
weight,
|
||||
NodeWeight::Primitive(PrimitiveWeight::SeqLooseSeg(..))
|
||||
) {
|
||||
Some(SeqLooseSegIndex::new(ni.node_index()).into())
|
||||
} else {
|
||||
None
|
||||
|
|
@ -273,13 +279,13 @@ impl<'a, GW: Copy, R: RulesTrait> FixedDot<'a, GW, R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> MakeShape for FixedDot<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> MakeShape for FixedDot<'a, CW, R> {
|
||||
fn shape(&self) -> PrimitiveShape {
|
||||
self.drawing.geometry().dot_shape(self.index.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetLimbs for FixedDot<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetLimbs for FixedDot<'a, CW, R> {
|
||||
fn segs(&self) -> Vec<SegIndex> {
|
||||
self.drawing
|
||||
.geometry()
|
||||
|
|
@ -295,12 +301,12 @@ impl<'a, GW: Copy, R: RulesTrait> GetLimbs for FixedDot<'a, GW, R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetFirstRail<'a, R> for FixedDot<'a, GW, R> {}
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetFirstRail<'a, R> for FixedDot<'a, CW, R> {}
|
||||
|
||||
pub type LooseDot<'a, GW, R> = GenericPrimitive<'a, LooseDotWeight, GW, R>;
|
||||
pub type LooseDot<'a, CW, R> = GenericPrimitive<'a, LooseDotWeight, CW, R>;
|
||||
impl_loose_primitive!(LooseDot, LooseDotWeight);
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> LooseDot<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> LooseDot<'a, CW, R> {
|
||||
pub fn seg(&self) -> Option<SeqLooseSegIndex> {
|
||||
self.drawing
|
||||
.geometry()
|
||||
|
|
@ -319,13 +325,13 @@ impl<'a, GW: Copy, R: RulesTrait> LooseDot<'a, GW, R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> MakeShape for LooseDot<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> MakeShape for LooseDot<'a, CW, R> {
|
||||
fn shape(&self) -> PrimitiveShape {
|
||||
self.drawing.geometry().dot_shape(self.index.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetLimbs for LooseDot<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetLimbs for LooseDot<'a, CW, R> {
|
||||
fn segs(&self) -> Vec<SegIndex> {
|
||||
if let Some(seg) = self.seg() {
|
||||
vec![seg.into()]
|
||||
|
|
@ -339,18 +345,18 @@ impl<'a, GW: Copy, R: RulesTrait> GetLimbs for LooseDot<'a, GW, R> {
|
|||
}
|
||||
}
|
||||
|
||||
pub type FixedSeg<'a, GW, R> = GenericPrimitive<'a, FixedSegWeight, GW, R>;
|
||||
pub type FixedSeg<'a, CW, R> = GenericPrimitive<'a, FixedSegWeight, CW, R>;
|
||||
impl_fixed_primitive!(FixedSeg, FixedSegWeight);
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> MakeShape for FixedSeg<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> MakeShape for FixedSeg<'a, CW, R> {
|
||||
fn shape(&self) -> PrimitiveShape {
|
||||
self.drawing.geometry().seg_shape(self.index.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetLimbs for FixedSeg<'a, GW, R> {}
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetLimbs for FixedSeg<'a, CW, R> {}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetJoints<FixedDotIndex, FixedDotIndex> for FixedSeg<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetJoints<FixedDotIndex, FixedDotIndex> for FixedSeg<'a, CW, R> {
|
||||
fn joints(&self) -> (FixedDotIndex, FixedDotIndex) {
|
||||
let (from, to) = self.drawing.geometry().seg_joints(self.index.into());
|
||||
(
|
||||
|
|
@ -360,24 +366,24 @@ impl<'a, GW: Copy, R: RulesTrait> GetJoints<FixedDotIndex, FixedDotIndex> for Fi
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetOtherJoint<FixedDotIndex, FixedDotIndex>
|
||||
for FixedSeg<'a, GW, R>
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetOtherJoint<FixedDotIndex, FixedDotIndex>
|
||||
for FixedSeg<'a, CW, R>
|
||||
{
|
||||
}
|
||||
|
||||
pub type LoneLooseSeg<'a, GW, R> = GenericPrimitive<'a, LoneLooseSegWeight, GW, R>;
|
||||
pub type LoneLooseSeg<'a, CW, R> = GenericPrimitive<'a, LoneLooseSegWeight, CW, R>;
|
||||
impl_loose_primitive!(LoneLooseSeg, LoneLooseSegWeight);
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> MakeShape for LoneLooseSeg<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> MakeShape for LoneLooseSeg<'a, CW, R> {
|
||||
fn shape(&self) -> PrimitiveShape {
|
||||
self.drawing.geometry().seg_shape(self.index.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetLimbs for LoneLooseSeg<'a, GW, R> {}
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetLimbs for LoneLooseSeg<'a, CW, R> {}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetJoints<FixedDotIndex, FixedDotIndex>
|
||||
for LoneLooseSeg<'a, GW, R>
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetJoints<FixedDotIndex, FixedDotIndex>
|
||||
for LoneLooseSeg<'a, CW, R>
|
||||
{
|
||||
fn joints(&self) -> (FixedDotIndex, FixedDotIndex) {
|
||||
let (from, to) = self.drawing.geometry().seg_joints(self.index.into());
|
||||
|
|
@ -388,23 +394,23 @@ impl<'a, GW: Copy, R: RulesTrait> GetJoints<FixedDotIndex, FixedDotIndex>
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetOtherJoint<FixedDotIndex, FixedDotIndex>
|
||||
for LoneLooseSeg<'a, GW, R>
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetOtherJoint<FixedDotIndex, FixedDotIndex>
|
||||
for LoneLooseSeg<'a, CW, R>
|
||||
{
|
||||
}
|
||||
|
||||
pub type SeqLooseSeg<'a, GW, R> = GenericPrimitive<'a, SeqLooseSegWeight, GW, R>;
|
||||
pub type SeqLooseSeg<'a, CW, R> = GenericPrimitive<'a, SeqLooseSegWeight, CW, R>;
|
||||
impl_loose_primitive!(SeqLooseSeg, SeqLooseSegWeight);
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> MakeShape for SeqLooseSeg<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> MakeShape for SeqLooseSeg<'a, CW, R> {
|
||||
fn shape(&self) -> PrimitiveShape {
|
||||
self.drawing.geometry().seg_shape(self.index.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetLimbs for SeqLooseSeg<'a, GW, R> {}
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetLimbs for SeqLooseSeg<'a, CW, R> {}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetJoints<DotIndex, LooseDotIndex> for SeqLooseSeg<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetJoints<DotIndex, LooseDotIndex> for SeqLooseSeg<'a, CW, R> {
|
||||
fn joints(&self) -> (DotIndex, LooseDotIndex) {
|
||||
let joints = self.drawing.geometry().seg_joints(self.index.into());
|
||||
if let DotWeight::Fixed(..) = self.drawing.geometry().dot_weight(joints.0) {
|
||||
|
|
@ -426,29 +432,29 @@ impl<'a, GW: Copy, R: RulesTrait> GetJoints<DotIndex, LooseDotIndex> for SeqLoos
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetOtherJoint<DotIndex, LooseDotIndex>
|
||||
for SeqLooseSeg<'a, GW, R>
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetOtherJoint<DotIndex, LooseDotIndex>
|
||||
for SeqLooseSeg<'a, CW, R>
|
||||
{
|
||||
}
|
||||
|
||||
pub type FixedBend<'a, GW, R> = GenericPrimitive<'a, FixedBendWeight, GW, R>;
|
||||
pub type FixedBend<'a, CW, R> = GenericPrimitive<'a, FixedBendWeight, CW, R>;
|
||||
impl_fixed_primitive!(FixedBend, FixedBendWeight);
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetBendIndex for FixedBend<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetBendIndex for FixedBend<'a, CW, R> {
|
||||
fn bend_index(&self) -> BendIndex {
|
||||
self.index.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> MakeShape for FixedBend<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> MakeShape for FixedBend<'a, CW, R> {
|
||||
fn shape(&self) -> PrimitiveShape {
|
||||
self.drawing.geometry().bend_shape(self.index.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetLimbs for FixedBend<'a, GW, R> {}
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetLimbs for FixedBend<'a, CW, R> {}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetJoints<FixedDotIndex, FixedDotIndex> for FixedBend<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetJoints<FixedDotIndex, FixedDotIndex> for FixedBend<'a, CW, R> {
|
||||
fn joints(&self) -> (FixedDotIndex, FixedDotIndex) {
|
||||
let (from, to) = self.drawing.geometry().bend_joints(self.index.into());
|
||||
(
|
||||
|
|
@ -458,44 +464,44 @@ impl<'a, GW: Copy, R: RulesTrait> GetJoints<FixedDotIndex, FixedDotIndex> for Fi
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetOtherJoint<FixedDotIndex, FixedDotIndex>
|
||||
for FixedBend<'a, GW, R>
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetOtherJoint<FixedDotIndex, FixedDotIndex>
|
||||
for FixedBend<'a, CW, R>
|
||||
{
|
||||
}
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetFirstRail<'a, R> for FixedBend<'a, GW, R> {}
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetCore<'a, R> for FixedBend<'a, GW, R> {} // TODO: Fixed bends don't have cores actually.
|
||||
//impl<'a, R: QueryRules> GetInnerOuter for FixedBend<'a, GW, R> {}
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetFirstRail<'a, R> for FixedBend<'a, CW, R> {}
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetCore<'a, R> for FixedBend<'a, CW, R> {} // TODO: Fixed bends don't have cores actually.
|
||||
//impl<'a, R: QueryRules> GetInnerOuter for FixedBend<'a, CW, R> {}
|
||||
|
||||
pub type LooseBend<'a, GW, R> = GenericPrimitive<'a, LooseBendWeight, GW, R>;
|
||||
pub type LooseBend<'a, CW, R> = GenericPrimitive<'a, LooseBendWeight, CW, R>;
|
||||
impl_loose_primitive!(LooseBend, LooseBendWeight);
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetBendIndex for LooseBend<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetBendIndex for LooseBend<'a, CW, R> {
|
||||
fn bend_index(&self) -> BendIndex {
|
||||
self.index.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> From<LooseBend<'a, GW, R>> for BendIndex {
|
||||
fn from(bend: LooseBend<'a, GW, R>) -> BendIndex {
|
||||
impl<'a, CW: Copy, R: RulesTrait> From<LooseBend<'a, CW, R>> for BendIndex {
|
||||
fn from(bend: LooseBend<'a, CW, R>) -> BendIndex {
|
||||
bend.index.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> MakeShape for LooseBend<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> MakeShape for LooseBend<'a, CW, R> {
|
||||
fn shape(&self) -> PrimitiveShape {
|
||||
self.drawing.geometry().bend_shape(self.index.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetLimbs for LooseBend<'a, GW, R> {}
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetLimbs for LooseBend<'a, CW, R> {}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetOffset for LooseBend<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetOffset for LooseBend<'a, CW, R> {
|
||||
fn offset(&self) -> f64 {
|
||||
self.weight().offset
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetJoints<LooseDotIndex, LooseDotIndex> for LooseBend<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetJoints<LooseDotIndex, LooseDotIndex> for LooseBend<'a, CW, R> {
|
||||
fn joints(&self) -> (LooseDotIndex, LooseDotIndex) {
|
||||
let (from, to) = self.drawing.geometry().bend_joints(self.index.into());
|
||||
(
|
||||
|
|
@ -505,9 +511,9 @@ impl<'a, GW: Copy, R: RulesTrait> GetJoints<LooseDotIndex, LooseDotIndex> for Lo
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetOtherJoint<LooseDotIndex, LooseDotIndex>
|
||||
for LooseBend<'a, GW, R>
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetOtherJoint<LooseDotIndex, LooseDotIndex>
|
||||
for LooseBend<'a, CW, R>
|
||||
{
|
||||
}
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetCore<'a, R> for LooseBend<'a, GW, R> {}
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetInnerOuter<'a, R> for LooseBend<'a, GW, R> {}
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetCore<'a, R> for LooseBend<'a, CW, R> {}
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetInnerOuter<'a, R> for LooseBend<'a, CW, R> {}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::{
|
|||
rules::DsnRules,
|
||||
structure::{self, DsnFile, Layer, Pcb, Shape},
|
||||
},
|
||||
geometry::grouping::GroupingManagerTrait,
|
||||
geometry::compound::CompoundManagerTrait,
|
||||
graph::{GenericIndex, GetNodeIndex},
|
||||
layout::{
|
||||
zone::{SolidZoneWeight, ZoneIndex},
|
||||
|
|
@ -348,7 +348,7 @@ impl DsnDesign {
|
|||
layer: u64,
|
||||
net: usize,
|
||||
) {
|
||||
let zone = layout.add_grouping(
|
||||
let zone = layout.add_compound(
|
||||
SolidZoneWeight {
|
||||
layer,
|
||||
maybe_net: Some(net),
|
||||
|
|
@ -539,7 +539,7 @@ impl DsnDesign {
|
|||
layer: u64,
|
||||
net: usize,
|
||||
) {
|
||||
let zone = layout.add_grouping(
|
||||
let zone = layout.add_compound(
|
||||
SolidZoneWeight {
|
||||
layer,
|
||||
maybe_net: Some(net),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
use crate::graph::{GenericIndex, GetNodeIndex};
|
||||
|
||||
pub trait CompoundManagerTrait<CW: Copy, GI: GetNodeIndex + Copy> {
|
||||
fn add_compound(&mut self, weight: CW) -> GenericIndex<CW>;
|
||||
fn remove_compound(&mut self, compound: GenericIndex<CW>);
|
||||
fn add_to_compound<W>(&mut self, node: GenericIndex<W>, compound: GenericIndex<CW>);
|
||||
fn compounds<W>(&self, node: GenericIndex<W>) -> impl Iterator<Item = GenericIndex<CW>>;
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ use crate::{
|
|||
seg::{FixedSegWeight, LoneLooseSegWeight, SegWeight, SeqLooseSegWeight},
|
||||
},
|
||||
geometry::{
|
||||
grouping::GroupingManagerTrait,
|
||||
compound::CompoundManagerTrait,
|
||||
primitive::{BendShape, DotShape, PrimitiveShape, SegShape},
|
||||
},
|
||||
graph::{GenericIndex, GetNodeIndex},
|
||||
|
|
@ -55,18 +55,18 @@ pub enum GeometryLabel {
|
|||
Joined,
|
||||
Outer,
|
||||
Core,
|
||||
Grouping,
|
||||
Compound,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum Node<PW, GW> {
|
||||
pub enum NodeWeight<PW, CW> {
|
||||
Primitive(PW),
|
||||
Grouping(GW),
|
||||
Compound(CW),
|
||||
}
|
||||
|
||||
pub trait DotWeightTrait<GW>: GetPos + SetPos + GetWidth + Into<GW> + Copy {}
|
||||
pub trait SegWeightTrait<GW>: GetWidth + Into<GW> + Copy {}
|
||||
pub trait BendWeightTrait<GW>: GetOffset + SetOffset + GetWidth + Into<GW> + Copy {}
|
||||
pub trait DotWeightTrait<CW>: GetPos + SetPos + GetWidth + Into<CW> + Copy {}
|
||||
pub trait SegWeightTrait<CW>: GetWidth + Into<CW> + Copy {}
|
||||
pub trait BendWeightTrait<CW>: GetOffset + SetOffset + GetWidth + Into<CW> + Copy {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Geometry<
|
||||
|
|
@ -74,18 +74,18 @@ pub struct Geometry<
|
|||
DW: DotWeightTrait<PW>,
|
||||
SW: SegWeightTrait<PW>,
|
||||
BW: BendWeightTrait<PW>,
|
||||
GW: Copy,
|
||||
CW: Copy,
|
||||
PI: GetNodeIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Copy,
|
||||
DI: GetNodeIndex + Into<PI> + Copy,
|
||||
SI: GetNodeIndex + Into<PI> + Copy,
|
||||
BI: GetNodeIndex + Into<PI> + Copy,
|
||||
> {
|
||||
graph: StableDiGraph<Node<PW, GW>, GeometryLabel, usize>,
|
||||
graph: StableDiGraph<NodeWeight<PW, CW>, GeometryLabel, usize>,
|
||||
weight_marker: PhantomData<PW>,
|
||||
dot_weight_marker: PhantomData<DW>,
|
||||
seg_weight_marker: PhantomData<SW>,
|
||||
bend_weight_marker: PhantomData<BW>,
|
||||
grouping_weight_marker: PhantomData<GW>,
|
||||
compound_weight_marker: PhantomData<CW>,
|
||||
index_marker: PhantomData<PI>,
|
||||
dot_index_marker: PhantomData<DI>,
|
||||
seg_index_marker: PhantomData<SI>,
|
||||
|
|
@ -97,12 +97,12 @@ impl<
|
|||
DW: DotWeightTrait<PW>,
|
||||
SW: SegWeightTrait<PW>,
|
||||
BW: BendWeightTrait<PW>,
|
||||
GW: Copy,
|
||||
CW: Copy,
|
||||
PI: GetNodeIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Copy,
|
||||
DI: GetNodeIndex + Into<PI> + Copy,
|
||||
SI: GetNodeIndex + Into<PI> + Copy,
|
||||
BI: GetNodeIndex + Into<PI> + Copy,
|
||||
> Geometry<PW, DW, SW, BW, GW, PI, DI, SI, BI>
|
||||
> Geometry<PW, DW, SW, BW, CW, PI, DI, SI, BI>
|
||||
{
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
|
@ -111,7 +111,7 @@ impl<
|
|||
dot_weight_marker: PhantomData,
|
||||
seg_weight_marker: PhantomData,
|
||||
bend_weight_marker: PhantomData,
|
||||
grouping_weight_marker: PhantomData,
|
||||
compound_weight_marker: PhantomData,
|
||||
index_marker: PhantomData,
|
||||
dot_index_marker: PhantomData,
|
||||
seg_index_marker: PhantomData,
|
||||
|
|
@ -120,7 +120,7 @@ impl<
|
|||
}
|
||||
|
||||
pub fn add_dot<W: DotWeightTrait<PW>>(&mut self, weight: W) -> GenericIndex<W> {
|
||||
GenericIndex::<W>::new(self.graph.add_node(Node::Primitive(weight.into())))
|
||||
GenericIndex::<W>::new(self.graph.add_node(NodeWeight::Primitive(weight.into())))
|
||||
}
|
||||
|
||||
pub fn add_seg<W: SegWeightTrait<PW>>(
|
||||
|
|
@ -129,7 +129,7 @@ impl<
|
|||
to: DI,
|
||||
weight: W,
|
||||
) -> GenericIndex<W> {
|
||||
let seg = GenericIndex::<W>::new(self.graph.add_node(Node::Primitive(weight.into())));
|
||||
let seg = GenericIndex::<W>::new(self.graph.add_node(NodeWeight::Primitive(weight.into())));
|
||||
|
||||
self.graph
|
||||
.update_edge(from.node_index(), seg.node_index(), GeometryLabel::Joined);
|
||||
|
|
@ -146,7 +146,8 @@ impl<
|
|||
core: DI,
|
||||
weight: W,
|
||||
) -> GenericIndex<W> {
|
||||
let bend = GenericIndex::<W>::new(self.graph.add_node(Node::Primitive(weight.into())));
|
||||
let bend =
|
||||
GenericIndex::<W>::new(self.graph.add_node(NodeWeight::Primitive(weight.into())));
|
||||
|
||||
self.graph
|
||||
.update_edge(from.node_index(), bend.node_index(), GeometryLabel::Joined);
|
||||
|
|
@ -165,13 +166,15 @@ impl<
|
|||
pub fn move_dot(&mut self, dot: DI, to: Point) {
|
||||
let mut weight = self.dot_weight(dot);
|
||||
weight.set_pos(to);
|
||||
*self.graph.node_weight_mut(dot.node_index()).unwrap() = Node::Primitive(weight.into());
|
||||
*self.graph.node_weight_mut(dot.node_index()).unwrap() =
|
||||
NodeWeight::Primitive(weight.into());
|
||||
}
|
||||
|
||||
pub fn shift_bend(&mut self, bend: BI, offset: f64) {
|
||||
let mut weight = self.bend_weight(bend);
|
||||
weight.set_offset(offset);
|
||||
*self.graph.node_weight_mut(bend.node_index()).unwrap() = Node::Primitive(weight.into());
|
||||
*self.graph.node_weight_mut(bend.node_index()).unwrap() =
|
||||
NodeWeight::Primitive(weight.into());
|
||||
}
|
||||
|
||||
pub fn flip_bend(&mut self, bend: BI) {
|
||||
|
|
@ -267,7 +270,7 @@ impl<
|
|||
}
|
||||
|
||||
fn primitive_weight(&self, index: NodeIndex<usize>) -> PW {
|
||||
if let Node::Primitive(weight) = *self.graph.node_weight(index).unwrap() {
|
||||
if let NodeWeight::Primitive(weight) = *self.graph.node_weight(index).unwrap() {
|
||||
weight
|
||||
} else {
|
||||
unreachable!()
|
||||
|
|
@ -292,8 +295,10 @@ impl<
|
|||
.unwrap_or_else(|_| unreachable!())
|
||||
}
|
||||
|
||||
pub fn grouping_weight(&self, grouping: GenericIndex<GW>) -> GW {
|
||||
if let Node::Grouping(weight) = *self.graph.node_weight(grouping.node_index()).unwrap() {
|
||||
pub fn compound_weight(&self, compound: GenericIndex<CW>) -> CW {
|
||||
if let NodeWeight::Compound(weight) =
|
||||
*self.graph.node_weight(compound.node_index()).unwrap()
|
||||
{
|
||||
weight
|
||||
} else {
|
||||
unreachable!()
|
||||
|
|
@ -449,15 +454,15 @@ impl<
|
|||
self.joineds(dot.into()).filter_map(|ni| ni.try_into().ok())
|
||||
}
|
||||
|
||||
pub fn grouping_members(&self, grouping: GenericIndex<GW>) -> impl Iterator<Item = PI> + '_ {
|
||||
pub fn compound_members(&self, compound: GenericIndex<CW>) -> impl Iterator<Item = PI> + '_ {
|
||||
self.graph
|
||||
.neighbors_directed(grouping.node_index(), Incoming)
|
||||
.neighbors_directed(compound.node_index(), Incoming)
|
||||
.filter(move |ni| {
|
||||
matches!(
|
||||
self.graph
|
||||
.edge_weight(self.graph.find_edge(*ni, grouping.node_index()).unwrap())
|
||||
.edge_weight(self.graph.find_edge(*ni, compound.node_index()).unwrap())
|
||||
.unwrap(),
|
||||
GeometryLabel::Grouping
|
||||
GeometryLabel::Compound
|
||||
)
|
||||
})
|
||||
.map(|ni| {
|
||||
|
|
@ -468,7 +473,7 @@ impl<
|
|||
})
|
||||
}
|
||||
|
||||
pub fn graph(&self) -> &StableDiGraph<Node<PW, GW>, GeometryLabel, usize> {
|
||||
pub fn graph(&self) -> &StableDiGraph<NodeWeight<PW, CW>, GeometryLabel, usize> {
|
||||
&self.graph
|
||||
}
|
||||
}
|
||||
|
|
@ -478,30 +483,30 @@ impl<
|
|||
DW: DotWeightTrait<PW>,
|
||||
SW: SegWeightTrait<PW>,
|
||||
BW: BendWeightTrait<PW>,
|
||||
GW: Copy,
|
||||
CW: Copy,
|
||||
PI: GetNodeIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Copy,
|
||||
DI: GetNodeIndex + Into<PI> + Copy,
|
||||
SI: GetNodeIndex + Into<PI> + Copy,
|
||||
BI: GetNodeIndex + Into<PI> + Copy,
|
||||
> GroupingManagerTrait<GW, GenericIndex<GW>> for Geometry<PW, DW, SW, BW, GW, PI, DI, SI, BI>
|
||||
> CompoundManagerTrait<CW, GenericIndex<CW>> for Geometry<PW, DW, SW, BW, CW, PI, DI, SI, BI>
|
||||
{
|
||||
fn add_grouping(&mut self, weight: GW) -> GenericIndex<GW> {
|
||||
GenericIndex::<GW>::new(self.graph.add_node(Node::Grouping(weight)))
|
||||
fn add_compound(&mut self, weight: CW) -> GenericIndex<CW> {
|
||||
GenericIndex::<CW>::new(self.graph.add_node(NodeWeight::Compound(weight)))
|
||||
}
|
||||
|
||||
fn remove_grouping(&mut self, grouping: GenericIndex<GW>) {
|
||||
self.graph.remove_node(grouping.node_index());
|
||||
fn remove_compound(&mut self, compound: GenericIndex<CW>) {
|
||||
self.graph.remove_node(compound.node_index());
|
||||
}
|
||||
|
||||
fn assign_to_grouping<W>(&mut self, primitive: GenericIndex<W>, grouping: GenericIndex<GW>) {
|
||||
fn add_to_compound<W>(&mut self, primitive: GenericIndex<W>, compound: GenericIndex<CW>) {
|
||||
self.graph.update_edge(
|
||||
primitive.node_index(),
|
||||
grouping.node_index(),
|
||||
GeometryLabel::Grouping,
|
||||
compound.node_index(),
|
||||
GeometryLabel::Compound,
|
||||
);
|
||||
}
|
||||
|
||||
fn groupings<W>(&self, node: GenericIndex<W>) -> impl Iterator<Item = GenericIndex<GW>> {
|
||||
fn compounds<W>(&self, node: GenericIndex<W>) -> impl Iterator<Item = GenericIndex<CW>> {
|
||||
self.graph
|
||||
.neighbors(node.node_index())
|
||||
.filter(move |ni| {
|
||||
|
|
@ -509,7 +514,7 @@ impl<
|
|||
self.graph
|
||||
.edge_weight(self.graph.find_edge(node.node_index(), *ni).unwrap())
|
||||
.unwrap(),
|
||||
GeometryLabel::Grouping
|
||||
GeometryLabel::Compound
|
||||
)
|
||||
})
|
||||
.map(|ni| GenericIndex::new(ni))
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
use crate::graph::{GenericIndex, GetNodeIndex};
|
||||
|
||||
pub trait GroupingManagerTrait<GW: Copy, GI: GetNodeIndex + Copy> {
|
||||
fn add_grouping(&mut self, weight: GW) -> GenericIndex<GW>;
|
||||
fn remove_grouping(&mut self, grouping: GenericIndex<GW>);
|
||||
fn assign_to_grouping<W>(&mut self, node: GenericIndex<W>, grouping: GenericIndex<GW>);
|
||||
fn groupings<W>(&self, node: GenericIndex<W>) -> impl Iterator<Item = GenericIndex<GW>>;
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#[macro_use]
|
||||
mod geometry;
|
||||
pub mod grouping;
|
||||
pub mod compound;
|
||||
pub mod primitive;
|
||||
mod shape;
|
||||
pub mod with_rtree;
|
||||
|
|
|
|||
|
|
@ -8,9 +8,10 @@ use rstar::{primitives::GeomWithData, Envelope, RTree, RTreeObject, AABB};
|
|||
use crate::{
|
||||
drawing::graph::{GetLayer, Retag},
|
||||
geometry::{
|
||||
grouping::GroupingManagerTrait,
|
||||
compound::CompoundManagerTrait,
|
||||
primitive::{PrimitiveShape, PrimitiveShapeTrait},
|
||||
BendWeightTrait, DotWeightTrait, Geometry, GeometryLabel, GetWidth, Node, SegWeightTrait,
|
||||
BendWeightTrait, DotWeightTrait, Geometry, GeometryLabel, GetWidth, NodeWeight,
|
||||
SegWeightTrait,
|
||||
},
|
||||
graph::{GenericIndex, GetNodeIndex},
|
||||
};
|
||||
|
|
@ -41,14 +42,14 @@ pub struct GeometryWithRtree<
|
|||
DW: DotWeightTrait<PW> + GetLayer,
|
||||
SW: SegWeightTrait<PW> + GetLayer,
|
||||
BW: BendWeightTrait<PW> + GetLayer,
|
||||
GW: Copy,
|
||||
CW: Copy,
|
||||
PI: GetNodeIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Copy,
|
||||
DI: GetNodeIndex + Into<PI> + Copy,
|
||||
SI: GetNodeIndex + Into<PI> + Copy,
|
||||
BI: GetNodeIndex + Into<PI> + Copy,
|
||||
> {
|
||||
geometry: Geometry<PW, DW, SW, BW, GW, PI, DI, SI, BI>,
|
||||
rtree: RTree<BboxedIndex<Node<PI, GenericIndex<GW>>>>,
|
||||
geometry: Geometry<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||
rtree: RTree<BboxedIndex<NodeWeight<PI, GenericIndex<CW>>>>,
|
||||
layer_count: u64,
|
||||
weight_marker: PhantomData<PW>,
|
||||
dot_weight_marker: PhantomData<DW>,
|
||||
|
|
@ -67,16 +68,16 @@ impl<
|
|||
DW: DotWeightTrait<PW> + GetLayer,
|
||||
SW: SegWeightTrait<PW> + GetLayer,
|
||||
BW: BendWeightTrait<PW> + GetLayer,
|
||||
GW: Copy,
|
||||
CW: Copy,
|
||||
PI: GetNodeIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + PartialEq + Copy,
|
||||
DI: GetNodeIndex + Into<PI> + Copy,
|
||||
SI: GetNodeIndex + Into<PI> + Copy,
|
||||
BI: GetNodeIndex + Into<PI> + Copy,
|
||||
> GeometryWithRtree<PW, DW, SW, BW, GW, PI, DI, SI, BI>
|
||||
> GeometryWithRtree<PW, DW, SW, BW, CW, PI, DI, SI, BI>
|
||||
{
|
||||
pub fn new(layer_count: u64) -> Self {
|
||||
Self {
|
||||
geometry: Geometry::<PW, DW, SW, BW, GW, PI, DI, SI, BI>::new(),
|
||||
geometry: Geometry::<PW, DW, SW, BW, CW, PI, DI, SI, BI>::new(),
|
||||
rtree: RTree::new(),
|
||||
layer_count,
|
||||
weight_marker: PhantomData,
|
||||
|
|
@ -101,7 +102,7 @@ impl<
|
|||
.dot_shape(dot.into().try_into().unwrap_or_else(|_| unreachable!()))
|
||||
.envelope_3d(0.0, weight.layer()),
|
||||
),
|
||||
Node::Primitive(dot.into()),
|
||||
NodeWeight::Primitive(dot.into()),
|
||||
));
|
||||
dot
|
||||
}
|
||||
|
|
@ -122,7 +123,7 @@ impl<
|
|||
.seg_shape(seg.into().try_into().unwrap_or_else(|_| unreachable!()))
|
||||
.envelope_3d(0.0, weight.layer()),
|
||||
),
|
||||
Node::Primitive(seg.into()),
|
||||
NodeWeight::Primitive(seg.into()),
|
||||
));
|
||||
seg
|
||||
}
|
||||
|
|
@ -144,19 +145,15 @@ impl<
|
|||
.bend_shape(bend.into().try_into().unwrap_or_else(|_| unreachable!()))
|
||||
.envelope_3d(0.0, weight.layer()),
|
||||
),
|
||||
Node::Primitive(bend.into()),
|
||||
NodeWeight::Primitive(bend.into()),
|
||||
));
|
||||
bend
|
||||
}
|
||||
|
||||
pub fn assign_to_grouping<W>(
|
||||
&mut self,
|
||||
primitive: GenericIndex<W>,
|
||||
grouping: GenericIndex<GW>,
|
||||
) {
|
||||
self.rtree.remove(&self.make_grouping_bbox(grouping));
|
||||
self.geometry.assign_to_grouping(primitive, grouping);
|
||||
self.rtree.insert(self.make_grouping_bbox(grouping));
|
||||
pub fn add_to_compound<W>(&mut self, primitive: GenericIndex<W>, compound: GenericIndex<CW>) {
|
||||
self.rtree.remove(&self.make_compound_bbox(compound));
|
||||
self.geometry.add_to_compound(primitive, compound);
|
||||
self.rtree.insert(self.make_compound_bbox(compound));
|
||||
}
|
||||
|
||||
pub fn remove_dot(&mut self, dot: DI) -> Result<(), ()> {
|
||||
|
|
@ -183,9 +180,9 @@ impl<
|
|||
self.geometry.remove_primitive(bend.into());
|
||||
}
|
||||
|
||||
pub fn remove_grouping(&mut self, grouping: GenericIndex<GW>) {
|
||||
self.rtree.remove(&self.make_grouping_bbox(grouping));
|
||||
self.geometry.remove_grouping(grouping);
|
||||
pub fn remove_compound(&mut self, compound: GenericIndex<CW>) {
|
||||
self.rtree.remove(&self.make_compound_bbox(compound));
|
||||
self.geometry.remove_compound(compound);
|
||||
}
|
||||
|
||||
pub fn move_dot(&mut self, dot: DI, to: Point) {
|
||||
|
|
@ -261,14 +258,14 @@ impl<
|
|||
DW: DotWeightTrait<PW> + GetLayer,
|
||||
SW: SegWeightTrait<PW> + GetLayer,
|
||||
BW: BendWeightTrait<PW> + GetLayer,
|
||||
GW: Copy,
|
||||
CW: Copy,
|
||||
PI: GetNodeIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + PartialEq + Copy,
|
||||
DI: GetNodeIndex + Into<PI> + Copy,
|
||||
SI: GetNodeIndex + Into<PI> + Copy,
|
||||
BI: GetNodeIndex + Into<PI> + Copy,
|
||||
> GeometryWithRtree<PW, DW, SW, BW, GW, PI, DI, SI, BI>
|
||||
> GeometryWithRtree<PW, DW, SW, BW, CW, PI, DI, SI, BI>
|
||||
{
|
||||
fn make_bbox(&self, primitive: PI) -> BboxedIndex<Node<PI, GenericIndex<GW>>> {
|
||||
fn make_bbox(&self, primitive: PI) -> BboxedIndex<NodeWeight<PI, GenericIndex<CW>>> {
|
||||
if let Ok(dot) = <PI as TryInto<DI>>::try_into(primitive) {
|
||||
self.make_dot_bbox(dot)
|
||||
} else if let Ok(seg) = <PI as TryInto<SI>>::try_into(primitive) {
|
||||
|
|
@ -280,50 +277,50 @@ impl<
|
|||
}
|
||||
}
|
||||
|
||||
fn make_dot_bbox(&self, dot: DI) -> BboxedIndex<Node<PI, GenericIndex<GW>>> {
|
||||
fn make_dot_bbox(&self, dot: DI) -> BboxedIndex<NodeWeight<PI, GenericIndex<CW>>> {
|
||||
BboxedIndex::new(
|
||||
Bbox::new(
|
||||
self.geometry
|
||||
.dot_shape(dot)
|
||||
.envelope_3d(0.0, self.layer(dot.into())),
|
||||
),
|
||||
Node::Primitive(dot.into()),
|
||||
NodeWeight::Primitive(dot.into()),
|
||||
)
|
||||
}
|
||||
|
||||
fn make_seg_bbox(&self, seg: SI) -> BboxedIndex<Node<PI, GenericIndex<GW>>> {
|
||||
fn make_seg_bbox(&self, seg: SI) -> BboxedIndex<NodeWeight<PI, GenericIndex<CW>>> {
|
||||
BboxedIndex::new(
|
||||
Bbox::new(
|
||||
self.geometry
|
||||
.seg_shape(seg)
|
||||
.envelope_3d(0.0, self.layer(seg.into())),
|
||||
),
|
||||
Node::Primitive(seg.into()),
|
||||
NodeWeight::Primitive(seg.into()),
|
||||
)
|
||||
}
|
||||
|
||||
fn make_bend_bbox(&self, bend: BI) -> BboxedIndex<Node<PI, GenericIndex<GW>>> {
|
||||
fn make_bend_bbox(&self, bend: BI) -> BboxedIndex<NodeWeight<PI, GenericIndex<CW>>> {
|
||||
BboxedIndex::new(
|
||||
Bbox::new(
|
||||
self.geometry
|
||||
.bend_shape(bend)
|
||||
.envelope_3d(0.0, self.layer(bend.into())),
|
||||
),
|
||||
Node::Primitive(bend.into()),
|
||||
NodeWeight::Primitive(bend.into()),
|
||||
)
|
||||
}
|
||||
|
||||
fn make_grouping_bbox(
|
||||
fn make_compound_bbox(
|
||||
&self,
|
||||
grouping: GenericIndex<GW>,
|
||||
) -> BboxedIndex<Node<PI, GenericIndex<GW>>> {
|
||||
compound: GenericIndex<CW>,
|
||||
) -> BboxedIndex<NodeWeight<PI, GenericIndex<CW>>> {
|
||||
let mut aabb = AABB::<[f64; 3]>::new_empty();
|
||||
|
||||
for member in self.geometry.grouping_members(grouping) {
|
||||
for member in self.geometry.compound_members(compound) {
|
||||
aabb.merge(&self.make_bbox(member).geom().aabb);
|
||||
}
|
||||
|
||||
BboxedIndex::new(Bbox::new(aabb), Node::Grouping(grouping))
|
||||
BboxedIndex::new(Bbox::new(aabb), NodeWeight::Compound(compound))
|
||||
}
|
||||
|
||||
fn shape(&self, primitive: PI) -> PrimitiveShape {
|
||||
|
|
@ -350,30 +347,30 @@ impl<
|
|||
}
|
||||
}
|
||||
|
||||
pub fn geometry(&self) -> &Geometry<PW, DW, SW, BW, GW, PI, DI, SI, BI> {
|
||||
pub fn geometry(&self) -> &Geometry<PW, DW, SW, BW, CW, PI, DI, SI, BI> {
|
||||
&self.geometry
|
||||
}
|
||||
|
||||
// XXX: The type appears wrong? I don't think it should contain GW?
|
||||
pub fn rtree(&self) -> &RTree<BboxedIndex<Node<PI, GenericIndex<GW>>>> {
|
||||
// XXX: The type appears wrong? I don't think it should contain CW?
|
||||
pub fn rtree(&self) -> &RTree<BboxedIndex<NodeWeight<PI, GenericIndex<CW>>>> {
|
||||
&self.rtree
|
||||
}
|
||||
|
||||
pub fn graph(&self) -> &StableDiGraph<Node<PW, GW>, GeometryLabel, usize> {
|
||||
pub fn graph(&self) -> &StableDiGraph<NodeWeight<PW, CW>, GeometryLabel, usize> {
|
||||
self.geometry.graph()
|
||||
}
|
||||
|
||||
fn test_envelopes(&self) -> bool {
|
||||
!self.rtree.iter().any(|wrapper| {
|
||||
// TODO: Test envelopes of groupings too.
|
||||
let Node::Primitive(primitive_node) = wrapper.data else {
|
||||
// TODO: Test envelopes of compounds too.
|
||||
let NodeWeight::Primitive(primitive_node) = wrapper.data else {
|
||||
return false;
|
||||
};
|
||||
let shape = self.shape(primitive_node);
|
||||
let layer = self.layer(primitive_node);
|
||||
let wrapper = BboxedIndex::new(
|
||||
Bbox::new(shape.envelope_3d(0.0, layer)),
|
||||
Node::Primitive(primitive_node),
|
||||
NodeWeight::Primitive(primitive_node),
|
||||
);
|
||||
!self
|
||||
.rtree
|
||||
|
|
@ -388,30 +385,30 @@ impl<
|
|||
DW: DotWeightTrait<PW> + GetLayer,
|
||||
SW: SegWeightTrait<PW> + GetLayer,
|
||||
BW: BendWeightTrait<PW> + GetLayer,
|
||||
GW: Copy,
|
||||
CW: Copy,
|
||||
PI: GetNodeIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + PartialEq + Copy,
|
||||
DI: GetNodeIndex + Into<PI> + Copy,
|
||||
SI: GetNodeIndex + Into<PI> + Copy,
|
||||
BI: GetNodeIndex + Into<PI> + Copy,
|
||||
> GroupingManagerTrait<GW, GenericIndex<GW>>
|
||||
for GeometryWithRtree<PW, DW, SW, BW, GW, PI, DI, SI, BI>
|
||||
> CompoundManagerTrait<CW, GenericIndex<CW>>
|
||||
for GeometryWithRtree<PW, DW, SW, BW, CW, PI, DI, SI, BI>
|
||||
{
|
||||
fn add_grouping(&mut self, weight: GW) -> GenericIndex<GW> {
|
||||
let grouping = self.geometry.add_grouping(weight);
|
||||
self.rtree.insert(self.make_grouping_bbox(grouping));
|
||||
grouping
|
||||
fn add_compound(&mut self, weight: CW) -> GenericIndex<CW> {
|
||||
let compound = self.geometry.add_compound(weight);
|
||||
self.rtree.insert(self.make_compound_bbox(compound));
|
||||
compound
|
||||
}
|
||||
|
||||
fn remove_grouping(&mut self, grouping: GenericIndex<GW>) {
|
||||
self.rtree.remove(&self.make_grouping_bbox(grouping));
|
||||
self.geometry.remove_grouping(grouping);
|
||||
fn remove_compound(&mut self, compound: GenericIndex<CW>) {
|
||||
self.rtree.remove(&self.make_compound_bbox(compound));
|
||||
self.geometry.remove_compound(compound);
|
||||
}
|
||||
|
||||
fn assign_to_grouping<W>(&mut self, primitive: GenericIndex<W>, grouping: GenericIndex<GW>) {
|
||||
self.geometry.assign_to_grouping(primitive, grouping);
|
||||
fn add_to_compound<W>(&mut self, primitive: GenericIndex<W>, compound: GenericIndex<CW>) {
|
||||
self.geometry.add_to_compound(primitive, compound);
|
||||
}
|
||||
|
||||
fn groupings<W>(&self, node: GenericIndex<W>) -> impl Iterator<Item = GenericIndex<GW>> {
|
||||
self.geometry.groupings(node)
|
||||
fn compounds<W>(&self, node: GenericIndex<W>) -> impl Iterator<Item = GenericIndex<CW>> {
|
||||
self.geometry.compounds(node)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ use crate::{
|
|||
Drawing, Infringement, LayoutException,
|
||||
},
|
||||
geometry::{
|
||||
grouping::GroupingManagerTrait, BendWeightTrait, DotWeightTrait, Geometry, GeometryLabel,
|
||||
GetWidth, Node, SegWeightTrait,
|
||||
compound::CompoundManagerTrait, BendWeightTrait, DotWeightTrait, Geometry, GeometryLabel,
|
||||
GetWidth, NodeWeight, SegWeightTrait,
|
||||
},
|
||||
graph::{GenericIndex, GetNodeIndex},
|
||||
layout::{
|
||||
|
|
@ -96,7 +96,7 @@ impl<R: RulesTrait> Layout<R> {
|
|||
|
||||
if let Ok(dot) = maybe_dot {
|
||||
self.drawing
|
||||
.assign_to_grouping(dot, GenericIndex::new(zone.node_index()));
|
||||
.add_to_compound(dot, GenericIndex::new(zone.node_index()));
|
||||
}
|
||||
|
||||
maybe_dot
|
||||
|
|
@ -122,7 +122,7 @@ impl<R: RulesTrait> Layout<R> {
|
|||
|
||||
if let Ok(seg) = maybe_seg {
|
||||
self.drawing
|
||||
.assign_to_grouping(seg, GenericIndex::new(zone.node_index()));
|
||||
.add_to_compound(seg, GenericIndex::new(zone.node_index()));
|
||||
}
|
||||
|
||||
maybe_seg
|
||||
|
|
@ -170,8 +170,8 @@ impl<R: RulesTrait> Layout<R> {
|
|||
|
||||
pub fn zones(&self) -> impl Iterator<Item = ZoneIndex> + '_ {
|
||||
self.drawing.rtree().iter().filter_map(|wrapper| {
|
||||
if let Node::Grouping(zone) = wrapper.data {
|
||||
Some(match self.drawing.geometry().grouping_weight(zone) {
|
||||
if let NodeWeight::Compound(zone) = wrapper.data {
|
||||
Some(match self.drawing.geometry().compound_weight(zone) {
|
||||
ZoneWeight::Solid(..) => {
|
||||
ZoneIndex::Solid(SolidZoneIndex::new(zone.node_index()))
|
||||
}
|
||||
|
|
@ -191,8 +191,8 @@ impl<R: RulesTrait> Layout<R> {
|
|||
[f64::INFINITY, f64::INFINITY, layer as f64],
|
||||
))
|
||||
.filter_map(|wrapper| {
|
||||
if let Node::Grouping(zone) = wrapper.data {
|
||||
Some(match self.drawing.geometry().grouping_weight(zone) {
|
||||
if let NodeWeight::Compound(zone) = wrapper.data {
|
||||
Some(match self.drawing.geometry().compound_weight(zone) {
|
||||
ZoneWeight::Solid(..) => {
|
||||
ZoneIndex::Solid(SolidZoneIndex::new(zone.node_index()))
|
||||
}
|
||||
|
|
@ -209,7 +209,7 @@ impl<R: RulesTrait> Layout<R> {
|
|||
pub fn zone_members(&self, zone: ZoneIndex) -> impl Iterator<Item = PrimitiveIndex> + '_ {
|
||||
self.drawing
|
||||
.geometry()
|
||||
.grouping_members(GenericIndex::new(zone.node_index()))
|
||||
.compound_members(GenericIndex::new(zone.node_index()))
|
||||
}
|
||||
|
||||
pub fn drawing(&self) -> &Drawing<impl Copy, R> {
|
||||
|
|
@ -217,27 +217,27 @@ impl<R: RulesTrait> Layout<R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<R: RulesTrait> GroupingManagerTrait<ZoneWeight, GenericIndex<ZoneWeight>> for Layout<R> {
|
||||
fn add_grouping(&mut self, weight: ZoneWeight) -> GenericIndex<ZoneWeight> {
|
||||
self.drawing.add_grouping(weight)
|
||||
impl<R: RulesTrait> CompoundManagerTrait<ZoneWeight, GenericIndex<ZoneWeight>> for Layout<R> {
|
||||
fn add_compound(&mut self, weight: ZoneWeight) -> GenericIndex<ZoneWeight> {
|
||||
self.drawing.add_compound(weight)
|
||||
}
|
||||
|
||||
fn remove_grouping(&mut self, grouping: GenericIndex<ZoneWeight>) {
|
||||
self.drawing.remove_grouping(grouping);
|
||||
fn remove_compound(&mut self, compound: GenericIndex<ZoneWeight>) {
|
||||
self.drawing.remove_compound(compound);
|
||||
}
|
||||
|
||||
fn assign_to_grouping<W>(
|
||||
fn add_to_compound<W>(
|
||||
&mut self,
|
||||
primitive: GenericIndex<W>,
|
||||
grouping: GenericIndex<ZoneWeight>,
|
||||
compound: GenericIndex<ZoneWeight>,
|
||||
) {
|
||||
self.drawing.assign_to_grouping(primitive, grouping);
|
||||
self.drawing.add_to_compound(primitive, compound);
|
||||
}
|
||||
|
||||
fn groupings<W>(
|
||||
fn compounds<W>(
|
||||
&self,
|
||||
node: GenericIndex<W>,
|
||||
) -> impl Iterator<Item = GenericIndex<ZoneWeight>> {
|
||||
self.drawing.groupings(node)
|
||||
self.drawing.compounds(node)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ impl MakePolygon for SolidZoneIndex {
|
|||
LineString::from(
|
||||
drawing
|
||||
.geometry()
|
||||
.grouping_members(GenericIndex::new(self.node_index()))
|
||||
.compound_members(GenericIndex::new(self.node_index()))
|
||||
.filter_map(|primitive_node| {
|
||||
if let Ok(dot) = DotIndex::try_from(primitive_node) {
|
||||
Some(drawing.geometry().dot_weight(dot).pos())
|
||||
|
|
@ -101,7 +101,7 @@ impl MakePolygon for PourZoneIndex {
|
|||
LineString::from(
|
||||
drawing
|
||||
.geometry()
|
||||
.grouping_members(GenericIndex::new(self.node_index()))
|
||||
.compound_members(GenericIndex::new(self.node_index()))
|
||||
.filter_map(|primitive_node| {
|
||||
if let Ok(dot) = DotIndex::try_from(primitive_node) {
|
||||
Some(drawing.geometry().dot_weight(dot).pos())
|
||||
|
|
|
|||
|
|
@ -46,14 +46,14 @@ impl From<BendIndex> for WraparoundableIndex {
|
|||
}
|
||||
|
||||
#[enum_dispatch(GetWraparound, GetDrawing, GetNodeIndex)]
|
||||
pub enum Wraparoundable<'a, GW: Copy, R: RulesTrait> {
|
||||
FixedDot(FixedDot<'a, GW, R>),
|
||||
FixedBend(FixedBend<'a, GW, R>),
|
||||
LooseBend(LooseBend<'a, GW, R>),
|
||||
pub enum Wraparoundable<'a, CW: Copy, R: RulesTrait> {
|
||||
FixedDot(FixedDot<'a, CW, R>),
|
||||
FixedBend(FixedBend<'a, CW, R>),
|
||||
LooseBend(LooseBend<'a, CW, R>),
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> Wraparoundable<'a, GW, R> {
|
||||
pub fn new(index: WraparoundableIndex, drawing: &'a Drawing<GW, R>) -> Self {
|
||||
impl<'a, CW: Copy, R: RulesTrait> Wraparoundable<'a, CW, R> {
|
||||
pub fn new(index: WraparoundableIndex, drawing: &'a Drawing<CW, R>) -> Self {
|
||||
match index {
|
||||
WraparoundableIndex::FixedDot(dot) => drawing.primitive(dot).into(),
|
||||
WraparoundableIndex::FixedBend(bend) => drawing.primitive(bend).into(),
|
||||
|
|
@ -62,19 +62,19 @@ impl<'a, GW: Copy, R: RulesTrait> Wraparoundable<'a, GW, R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetWraparound for FixedDot<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetWraparound for FixedDot<'a, CW, R> {
|
||||
fn wraparound(&self) -> Option<LooseBendIndex> {
|
||||
self.first_rail()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetWraparound for LooseBend<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetWraparound for LooseBend<'a, CW, R> {
|
||||
fn wraparound(&self) -> Option<LooseBendIndex> {
|
||||
self.outer()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, GW: Copy, R: RulesTrait> GetWraparound for FixedBend<'a, GW, R> {
|
||||
impl<'a, CW: Copy, R: RulesTrait> GetWraparound for FixedBend<'a, CW, R> {
|
||||
fn wraparound(&self) -> Option<LooseBendIndex> {
|
||||
self.first_rail()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue