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