mirror of https://codeberg.org/topola/topola.git
geometry: expose grouping management via new trait
This commit is contained in:
parent
f2d0de6607
commit
5cef59227a
|
|
@ -28,6 +28,7 @@ use crate::drawing::{
|
||||||
},
|
},
|
||||||
zone::{PourZoneIndex, SolidZoneIndex, ZoneIndex, ZoneWeight},
|
zone::{PourZoneIndex, SolidZoneIndex, ZoneIndex, ZoneWeight},
|
||||||
};
|
};
|
||||||
|
use crate::geometry::grouping::GroupingManagerTrait;
|
||||||
use crate::geometry::Node;
|
use crate::geometry::Node;
|
||||||
use crate::geometry::{
|
use crate::geometry::{
|
||||||
primitive::{PrimitiveShape, PrimitiveShapeTrait},
|
primitive::{PrimitiveShape, PrimitiveShapeTrait},
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,10 @@ use crate::{
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
seg::{FixedSegWeight, LoneLooseSegWeight, SegWeight, SeqLooseSegWeight},
|
seg::{FixedSegWeight, LoneLooseSegWeight, SegWeight, SeqLooseSegWeight},
|
||||||
},
|
},
|
||||||
geometry::primitive::{BendShape, DotShape, PrimitiveShape, SegShape},
|
geometry::{
|
||||||
|
grouping::GroupingManagerTrait,
|
||||||
|
primitive::{BendShape, DotShape, PrimitiveShape, SegShape},
|
||||||
|
},
|
||||||
graph::{GenericIndex, GetNodeIndex},
|
graph::{GenericIndex, GetNodeIndex},
|
||||||
math::Circle,
|
math::Circle,
|
||||||
};
|
};
|
||||||
|
|
@ -155,30 +158,10 @@ impl<
|
||||||
bend
|
bend
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_grouping(&mut self, weight: GW) -> GenericIndex<GW> {
|
|
||||||
GenericIndex::<GW>::new(self.graph.add_node(Node::Grouping(weight)))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn assign_to_grouping<W>(
|
|
||||||
&mut self,
|
|
||||||
primitive: GenericIndex<W>,
|
|
||||||
grouping: GenericIndex<GW>,
|
|
||||||
) {
|
|
||||||
self.graph.update_edge(
|
|
||||||
primitive.node_index(),
|
|
||||||
grouping.node_index(),
|
|
||||||
GeometryLabel::Grouping,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn remove_primitive(&mut self, primitive: PI) {
|
pub fn remove_primitive(&mut self, primitive: PI) {
|
||||||
self.graph.remove_node(primitive.node_index());
|
self.graph.remove_node(primitive.node_index());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_grouping(&mut self, grouping: GenericIndex<GW>) {
|
|
||||||
self.graph.remove_node(grouping.node_index());
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
@ -489,3 +472,32 @@ impl<
|
||||||
&self.graph
|
&self.graph
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<
|
||||||
|
PW: GetWidth + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<PI> + Copy,
|
||||||
|
DW: DotWeightTrait<PW>,
|
||||||
|
SW: SegWeightTrait<PW>,
|
||||||
|
BW: BendWeightTrait<PW>,
|
||||||
|
GW: 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>
|
||||||
|
{
|
||||||
|
fn add_grouping(&mut self, weight: GW) -> GenericIndex<GW> {
|
||||||
|
GenericIndex::<GW>::new(self.graph.add_node(Node::Grouping(weight)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_grouping(&mut self, grouping: GenericIndex<GW>) {
|
||||||
|
self.graph.remove_node(grouping.node_index());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn assign_to_grouping<W>(&mut self, primitive: GenericIndex<W>, grouping: GenericIndex<GW>) {
|
||||||
|
self.graph.update_edge(
|
||||||
|
primitive.node_index(),
|
||||||
|
grouping.node_index(),
|
||||||
|
GeometryLabel::Grouping,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
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>);
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod geometry;
|
mod geometry;
|
||||||
|
pub mod grouping;
|
||||||
pub mod primitive;
|
pub mod primitive;
|
||||||
mod shape;
|
mod shape;
|
||||||
pub mod with_rtree;
|
pub mod with_rtree;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use rstar::{primitives::GeomWithData, Envelope, RTree, RTreeObject, AABB};
|
||||||
use crate::{
|
use crate::{
|
||||||
drawing::graph::{GetLayer, Retag},
|
drawing::graph::{GetLayer, Retag},
|
||||||
geometry::{
|
geometry::{
|
||||||
|
grouping::GroupingManagerTrait,
|
||||||
primitive::{PrimitiveShape, PrimitiveShapeTrait},
|
primitive::{PrimitiveShape, PrimitiveShapeTrait},
|
||||||
BendWeightTrait, DotWeightTrait, Geometry, GeometryLabel, GetWidth, Node, SegWeightTrait,
|
BendWeightTrait, DotWeightTrait, Geometry, GeometryLabel, GetWidth, Node, SegWeightTrait,
|
||||||
},
|
},
|
||||||
|
|
@ -148,12 +149,6 @@ impl<
|
||||||
bend
|
bend
|
||||||
}
|
}
|
||||||
|
|
||||||
pub 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
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn assign_to_grouping<W>(
|
pub fn assign_to_grouping<W>(
|
||||||
&mut self,
|
&mut self,
|
||||||
primitive: GenericIndex<W>,
|
primitive: GenericIndex<W>,
|
||||||
|
|
@ -386,3 +381,32 @@ impl<
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<
|
||||||
|
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<PI> + Copy,
|
||||||
|
DW: DotWeightTrait<PW> + GetLayer,
|
||||||
|
SW: SegWeightTrait<PW> + GetLayer,
|
||||||
|
BW: BendWeightTrait<PW> + GetLayer,
|
||||||
|
GW: 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>
|
||||||
|
{
|
||||||
|
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 remove_grouping(&mut self, grouping: GenericIndex<GW>) {
|
||||||
|
self.rtree.remove(&self.make_grouping_bbox(grouping));
|
||||||
|
self.geometry.remove_grouping(grouping);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn assign_to_grouping<W>(&mut self, primitive: GenericIndex<W>, grouping: GenericIndex<GW>) {
|
||||||
|
self.geometry.assign_to_grouping(primitive, grouping);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue