mirror of https://codeberg.org/topola/topola.git
geometry: implement incomplete interface for manipulation of groupings
This commit is contained in:
parent
888a4ecbad
commit
3a812d5621
|
|
@ -139,12 +139,12 @@ impl eframe::App for App {
|
||||||
let mut painter = Painter::new(ui, transform);
|
let mut painter = Painter::new(ui, transform);
|
||||||
|
|
||||||
if let Some(layout) = &self.drawing {
|
if let Some(layout) = &self.drawing {
|
||||||
for node in layout.layer_nodes(1) {
|
for node in layout.layer_primitive_nodes(1) {
|
||||||
let shape = node.primitive(layout).shape();
|
let shape = node.primitive(layout).shape();
|
||||||
painter.paint_shape(&shape, egui::Color32::from_rgb(52, 52, 200));
|
painter.paint_shape(&shape, egui::Color32::from_rgb(52, 52, 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
for node in layout.layer_nodes(0) {
|
for node in layout.layer_primitive_nodes(0) {
|
||||||
let shape = node.primitive(layout).shape();
|
let shape = node.primitive(layout).shape();
|
||||||
painter.paint_shape(&shape, egui::Color32::from_rgb(200, 52, 52));
|
painter.paint_shape(&shape, egui::Color32::from_rgb(200, 52, 52));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ use painter::Painter;
|
||||||
use petgraph::visit::{EdgeRef, IntoEdgeReferences};
|
use petgraph::visit::{EdgeRef, IntoEdgeReferences};
|
||||||
use topola::draw::DrawException;
|
use topola::draw::DrawException;
|
||||||
use topola::drawing::dot::FixedDotWeight;
|
use topola::drawing::dot::FixedDotWeight;
|
||||||
use topola::drawing::graph::{GeometryIndex, MakePrimitive};
|
use topola::drawing::graph::{MakePrimitive, PrimitiveIndex};
|
||||||
use topola::drawing::primitive::MakeShape;
|
use topola::drawing::primitive::MakeShape;
|
||||||
use topola::drawing::rules::{Conditions, RulesTrait};
|
use topola::drawing::rules::{Conditions, RulesTrait};
|
||||||
use topola::drawing::seg::FixedSegWeight;
|
use topola::drawing::seg::FixedSegWeight;
|
||||||
|
|
@ -323,7 +323,7 @@ fn render_times(
|
||||||
mut maybe_mesh: Option<Mesh>,
|
mut maybe_mesh: Option<Mesh>,
|
||||||
path: &[VertexIndex],
|
path: &[VertexIndex],
|
||||||
ghosts: &[Shape],
|
ghosts: &[Shape],
|
||||||
highlighteds: &[GeometryIndex],
|
highlighteds: &[PrimitiveIndex],
|
||||||
times: i64,
|
times: i64,
|
||||||
) {
|
) {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
|
@ -394,7 +394,7 @@ fn render_times(
|
||||||
};
|
};
|
||||||
|
|
||||||
//let result = panic::catch_unwind(|| {
|
//let result = panic::catch_unwind(|| {
|
||||||
for node in layout.layer_nodes(1) {
|
for node in layout.layer_primitive_nodes(1) {
|
||||||
let color = if highlighteds.contains(&node) {
|
let color = if highlighteds.contains(&node) {
|
||||||
ColorU::new(100, 100, 255, 255)
|
ColorU::new(100, 100, 255, 255)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -405,7 +405,7 @@ fn render_times(
|
||||||
painter.paint_shape(&shape, color, view.zoom);
|
painter.paint_shape(&shape, color, view.zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
for node in layout.layer_nodes(0) {
|
for node in layout.layer_primitive_nodes(0) {
|
||||||
let color = if highlighteds.contains(&node) {
|
let color = if highlighteds.contains(&node) {
|
||||||
ColorU::new(255, 100, 100, 255)
|
ColorU::new(255, 100, 100, 255)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use enum_dispatch::enum_dispatch;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
drawing::{
|
drawing::{
|
||||||
graph::{GeometryIndex, GeometryWeight, GetLayer, GetMaybeNet, MakePrimitive, Retag},
|
graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight, Retag},
|
||||||
primitive::{GenericPrimitive, Primitive},
|
primitive::{GenericPrimitive, Primitive},
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
Drawing,
|
Drawing,
|
||||||
|
|
@ -20,22 +20,22 @@ pub enum BendIndex {
|
||||||
Loose(LooseBendIndex),
|
Loose(LooseBendIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<BendIndex> for GeometryIndex {
|
impl From<BendIndex> for PrimitiveIndex {
|
||||||
fn from(bend: BendIndex) -> Self {
|
fn from(bend: BendIndex) -> Self {
|
||||||
match bend {
|
match bend {
|
||||||
BendIndex::Fixed(bend) => GeometryIndex::FixedBend(bend),
|
BendIndex::Fixed(bend) => PrimitiveIndex::FixedBend(bend),
|
||||||
BendIndex::Loose(bend) => GeometryIndex::LooseBend(bend),
|
BendIndex::Loose(bend) => PrimitiveIndex::LooseBend(bend),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<GeometryIndex> for BendIndex {
|
impl TryFrom<PrimitiveIndex> for BendIndex {
|
||||||
type Error = (); // TODO.
|
type Error = (); // TODO.
|
||||||
|
|
||||||
fn try_from(index: GeometryIndex) -> Result<BendIndex, ()> {
|
fn try_from(index: PrimitiveIndex) -> Result<BendIndex, ()> {
|
||||||
match index {
|
match index {
|
||||||
GeometryIndex::FixedBend(index) => Ok(BendIndex::Fixed(index)),
|
PrimitiveIndex::FixedBend(index) => Ok(BendIndex::Fixed(index)),
|
||||||
GeometryIndex::LooseBend(index) => Ok(BendIndex::Loose(index)),
|
PrimitiveIndex::LooseBend(index) => Ok(BendIndex::Loose(index)),
|
||||||
_ => Err(()),
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -48,28 +48,28 @@ pub enum BendWeight {
|
||||||
Loose(LooseBendWeight),
|
Loose(LooseBendWeight),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<BendWeight> for GeometryWeight {
|
impl From<BendWeight> for PrimitiveWeight {
|
||||||
fn from(bend: BendWeight) -> Self {
|
fn from(bend: BendWeight) -> Self {
|
||||||
match bend {
|
match bend {
|
||||||
BendWeight::Fixed(weight) => GeometryWeight::FixedBend(weight),
|
BendWeight::Fixed(weight) => PrimitiveWeight::FixedBend(weight),
|
||||||
BendWeight::Loose(weight) => GeometryWeight::LooseBend(weight),
|
BendWeight::Loose(weight) => PrimitiveWeight::LooseBend(weight),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<GeometryWeight> for BendWeight {
|
impl TryFrom<PrimitiveWeight> for BendWeight {
|
||||||
type Error = (); // TODO.
|
type Error = (); // TODO.
|
||||||
|
|
||||||
fn try_from(weight: GeometryWeight) -> Result<BendWeight, ()> {
|
fn try_from(weight: PrimitiveWeight) -> Result<BendWeight, ()> {
|
||||||
match weight {
|
match weight {
|
||||||
GeometryWeight::FixedBend(weight) => Ok(BendWeight::Fixed(weight)),
|
PrimitiveWeight::FixedBend(weight) => Ok(BendWeight::Fixed(weight)),
|
||||||
GeometryWeight::LooseBend(weight) => Ok(BendWeight::Loose(weight)),
|
PrimitiveWeight::LooseBend(weight) => Ok(BendWeight::Loose(weight)),
|
||||||
_ => Err(()),
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BendWeightTrait<GeometryWeight> for BendWeight {}
|
impl BendWeightTrait<PrimitiveWeight> for BendWeight {}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct FixedBendWeight {
|
pub struct FixedBendWeight {
|
||||||
|
|
@ -80,7 +80,7 @@ pub struct FixedBendWeight {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_fixed_weight!(FixedBendWeight, FixedBend, FixedBendIndex);
|
impl_fixed_weight!(FixedBendWeight, FixedBend, FixedBendIndex);
|
||||||
impl BendWeightTrait<GeometryWeight> for FixedBendWeight {}
|
impl BendWeightTrait<PrimitiveWeight> for FixedBendWeight {}
|
||||||
|
|
||||||
impl GetOffset for FixedBendWeight {
|
impl GetOffset for FixedBendWeight {
|
||||||
fn offset(&self) -> f64 {
|
fn offset(&self) -> f64 {
|
||||||
|
|
@ -127,4 +127,4 @@ impl GetWidth for LooseBendWeight {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_loose_weight!(LooseBendWeight, LooseBend, LooseBendIndex);
|
impl_loose_weight!(LooseBendWeight, LooseBend, LooseBendIndex);
|
||||||
impl BendWeightTrait<GeometryWeight> for LooseBendWeight {}
|
impl BendWeightTrait<PrimitiveWeight> for LooseBendWeight {}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use crate::wraparoundable::{GetWraparound, WraparoundableIndex};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
bend::LooseBendIndex,
|
bend::LooseBendIndex,
|
||||||
graph::GeometryIndex,
|
graph::PrimitiveIndex,
|
||||||
primitive::{GetInnerOuter, GetJoints},
|
primitive::{GetInnerOuter, GetJoints},
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
Drawing,
|
Drawing,
|
||||||
|
|
@ -18,8 +18,8 @@ impl<'a, R: RulesTrait> Collect<'a, R> {
|
||||||
Self { drawing }
|
Self { drawing }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bend_bow(&self, bend: LooseBendIndex) -> Vec<GeometryIndex> {
|
pub fn bend_bow(&self, bend: LooseBendIndex) -> Vec<PrimitiveIndex> {
|
||||||
let mut v: Vec<GeometryIndex> = vec![];
|
let mut v: Vec<PrimitiveIndex> = vec![];
|
||||||
v.push(bend.into());
|
v.push(bend.into());
|
||||||
|
|
||||||
let ends = self.drawing.primitive(bend).joints();
|
let ends = self.drawing.primitive(bend).joints();
|
||||||
|
|
@ -37,7 +37,7 @@ impl<'a, R: RulesTrait> Collect<'a, R> {
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bend_outer_bows(&self, bend: LooseBendIndex) -> Vec<GeometryIndex> {
|
pub fn bend_outer_bows(&self, bend: LooseBendIndex) -> Vec<PrimitiveIndex> {
|
||||||
let mut v = vec![];
|
let mut v = vec![];
|
||||||
let mut rail = bend;
|
let mut rail = bend;
|
||||||
|
|
||||||
|
|
@ -49,7 +49,7 @@ impl<'a, R: RulesTrait> Collect<'a, R> {
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wraparounded_bows(&self, around: WraparoundableIndex) -> Vec<GeometryIndex> {
|
pub fn wraparounded_bows(&self, around: WraparoundableIndex) -> Vec<PrimitiveIndex> {
|
||||||
let mut v = vec![];
|
let mut v = vec![];
|
||||||
let mut rail = around.into();
|
let mut rail = around.into();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use petgraph::stable_graph::NodeIndex;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
drawing::{
|
drawing::{
|
||||||
graph::{GeometryIndex, GeometryWeight, GetLayer, GetMaybeNet, MakePrimitive, Retag},
|
graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight, Retag},
|
||||||
primitive::{GenericPrimitive, Primitive},
|
primitive::{GenericPrimitive, Primitive},
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
Drawing,
|
Drawing,
|
||||||
|
|
@ -22,22 +22,22 @@ pub enum DotIndex {
|
||||||
Loose(LooseDotIndex),
|
Loose(LooseDotIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<DotIndex> for GeometryIndex {
|
impl From<DotIndex> for PrimitiveIndex {
|
||||||
fn from(dot: DotIndex) -> Self {
|
fn from(dot: DotIndex) -> Self {
|
||||||
match dot {
|
match dot {
|
||||||
DotIndex::Fixed(index) => GeometryIndex::FixedDot(index),
|
DotIndex::Fixed(index) => PrimitiveIndex::FixedDot(index),
|
||||||
DotIndex::Loose(index) => GeometryIndex::LooseDot(index),
|
DotIndex::Loose(index) => PrimitiveIndex::LooseDot(index),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<GeometryIndex> for DotIndex {
|
impl TryFrom<PrimitiveIndex> for DotIndex {
|
||||||
type Error = (); // TODO.
|
type Error = (); // TODO.
|
||||||
|
|
||||||
fn try_from(index: GeometryIndex) -> Result<DotIndex, ()> {
|
fn try_from(index: PrimitiveIndex) -> Result<DotIndex, ()> {
|
||||||
match index {
|
match index {
|
||||||
GeometryIndex::FixedDot(index) => Ok(DotIndex::Fixed(index)),
|
PrimitiveIndex::FixedDot(index) => Ok(DotIndex::Fixed(index)),
|
||||||
GeometryIndex::LooseDot(index) => Ok(DotIndex::Loose(index)),
|
PrimitiveIndex::LooseDot(index) => Ok(DotIndex::Loose(index)),
|
||||||
_ => Err(()),
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -50,28 +50,28 @@ pub enum DotWeight {
|
||||||
Loose(LooseDotWeight),
|
Loose(LooseDotWeight),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<DotWeight> for GeometryWeight {
|
impl From<DotWeight> for PrimitiveWeight {
|
||||||
fn from(dot: DotWeight) -> Self {
|
fn from(dot: DotWeight) -> Self {
|
||||||
match dot {
|
match dot {
|
||||||
DotWeight::Fixed(weight) => GeometryWeight::FixedDot(weight),
|
DotWeight::Fixed(weight) => PrimitiveWeight::FixedDot(weight),
|
||||||
DotWeight::Loose(weight) => GeometryWeight::LooseDot(weight),
|
DotWeight::Loose(weight) => PrimitiveWeight::LooseDot(weight),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<GeometryWeight> for DotWeight {
|
impl TryFrom<PrimitiveWeight> for DotWeight {
|
||||||
type Error = (); // TODO.
|
type Error = (); // TODO.
|
||||||
|
|
||||||
fn try_from(weight: GeometryWeight) -> Result<DotWeight, ()> {
|
fn try_from(weight: PrimitiveWeight) -> Result<DotWeight, ()> {
|
||||||
match weight {
|
match weight {
|
||||||
GeometryWeight::FixedDot(weight) => Ok(DotWeight::Fixed(weight)),
|
PrimitiveWeight::FixedDot(weight) => Ok(DotWeight::Fixed(weight)),
|
||||||
GeometryWeight::LooseDot(weight) => Ok(DotWeight::Loose(weight)),
|
PrimitiveWeight::LooseDot(weight) => Ok(DotWeight::Loose(weight)),
|
||||||
_ => Err(()),
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DotWeightTrait<GeometryWeight> for DotWeight {}
|
impl DotWeightTrait<PrimitiveWeight> for DotWeight {}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct FixedDotWeight {
|
pub struct FixedDotWeight {
|
||||||
|
|
@ -81,7 +81,7 @@ pub struct FixedDotWeight {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_fixed_weight!(FixedDotWeight, FixedDot, FixedDotIndex);
|
impl_fixed_weight!(FixedDotWeight, FixedDot, FixedDotIndex);
|
||||||
impl DotWeightTrait<GeometryWeight> for FixedDotWeight {}
|
impl DotWeightTrait<PrimitiveWeight> for FixedDotWeight {}
|
||||||
|
|
||||||
impl GetPos for FixedDotWeight {
|
impl GetPos for FixedDotWeight {
|
||||||
fn pos(&self) -> Point {
|
fn pos(&self) -> Point {
|
||||||
|
|
@ -109,7 +109,7 @@ pub struct LooseDotWeight {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_loose_weight!(LooseDotWeight, LooseDot, LooseDotIndex);
|
impl_loose_weight!(LooseDotWeight, LooseDot, LooseDotIndex);
|
||||||
impl DotWeightTrait<GeometryWeight> for LooseDotWeight {}
|
impl DotWeightTrait<PrimitiveWeight> for LooseDotWeight {}
|
||||||
|
|
||||||
impl GetPos for LooseDotWeight {
|
impl GetPos for LooseDotWeight {
|
||||||
fn pos(&self) -> Point {
|
fn pos(&self) -> Point {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ use crate::drawing::rules::GetConditions;
|
||||||
use crate::drawing::{
|
use crate::drawing::{
|
||||||
bend::{FixedBendIndex, LooseBendIndex, LooseBendWeight},
|
bend::{FixedBendIndex, LooseBendIndex, LooseBendWeight},
|
||||||
dot::{DotIndex, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
|
dot::{DotIndex, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
|
||||||
graph::{GeometryIndex, GeometryWeight, MakePrimitive},
|
graph::{MakePrimitive, PrimitiveIndex, PrimitiveWeight},
|
||||||
grouping::{GroupingIndex, GroupingWeight},
|
grouping::{GroupingIndex, GroupingWeight},
|
||||||
primitive::{GenericPrimitive, GetCore, GetInnerOuter, GetJoints, GetOtherJoint, MakeShape},
|
primitive::{GenericPrimitive, GetCore, GetInnerOuter, GetJoints, GetOtherJoint, MakeShape},
|
||||||
seg::{
|
seg::{
|
||||||
|
|
@ -27,6 +27,7 @@ use crate::drawing::{
|
||||||
SeqLooseSegIndex, SeqLooseSegWeight,
|
SeqLooseSegIndex, SeqLooseSegWeight,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use crate::geometry::Compound;
|
||||||
use crate::geometry::{
|
use crate::geometry::{
|
||||||
shape::{Shape, ShapeTrait},
|
shape::{Shape, ShapeTrait},
|
||||||
with_rtree::GeometryWithRtree,
|
with_rtree::GeometryWithRtree,
|
||||||
|
|
@ -56,29 +57,28 @@ pub enum LayoutException {
|
||||||
// TODO add real error messages + these should eventually use Display
|
// TODO add real error messages + these should eventually use Display
|
||||||
#[derive(Error, Debug, Clone, Copy)]
|
#[derive(Error, Debug, Clone, Copy)]
|
||||||
#[error("{0:?} infringes on {1:?}")]
|
#[error("{0:?} infringes on {1:?}")]
|
||||||
pub struct Infringement(pub Shape, pub GeometryIndex);
|
pub struct Infringement(pub Shape, pub PrimitiveIndex);
|
||||||
|
|
||||||
#[derive(Error, Debug, Clone, Copy)]
|
#[derive(Error, Debug, Clone, Copy)]
|
||||||
#[error("{0:?} collides with {1:?}")]
|
#[error("{0:?} collides with {1:?}")]
|
||||||
pub struct Collision(pub Shape, pub GeometryIndex);
|
pub struct Collision(pub Shape, pub PrimitiveIndex);
|
||||||
|
|
||||||
#[derive(Error, Debug, Clone, Copy)]
|
#[derive(Error, Debug, Clone, Copy)]
|
||||||
#[error("{1:?} is already connected to net {0}")]
|
#[error("{1:?} is already connected to net {0}")]
|
||||||
pub struct AlreadyConnected(pub usize, pub GeometryIndex);
|
pub struct AlreadyConnected(pub usize, pub PrimitiveIndex);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Drawing<R: RulesTrait> {
|
pub struct Drawing<R: RulesTrait> {
|
||||||
geometry_with_rtree: GeometryWithRtree<
|
geometry_with_rtree: GeometryWithRtree<
|
||||||
GeometryWeight,
|
PrimitiveWeight,
|
||||||
DotWeight,
|
DotWeight,
|
||||||
SegWeight,
|
SegWeight,
|
||||||
BendWeight,
|
BendWeight,
|
||||||
GroupingWeight,
|
GroupingWeight,
|
||||||
GeometryIndex,
|
PrimitiveIndex,
|
||||||
DotIndex,
|
DotIndex,
|
||||||
SegIndex,
|
SegIndex,
|
||||||
BendIndex,
|
BendIndex,
|
||||||
GroupingIndex,
|
|
||||||
>,
|
>,
|
||||||
rules: R,
|
rules: R,
|
||||||
}
|
}
|
||||||
|
|
@ -179,13 +179,13 @@ impl<R: RulesTrait> Drawing<R> {
|
||||||
|
|
||||||
#[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))]
|
#[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))]
|
||||||
#[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))]
|
#[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))]
|
||||||
fn add_dot_infringably<W: DotWeightTrait<GeometryWeight> + GetLayer>(
|
fn add_dot_infringably<W: DotWeightTrait<PrimitiveWeight> + GetLayer>(
|
||||||
&mut self,
|
&mut self,
|
||||||
weight: W,
|
weight: W,
|
||||||
infringables: Option<&[GeometryIndex]>,
|
infringables: Option<&[PrimitiveIndex]>,
|
||||||
) -> Result<GenericIndex<W>, Infringement>
|
) -> Result<GenericIndex<W>, Infringement>
|
||||||
where
|
where
|
||||||
GenericIndex<W>: Into<GeometryIndex> + Copy,
|
GenericIndex<W>: Into<PrimitiveIndex> + Copy,
|
||||||
{
|
{
|
||||||
let dot = self.geometry_with_rtree.add_dot(weight);
|
let dot = self.geometry_with_rtree.add_dot(weight);
|
||||||
self.fail_and_remove_if_infringes_except(dot.into(), infringables)?;
|
self.fail_and_remove_if_infringes_except(dot.into(), infringables)?;
|
||||||
|
|
@ -405,7 +405,7 @@ impl<R: RulesTrait> Drawing<R> {
|
||||||
seg_weight: SeqLooseSegWeight,
|
seg_weight: SeqLooseSegWeight,
|
||||||
bend_weight: LooseBendWeight,
|
bend_weight: LooseBendWeight,
|
||||||
cw: bool,
|
cw: bool,
|
||||||
infringables: Option<&[GeometryIndex]>,
|
infringables: Option<&[PrimitiveIndex]>,
|
||||||
) -> Result<Segbend, LayoutException> {
|
) -> Result<Segbend, LayoutException> {
|
||||||
let seg_to = self.add_dot_infringably(dot_weight, infringables)?;
|
let seg_to = self.add_dot_infringably(dot_weight, infringables)?;
|
||||||
let seg = self
|
let seg = self
|
||||||
|
|
@ -473,15 +473,15 @@ impl<R: RulesTrait> Drawing<R> {
|
||||||
#[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count() + 2))]
|
#[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count() + 2))]
|
||||||
#[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))]
|
#[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))]
|
||||||
#[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
|
#[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
|
||||||
fn add_seg_infringably<W: SegWeightTrait<GeometryWeight> + GetLayer>(
|
fn add_seg_infringably<W: SegWeightTrait<PrimitiveWeight> + GetLayer>(
|
||||||
&mut self,
|
&mut self,
|
||||||
from: DotIndex,
|
from: DotIndex,
|
||||||
to: DotIndex,
|
to: DotIndex,
|
||||||
weight: W,
|
weight: W,
|
||||||
infringables: Option<&[GeometryIndex]>,
|
infringables: Option<&[PrimitiveIndex]>,
|
||||||
) -> Result<GenericIndex<W>, Infringement>
|
) -> Result<GenericIndex<W>, Infringement>
|
||||||
where
|
where
|
||||||
GenericIndex<W>: Into<GeometryIndex> + Copy,
|
GenericIndex<W>: Into<PrimitiveIndex> + Copy,
|
||||||
{
|
{
|
||||||
let seg = self.geometry_with_rtree.add_seg(from, to, weight);
|
let seg = self.geometry_with_rtree.add_seg(from, to, weight);
|
||||||
self.fail_and_remove_if_infringes_except(seg.into(), infringables)?;
|
self.fail_and_remove_if_infringes_except(seg.into(), infringables)?;
|
||||||
|
|
@ -500,7 +500,7 @@ impl<R: RulesTrait> Drawing<R> {
|
||||||
to: LooseDotIndex,
|
to: LooseDotIndex,
|
||||||
around: WraparoundableIndex,
|
around: WraparoundableIndex,
|
||||||
weight: LooseBendWeight,
|
weight: LooseBendWeight,
|
||||||
infringables: Option<&[GeometryIndex]>,
|
infringables: Option<&[PrimitiveIndex]>,
|
||||||
) -> Result<LooseBendIndex, LayoutException> {
|
) -> Result<LooseBendIndex, LayoutException> {
|
||||||
// It makes no sense to wrap something around or under one of its connectables.
|
// It makes no sense to wrap something around or under one of its connectables.
|
||||||
//
|
//
|
||||||
|
|
@ -537,16 +537,16 @@ impl<R: RulesTrait> Drawing<R> {
|
||||||
#[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))]
|
#[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))]
|
||||||
#[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count() + 3))]
|
#[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count() + 3))]
|
||||||
#[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
|
#[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
|
||||||
fn add_core_bend_infringably<W: BendWeightTrait<GeometryWeight> + GetLayer>(
|
fn add_core_bend_infringably<W: BendWeightTrait<PrimitiveWeight> + GetLayer>(
|
||||||
&mut self,
|
&mut self,
|
||||||
from: DotIndex,
|
from: DotIndex,
|
||||||
to: DotIndex,
|
to: DotIndex,
|
||||||
core: FixedDotIndex,
|
core: FixedDotIndex,
|
||||||
weight: W,
|
weight: W,
|
||||||
infringables: Option<&[GeometryIndex]>,
|
infringables: Option<&[PrimitiveIndex]>,
|
||||||
) -> Result<GenericIndex<W>, Infringement>
|
) -> Result<GenericIndex<W>, Infringement>
|
||||||
where
|
where
|
||||||
GenericIndex<W>: Into<GeometryIndex> + Copy,
|
GenericIndex<W>: Into<PrimitiveIndex> + Copy,
|
||||||
{
|
{
|
||||||
let bend = self
|
let bend = self
|
||||||
.geometry_with_rtree
|
.geometry_with_rtree
|
||||||
|
|
@ -566,7 +566,7 @@ impl<R: RulesTrait> Drawing<R> {
|
||||||
to: LooseDotIndex,
|
to: LooseDotIndex,
|
||||||
inner: BendIndex,
|
inner: BendIndex,
|
||||||
weight: LooseBendWeight,
|
weight: LooseBendWeight,
|
||||||
infringables: Option<&[GeometryIndex]>,
|
infringables: Option<&[PrimitiveIndex]>,
|
||||||
) -> Result<GenericIndex<LooseBendWeight>, Infringement> {
|
) -> Result<GenericIndex<LooseBendWeight>, Infringement> {
|
||||||
let core = *self
|
let core = *self
|
||||||
.geometry_with_rtree
|
.geometry_with_rtree
|
||||||
|
|
@ -616,8 +616,8 @@ impl<R: RulesTrait> Drawing<R> {
|
||||||
#[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() - 1))]
|
#[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() - 1))]
|
||||||
fn fail_and_remove_if_infringes_except(
|
fn fail_and_remove_if_infringes_except(
|
||||||
&mut self,
|
&mut self,
|
||||||
node: GeometryIndex,
|
node: PrimitiveIndex,
|
||||||
maybe_except: Option<&[GeometryIndex]>,
|
maybe_except: Option<&[PrimitiveIndex]>,
|
||||||
) -> Result<(), Infringement> {
|
) -> Result<(), Infringement> {
|
||||||
if let Some(infringement) = self.detect_infringement_except(node, maybe_except) {
|
if let Some(infringement) = self.detect_infringement_except(node, maybe_except) {
|
||||||
if let Ok(dot) = node.try_into() {
|
if let Ok(dot) = node.try_into() {
|
||||||
|
|
@ -632,21 +632,33 @@ impl<R: RulesTrait> Drawing<R> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodes(&self) -> impl Iterator<Item = GeometryIndex> + '_ {
|
pub fn primitive_nodes(&self) -> impl Iterator<Item = PrimitiveIndex> + '_ {
|
||||||
self.geometry_with_rtree
|
self.geometry_with_rtree
|
||||||
.rtree()
|
.rtree()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|wrapper| wrapper.data)
|
.filter_map(|wrapper| {
|
||||||
|
if let Compound::Primitive(primitive_node) = wrapper.data {
|
||||||
|
Some(primitive_node)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn layer_nodes(&self, layer: u64) -> impl Iterator<Item = GeometryIndex> + '_ {
|
pub fn layer_primitive_nodes(&self, layer: u64) -> impl Iterator<Item = PrimitiveIndex> + '_ {
|
||||||
self.geometry_with_rtree
|
self.geometry_with_rtree
|
||||||
.rtree()
|
.rtree()
|
||||||
.locate_in_envelope_intersecting(&AABB::from_corners(
|
.locate_in_envelope_intersecting(&AABB::from_corners(
|
||||||
[-f64::INFINITY, -f64::INFINITY, layer as f64],
|
[-f64::INFINITY, -f64::INFINITY, layer as f64],
|
||||||
[f64::INFINITY, f64::INFINITY, layer as f64],
|
[f64::INFINITY, f64::INFINITY, layer as f64],
|
||||||
))
|
))
|
||||||
.map(|wrapper| wrapper.data)
|
.filter_map(|wrapper| {
|
||||||
|
if let Compound::Primitive(primitive_node) = wrapper.data {
|
||||||
|
Some(primitive_node)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_count(&self) -> usize {
|
pub fn node_count(&self) -> usize {
|
||||||
|
|
@ -670,7 +682,7 @@ impl<R: RulesTrait> Drawing<R> {
|
||||||
&mut self,
|
&mut self,
|
||||||
dot: DotIndex,
|
dot: DotIndex,
|
||||||
to: Point,
|
to: Point,
|
||||||
infringables: Option<&[GeometryIndex]>,
|
infringables: Option<&[PrimitiveIndex]>,
|
||||||
) -> Result<(), Infringement> {
|
) -> Result<(), Infringement> {
|
||||||
let old_pos = self.geometry_with_rtree.geometry().dot_weight(dot).pos();
|
let old_pos = self.geometry_with_rtree.geometry().dot_weight(dot).pos();
|
||||||
self.geometry_with_rtree.move_dot(dot, to);
|
self.geometry_with_rtree.move_dot(dot, to);
|
||||||
|
|
@ -698,7 +710,7 @@ impl<R: RulesTrait> Drawing<R> {
|
||||||
&mut self,
|
&mut self,
|
||||||
bend: BendIndex,
|
bend: BendIndex,
|
||||||
offset: f64,
|
offset: f64,
|
||||||
infringables: Option<&[GeometryIndex]>,
|
infringables: Option<&[PrimitiveIndex]>,
|
||||||
) -> Result<(), Infringement> {
|
) -> Result<(), Infringement> {
|
||||||
let old_offset = self
|
let old_offset = self
|
||||||
.geometry_with_rtree
|
.geometry_with_rtree
|
||||||
|
|
@ -720,8 +732,8 @@ impl<R: RulesTrait> Drawing<R> {
|
||||||
#[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()))]
|
||||||
fn detect_infringement_except(
|
fn detect_infringement_except(
|
||||||
&self,
|
&self,
|
||||||
node: GeometryIndex,
|
node: PrimitiveIndex,
|
||||||
maybe_except: Option<&[GeometryIndex]>,
|
maybe_except: Option<&[PrimitiveIndex]>,
|
||||||
) -> Option<Infringement> {
|
) -> Option<Infringement> {
|
||||||
let limiting_shape = node.primitive(self).shape().inflate(
|
let limiting_shape = node.primitive(self).shape().inflate(
|
||||||
node.primitive(self)
|
node.primitive(self)
|
||||||
|
|
@ -735,10 +747,19 @@ impl<R: RulesTrait> Drawing<R> {
|
||||||
self.geometry_with_rtree
|
self.geometry_with_rtree
|
||||||
.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(|wrapper| maybe_except.is_some_and(|except| !except.contains(&wrapper.data)))
|
.filter_map(|wrapper| {
|
||||||
.filter(|wrapper| !self.are_connectable(node, wrapper.data))
|
if let Compound::Primitive(primitive_node) = wrapper.data {
|
||||||
.filter(|wrapper| {
|
Some(primitive_node)
|
||||||
let infringee_conditions = wrapper.data.primitive(self).conditions();
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(|primitive_node| {
|
||||||
|
maybe_except.is_some_and(|except| !except.contains(&primitive_node))
|
||||||
|
})
|
||||||
|
.filter(|primitive_node| !self.are_connectable(node, *primitive_node))
|
||||||
|
.filter(|primitive_node| {
|
||||||
|
let infringee_conditions = primitive_node.primitive(self).conditions();
|
||||||
|
|
||||||
let epsilon = 1.0;
|
let epsilon = 1.0;
|
||||||
inflated_shape = node.primitive(self).shape().inflate(
|
inflated_shape = node.primitive(self).shape().inflate(
|
||||||
|
|
@ -746,31 +767,38 @@ impl<R: RulesTrait> Drawing<R> {
|
||||||
.clamp(0.0, f64::INFINITY),
|
.clamp(0.0, f64::INFINITY),
|
||||||
);
|
);
|
||||||
|
|
||||||
inflated_shape.intersects(&wrapper.data.primitive(self).shape())
|
inflated_shape.intersects(&primitive_node.primitive(self).shape())
|
||||||
})
|
})
|
||||||
.map(|wrapper| wrapper.data)
|
.map(|primitive_node| primitive_node)
|
||||||
.next()
|
.next()
|
||||||
.and_then(|infringee| Some(Infringement(inflated_shape, infringee)))
|
.and_then(|infringee| Some(Infringement(inflated_shape, infringee)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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()))]
|
||||||
fn detect_collision(&self, node: GeometryIndex) -> Option<Collision> {
|
fn detect_collision(&self, node: PrimitiveIndex) -> Option<Collision> {
|
||||||
let shape = node.primitive(self).shape();
|
let shape = node.primitive(self).shape();
|
||||||
|
|
||||||
self.geometry_with_rtree
|
self.geometry_with_rtree
|
||||||
.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(|wrapper| !self.are_connectable(node, wrapper.data))
|
.filter_map(|wrapper| {
|
||||||
.filter(|wrapper| shape.intersects(&wrapper.data.primitive(self).shape()))
|
if let Compound::Primitive(primitive_node) = wrapper.data {
|
||||||
.map(|wrapper| wrapper.data)
|
Some(primitive_node)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(|primitive_node| !self.are_connectable(node, *primitive_node))
|
||||||
|
.filter(|primitive_node| shape.intersects(&primitive_node.primitive(self).shape()))
|
||||||
|
.map(|primitive_node| primitive_node)
|
||||||
.next()
|
.next()
|
||||||
.and_then(|collidee| Some(Collision(shape, collidee)))
|
.and_then(|collidee| Some(Collision(shape, collidee)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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()))]
|
||||||
fn are_connectable(&self, node1: GeometryIndex, node2: GeometryIndex) -> bool {
|
fn are_connectable(&self, node1: PrimitiveIndex, node2: PrimitiveIndex) -> bool {
|
||||||
if let (Some(node1_net_id), Some(node2_net_id)) = (
|
if let (Some(node1_net_id), Some(node2_net_id)) = (
|
||||||
node1.primitive(self).maybe_net(),
|
node1.primitive(self).maybe_net(),
|
||||||
node2.primitive(self).maybe_net(),
|
node2.primitive(self).maybe_net(),
|
||||||
|
|
@ -788,16 +816,15 @@ impl<R: RulesTrait> Drawing<R> {
|
||||||
pub fn geometry(
|
pub fn geometry(
|
||||||
&self,
|
&self,
|
||||||
) -> &Geometry<
|
) -> &Geometry<
|
||||||
GeometryWeight,
|
PrimitiveWeight,
|
||||||
DotWeight,
|
DotWeight,
|
||||||
SegWeight,
|
SegWeight,
|
||||||
BendWeight,
|
BendWeight,
|
||||||
GroupingWeight,
|
GroupingWeight,
|
||||||
GeometryIndex,
|
PrimitiveIndex,
|
||||||
DotIndex,
|
DotIndex,
|
||||||
SegIndex,
|
SegIndex,
|
||||||
BendIndex,
|
BendIndex,
|
||||||
GroupingIndex,
|
|
||||||
> {
|
> {
|
||||||
self.geometry_with_rtree.geometry()
|
self.geometry_with_rtree.geometry()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ use super::{
|
||||||
};
|
};
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
pub trait Retag<GeometryIndex> {
|
pub trait Retag<PrimitiveIndex> {
|
||||||
fn retag(&self, index: NodeIndex<usize>) -> GeometryIndex;
|
fn retag(&self, index: NodeIndex<usize>) -> PrimitiveIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
|
|
@ -37,9 +37,9 @@ pub trait MakePrimitive {
|
||||||
|
|
||||||
macro_rules! impl_weight {
|
macro_rules! impl_weight {
|
||||||
($weight_struct:ident, $weight_variant:ident, $index_struct:ident) => {
|
($weight_struct:ident, $weight_variant:ident, $index_struct:ident) => {
|
||||||
impl Retag<GeometryIndex> for $weight_struct {
|
impl Retag<PrimitiveIndex> for $weight_struct {
|
||||||
fn retag(&self, index: NodeIndex<usize>) -> GeometryIndex {
|
fn retag(&self, index: NodeIndex<usize>) -> PrimitiveIndex {
|
||||||
GeometryIndex::$weight_variant($index_struct::new(index))
|
PrimitiveIndex::$weight_variant($index_struct::new(index))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,7 +79,7 @@ macro_rules! impl_loose_weight {
|
||||||
|
|
||||||
#[enum_dispatch(GetNodeIndex, MakePrimitive)]
|
#[enum_dispatch(GetNodeIndex, MakePrimitive)]
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum GeometryIndex {
|
pub enum PrimitiveIndex {
|
||||||
FixedDot(FixedDotIndex),
|
FixedDot(FixedDotIndex),
|
||||||
LooseDot(LooseDotIndex),
|
LooseDot(LooseDotIndex),
|
||||||
FixedSeg(FixedSegIndex),
|
FixedSeg(FixedSegIndex),
|
||||||
|
|
@ -89,9 +89,9 @@ pub enum GeometryIndex {
|
||||||
LooseBend(LooseBendIndex),
|
LooseBend(LooseBendIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[enum_dispatch(GetWidth, GetLayer, Retag<GeometryIndex>)]
|
#[enum_dispatch(GetWidth, GetLayer, Retag<PrimitiveIndex>)]
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum GeometryWeight {
|
pub enum PrimitiveWeight {
|
||||||
FixedDot(FixedDotWeight),
|
FixedDot(FixedDotWeight),
|
||||||
LooseDot(LooseDotWeight),
|
LooseDot(LooseDotWeight),
|
||||||
FixedSeg(FixedSegWeight),
|
FixedSeg(FixedSegWeight),
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use petgraph::stable_graph::NodeIndex;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
drawing::{
|
drawing::{
|
||||||
graph::{GeometryIndex, GeometryWeight, GetLayer, GetMaybeNet, MakePrimitive, Retag},
|
graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight, Retag},
|
||||||
primitive::{GenericPrimitive, Primitive},
|
primitive::{GenericPrimitive, Primitive},
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
Drawing,
|
Drawing,
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
graph::GeometryIndex,
|
graph::PrimitiveIndex,
|
||||||
primitive::GetJoints,
|
primitive::GetJoints,
|
||||||
rules::{Conditions, RulesTrait},
|
rules::{Conditions, RulesTrait},
|
||||||
segbend::Segbend,
|
segbend::Segbend,
|
||||||
|
|
@ -241,7 +241,7 @@ impl<'a, R: RulesTrait> Guide<'a, R> {
|
||||||
.other_joint(head.segbend.dot.into())
|
.other_joint(head.segbend.dot.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn conditions(&self, node: GeometryIndex) -> Conditions {
|
fn conditions(&self, node: PrimitiveIndex) -> Conditions {
|
||||||
node.primitive(self.drawing).conditions()
|
node.primitive(self.drawing).conditions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use crate::{
|
||||||
drawing::{
|
drawing::{
|
||||||
bend::LooseBendIndex,
|
bend::LooseBendIndex,
|
||||||
dot::{DotIndex, LooseDotIndex},
|
dot::{DotIndex, LooseDotIndex},
|
||||||
graph::{GeometryIndex, MakePrimitive},
|
graph::{MakePrimitive, PrimitiveIndex},
|
||||||
primitive::{GetJoints, LoneLooseSeg, LooseBend, LooseDot, Primitive, SeqLooseSeg},
|
primitive::{GetJoints, LoneLooseSeg, LooseBend, LooseDot, Primitive, SeqLooseSeg},
|
||||||
seg::{LoneLooseSegIndex, SeqLooseSegIndex},
|
seg::{LoneLooseSegIndex, SeqLooseSegIndex},
|
||||||
},
|
},
|
||||||
|
|
@ -29,13 +29,13 @@ pub enum LooseIndex {
|
||||||
Bend(LooseBendIndex),
|
Bend(LooseBendIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<LooseIndex> for GeometryIndex {
|
impl From<LooseIndex> for PrimitiveIndex {
|
||||||
fn from(loose: LooseIndex) -> Self {
|
fn from(loose: LooseIndex) -> Self {
|
||||||
match loose {
|
match loose {
|
||||||
LooseIndex::Dot(dot) => GeometryIndex::LooseDot(dot),
|
LooseIndex::Dot(dot) => PrimitiveIndex::LooseDot(dot),
|
||||||
LooseIndex::LoneSeg(seg) => GeometryIndex::LoneLooseSeg(seg),
|
LooseIndex::LoneSeg(seg) => PrimitiveIndex::LoneLooseSeg(seg),
|
||||||
LooseIndex::SeqSeg(seg) => GeometryIndex::SeqLooseSeg(seg),
|
LooseIndex::SeqSeg(seg) => PrimitiveIndex::SeqLooseSeg(seg),
|
||||||
LooseIndex::Bend(bend) => GeometryIndex::LooseBend(bend),
|
LooseIndex::Bend(bend) => PrimitiveIndex::LooseBend(bend),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use crate::{
|
||||||
drawing::{
|
drawing::{
|
||||||
bend::{BendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight},
|
bend::{BendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight},
|
||||||
dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
|
dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
|
||||||
graph::{GeometryIndex, GeometryWeight, GetLayer, GetMaybeNet, Retag},
|
graph::{GetLayer, GetMaybeNet, PrimitiveIndex, PrimitiveWeight, Retag},
|
||||||
loose::LooseIndex,
|
loose::LooseIndex,
|
||||||
rules::{Conditions, GetConditions, RulesTrait},
|
rules::{Conditions, GetConditions, RulesTrait},
|
||||||
seg::{
|
seg::{
|
||||||
|
|
@ -20,7 +20,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
Drawing,
|
Drawing,
|
||||||
},
|
},
|
||||||
geometry::CompoundWeight,
|
geometry::Compound,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
|
|
@ -40,10 +40,10 @@ pub trait MakeShape {
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
pub trait GetLimbs {
|
pub trait GetLimbs {
|
||||||
fn limbs(&self) -> Vec<GeometryIndex> {
|
fn limbs(&self) -> Vec<PrimitiveIndex> {
|
||||||
let mut v = vec![];
|
let mut v = vec![];
|
||||||
v.extend(self.segs().into_iter().map(Into::<GeometryIndex>::into));
|
v.extend(self.segs().into_iter().map(Into::<PrimitiveIndex>::into));
|
||||||
v.extend(self.bends().into_iter().map(Into::<GeometryIndex>::into));
|
v.extend(self.bends().into_iter().map(Into::<PrimitiveIndex>::into));
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,7 +119,7 @@ macro_rules! impl_primitive {
|
||||||
($primitive_struct:ident, $weight_struct:ident) => {
|
($primitive_struct:ident, $weight_struct:ident) => {
|
||||||
impl<'a, R: RulesTrait> GetWeight<$weight_struct> for $primitive_struct<'a, R> {
|
impl<'a, R: RulesTrait> GetWeight<$weight_struct> for $primitive_struct<'a, R> {
|
||||||
fn weight(&self) -> $weight_struct {
|
fn weight(&self) -> $weight_struct {
|
||||||
if let GeometryWeight::$primitive_struct(weight) = self.tagged_weight() {
|
if let PrimitiveWeight::$primitive_struct(weight) = self.tagged_weight() {
|
||||||
weight
|
weight
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
|
|
@ -183,8 +183,8 @@ impl<'a, W, R: RulesTrait> GenericPrimitive<'a, W, R> {
|
||||||
Self { index, drawing }
|
Self { index, drawing }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tagged_weight(&self) -> GeometryWeight {
|
fn tagged_weight(&self) -> PrimitiveWeight {
|
||||||
if let CompoundWeight::Primitive(weight) = *self
|
if let Compound::Primitive(weight) = *self
|
||||||
.drawing
|
.drawing
|
||||||
.geometry()
|
.geometry()
|
||||||
.graph()
|
.graph()
|
||||||
|
|
@ -202,8 +202,8 @@ impl<'a, W, R: RulesTrait> GenericPrimitive<'a, W, R> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, W, R: RulesTrait> GetInterior<GeometryIndex> for GenericPrimitive<'a, W, R> {
|
impl<'a, W, R: RulesTrait> GetInterior<PrimitiveIndex> for GenericPrimitive<'a, W, R> {
|
||||||
fn interior(&self) -> Vec<GeometryIndex> {
|
fn interior(&self) -> Vec<PrimitiveIndex> {
|
||||||
vec![self.tagged_weight().retag(self.index.node_index())]
|
vec![self.tagged_weight().retag(self.index.node_index())]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -260,12 +260,12 @@ impl<'a, R: RulesTrait> FixedDot<'a, R> {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
if matches!(
|
if matches!(
|
||||||
weight,
|
weight,
|
||||||
CompoundWeight::Primitive(GeometryWeight::LoneLooseSeg(..))
|
Compound::Primitive(PrimitiveWeight::LoneLooseSeg(..))
|
||||||
) {
|
) {
|
||||||
Some(LoneLooseSegIndex::new(ni.node_index()).into())
|
Some(LoneLooseSegIndex::new(ni.node_index()).into())
|
||||||
} else if matches!(
|
} else if matches!(
|
||||||
weight,
|
weight,
|
||||||
CompoundWeight::Primitive(GeometryWeight::SeqLooseSeg(..))
|
Compound::Primitive(PrimitiveWeight::SeqLooseSeg(..))
|
||||||
) {
|
) {
|
||||||
Some(SeqLooseSegIndex::new(ni.node_index()).into())
|
Some(SeqLooseSegIndex::new(ni.node_index()).into())
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use enum_dispatch::enum_dispatch;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
drawing::{
|
drawing::{
|
||||||
graph::{GeometryIndex, GeometryWeight, GetLayer, GetMaybeNet, MakePrimitive, Retag},
|
graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight, Retag},
|
||||||
primitive::{GenericPrimitive, Primitive},
|
primitive::{GenericPrimitive, Primitive},
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
Drawing,
|
Drawing,
|
||||||
|
|
@ -21,24 +21,24 @@ pub enum SegIndex {
|
||||||
SeqLoose(SeqLooseSegIndex),
|
SeqLoose(SeqLooseSegIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SegIndex> for GeometryIndex {
|
impl From<SegIndex> for PrimitiveIndex {
|
||||||
fn from(seg: SegIndex) -> Self {
|
fn from(seg: SegIndex) -> Self {
|
||||||
match seg {
|
match seg {
|
||||||
SegIndex::Fixed(seg) => GeometryIndex::FixedSeg(seg),
|
SegIndex::Fixed(seg) => PrimitiveIndex::FixedSeg(seg),
|
||||||
SegIndex::LoneLoose(seg) => GeometryIndex::LoneLooseSeg(seg),
|
SegIndex::LoneLoose(seg) => PrimitiveIndex::LoneLooseSeg(seg),
|
||||||
SegIndex::SeqLoose(seg) => GeometryIndex::SeqLooseSeg(seg),
|
SegIndex::SeqLoose(seg) => PrimitiveIndex::SeqLooseSeg(seg),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<GeometryIndex> for SegIndex {
|
impl TryFrom<PrimitiveIndex> for SegIndex {
|
||||||
type Error = (); // TODO.
|
type Error = (); // TODO.
|
||||||
|
|
||||||
fn try_from(index: GeometryIndex) -> Result<SegIndex, ()> {
|
fn try_from(index: PrimitiveIndex) -> Result<SegIndex, ()> {
|
||||||
match index {
|
match index {
|
||||||
GeometryIndex::FixedSeg(index) => Ok(SegIndex::Fixed(index)),
|
PrimitiveIndex::FixedSeg(index) => Ok(SegIndex::Fixed(index)),
|
||||||
GeometryIndex::LoneLooseSeg(index) => Ok(SegIndex::LoneLoose(index)),
|
PrimitiveIndex::LoneLooseSeg(index) => Ok(SegIndex::LoneLoose(index)),
|
||||||
GeometryIndex::SeqLooseSeg(index) => Ok(SegIndex::SeqLoose(index)),
|
PrimitiveIndex::SeqLooseSeg(index) => Ok(SegIndex::SeqLoose(index)),
|
||||||
_ => Err(()),
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -52,30 +52,30 @@ pub enum SegWeight {
|
||||||
SeqLoose(SeqLooseSegWeight),
|
SeqLoose(SeqLooseSegWeight),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SegWeight> for GeometryWeight {
|
impl From<SegWeight> for PrimitiveWeight {
|
||||||
fn from(seg: SegWeight) -> Self {
|
fn from(seg: SegWeight) -> Self {
|
||||||
match seg {
|
match seg {
|
||||||
SegWeight::Fixed(weight) => GeometryWeight::FixedSeg(weight),
|
SegWeight::Fixed(weight) => PrimitiveWeight::FixedSeg(weight),
|
||||||
SegWeight::LoneLoose(weight) => GeometryWeight::LoneLooseSeg(weight),
|
SegWeight::LoneLoose(weight) => PrimitiveWeight::LoneLooseSeg(weight),
|
||||||
SegWeight::SeqLoose(weight) => GeometryWeight::SeqLooseSeg(weight),
|
SegWeight::SeqLoose(weight) => PrimitiveWeight::SeqLooseSeg(weight),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<GeometryWeight> for SegWeight {
|
impl TryFrom<PrimitiveWeight> for SegWeight {
|
||||||
type Error = (); // TODO.
|
type Error = (); // TODO.
|
||||||
|
|
||||||
fn try_from(weight: GeometryWeight) -> Result<SegWeight, ()> {
|
fn try_from(weight: PrimitiveWeight) -> Result<SegWeight, ()> {
|
||||||
match weight {
|
match weight {
|
||||||
GeometryWeight::FixedSeg(weight) => Ok(SegWeight::Fixed(weight)),
|
PrimitiveWeight::FixedSeg(weight) => Ok(SegWeight::Fixed(weight)),
|
||||||
GeometryWeight::LoneLooseSeg(weight) => Ok(SegWeight::LoneLoose(weight)),
|
PrimitiveWeight::LoneLooseSeg(weight) => Ok(SegWeight::LoneLoose(weight)),
|
||||||
GeometryWeight::SeqLooseSeg(weight) => Ok(SegWeight::SeqLoose(weight)),
|
PrimitiveWeight::SeqLooseSeg(weight) => Ok(SegWeight::SeqLoose(weight)),
|
||||||
_ => Err(()),
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SegWeightTrait<GeometryWeight> for SegWeight {}
|
impl SegWeightTrait<PrimitiveWeight> for SegWeight {}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct FixedSegWeight {
|
pub struct FixedSegWeight {
|
||||||
|
|
@ -85,7 +85,7 @@ pub struct FixedSegWeight {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_fixed_weight!(FixedSegWeight, FixedSeg, FixedSegIndex);
|
impl_fixed_weight!(FixedSegWeight, FixedSeg, FixedSegIndex);
|
||||||
impl SegWeightTrait<GeometryWeight> for FixedSegWeight {}
|
impl SegWeightTrait<PrimitiveWeight> for FixedSegWeight {}
|
||||||
|
|
||||||
impl GetWidth for FixedSegWeight {
|
impl GetWidth for FixedSegWeight {
|
||||||
fn width(&self) -> f64 {
|
fn width(&self) -> f64 {
|
||||||
|
|
@ -101,7 +101,7 @@ pub struct LoneLooseSegWeight {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_loose_weight!(LoneLooseSegWeight, LoneLooseSeg, LoneLooseSegIndex);
|
impl_loose_weight!(LoneLooseSegWeight, LoneLooseSeg, LoneLooseSegIndex);
|
||||||
impl SegWeightTrait<GeometryWeight> for LoneLooseSegWeight {}
|
impl SegWeightTrait<PrimitiveWeight> for LoneLooseSegWeight {}
|
||||||
|
|
||||||
impl GetWidth for LoneLooseSegWeight {
|
impl GetWidth for LoneLooseSegWeight {
|
||||||
fn width(&self) -> f64 {
|
fn width(&self) -> f64 {
|
||||||
|
|
@ -117,7 +117,7 @@ pub struct SeqLooseSegWeight {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_loose_weight!(SeqLooseSegWeight, SeqLooseSeg, SeqLooseSegIndex);
|
impl_loose_weight!(SeqLooseSegWeight, SeqLooseSeg, SeqLooseSegIndex);
|
||||||
impl SegWeightTrait<GeometryWeight> for SeqLooseSegWeight {}
|
impl SegWeightTrait<PrimitiveWeight> for SeqLooseSegWeight {}
|
||||||
|
|
||||||
impl GetWidth for SeqLooseSegWeight {
|
impl GetWidth for SeqLooseSegWeight {
|
||||||
fn width(&self) -> f64 {
|
fn width(&self) -> f64 {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::drawing::{
|
use crate::drawing::{
|
||||||
bend::LooseBendIndex,
|
bend::LooseBendIndex,
|
||||||
dot::LooseDotIndex,
|
dot::LooseDotIndex,
|
||||||
graph::GeometryIndex,
|
graph::PrimitiveIndex,
|
||||||
primitive::{GetInterior, GetJoints, GetOtherJoint, LooseBend, LooseDot},
|
primitive::{GetInterior, GetJoints, GetOtherJoint, LooseBend, LooseDot},
|
||||||
seg::SeqLooseSegIndex,
|
seg::SeqLooseSegIndex,
|
||||||
Drawing,
|
Drawing,
|
||||||
|
|
@ -25,8 +25,8 @@ impl Segbend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GetInterior<GeometryIndex> for Segbend {
|
impl GetInterior<PrimitiveIndex> for Segbend {
|
||||||
fn interior(&self) -> Vec<GeometryIndex> {
|
fn interior(&self) -> Vec<PrimitiveIndex> {
|
||||||
vec![self.bend.into(), self.dot.into(), self.seg.into()]
|
vec![self.bend.into(), self.dot.into(), self.seg.into()]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ use crate::{
|
||||||
drawing::{
|
drawing::{
|
||||||
bend::{BendWeight, FixedBendWeight, LooseBendWeight},
|
bend::{BendWeight, FixedBendWeight, LooseBendWeight},
|
||||||
dot::{DotWeight, FixedDotWeight, LooseDotWeight},
|
dot::{DotWeight, FixedDotWeight, LooseDotWeight},
|
||||||
graph::{GeometryWeight, Retag},
|
graph::{PrimitiveWeight, Retag},
|
||||||
primitive::Primitive,
|
primitive::Primitive,
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
seg::{FixedSegWeight, LoneLooseSegWeight, SegWeight, SeqLooseSegWeight},
|
seg::{FixedSegWeight, LoneLooseSegWeight, SegWeight, SeqLooseSegWeight},
|
||||||
|
|
@ -52,10 +52,11 @@ pub enum GeometryLabel {
|
||||||
Joined,
|
Joined,
|
||||||
Outer,
|
Outer,
|
||||||
Core,
|
Core,
|
||||||
|
Grouping,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum CompoundWeight<PW, XW> {
|
pub enum Compound<PW, XW> {
|
||||||
Primitive(PW),
|
Primitive(PW),
|
||||||
Grouping(XW),
|
Grouping(XW),
|
||||||
}
|
}
|
||||||
|
|
@ -75,9 +76,8 @@ pub struct Geometry<
|
||||||
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,
|
||||||
GI: GetNodeIndex + Copy,
|
|
||||||
> {
|
> {
|
||||||
graph: StableDiGraph<CompoundWeight<PW, GW>, GeometryLabel, usize>,
|
graph: StableDiGraph<Compound<PW, GW>, 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>,
|
||||||
|
|
@ -87,7 +87,6 @@ pub struct Geometry<
|
||||||
dot_index_marker: PhantomData<DI>,
|
dot_index_marker: PhantomData<DI>,
|
||||||
seg_index_marker: PhantomData<SI>,
|
seg_index_marker: PhantomData<SI>,
|
||||||
bend_index_marker: PhantomData<BI>,
|
bend_index_marker: PhantomData<BI>,
|
||||||
grouping_index_marker: PhantomData<GI>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
|
|
@ -100,8 +99,7 @@ impl<
|
||||||
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,
|
||||||
GI: GetNodeIndex + Copy,
|
> Geometry<PW, DW, SW, BW, GW, PI, DI, SI, BI>
|
||||||
> Geometry<PW, DW, SW, BW, GW, PI, DI, SI, BI, GI>
|
|
||||||
{
|
{
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
@ -115,15 +113,11 @@ impl<
|
||||||
dot_index_marker: PhantomData,
|
dot_index_marker: PhantomData,
|
||||||
seg_index_marker: PhantomData,
|
seg_index_marker: PhantomData,
|
||||||
bend_index_marker: PhantomData,
|
bend_index_marker: PhantomData,
|
||||||
grouping_index_marker: PhantomData,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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(
|
GenericIndex::<W>::new(self.graph.add_node(Compound::Primitive(weight.into())))
|
||||||
self.graph
|
|
||||||
.add_node(CompoundWeight::Primitive(weight.into())),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_seg<W: SegWeightTrait<PW>>(
|
pub fn add_seg<W: SegWeightTrait<PW>>(
|
||||||
|
|
@ -132,10 +126,7 @@ impl<
|
||||||
to: DI,
|
to: DI,
|
||||||
weight: W,
|
weight: W,
|
||||||
) -> GenericIndex<W> {
|
) -> GenericIndex<W> {
|
||||||
let seg = GenericIndex::<W>::new(
|
let seg = GenericIndex::<W>::new(self.graph.add_node(Compound::Primitive(weight.into())));
|
||||||
self.graph
|
|
||||||
.add_node(CompoundWeight::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);
|
||||||
|
|
@ -152,10 +143,7 @@ impl<
|
||||||
core: DI,
|
core: DI,
|
||||||
weight: W,
|
weight: W,
|
||||||
) -> GenericIndex<W> {
|
) -> GenericIndex<W> {
|
||||||
let bend = GenericIndex::<W>::new(
|
let bend = GenericIndex::<W>::new(self.graph.add_node(Compound::Primitive(weight.into())));
|
||||||
self.graph
|
|
||||||
.add_node(CompoundWeight::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);
|
||||||
|
|
@ -167,22 +155,41 @@ impl<
|
||||||
bend
|
bend
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove(&mut self, node: PI) {
|
pub fn add_grouping(&mut self, weight: GW) -> GenericIndex<GW> {
|
||||||
self.graph.remove_node(node.node_index());
|
GenericIndex::<GW>::new(self.graph.add_node(Compound::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) {
|
||||||
|
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);
|
||||||
*self.graph.node_weight_mut(dot.node_index()).unwrap() =
|
*self.graph.node_weight_mut(dot.node_index()).unwrap() = Compound::Primitive(weight.into());
|
||||||
CompoundWeight::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() =
|
*self.graph.node_weight_mut(bend.node_index()).unwrap() =
|
||||||
CompoundWeight::Primitive(weight.into());
|
Compound::Primitive(weight.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn flip_bend(&mut self, bend: BI) {
|
pub fn flip_bend(&mut self, bend: BI) {
|
||||||
|
|
@ -278,7 +285,7 @@ impl<
|
||||||
}
|
}
|
||||||
|
|
||||||
fn primitive_weight(&self, index: NodeIndex<usize>) -> PW {
|
fn primitive_weight(&self, index: NodeIndex<usize>) -> PW {
|
||||||
if let CompoundWeight::Primitive(weight) = *self.graph.node_weight(index).unwrap() {
|
if let Compound::Primitive(weight) = *self.graph.node_weight(index).unwrap() {
|
||||||
weight
|
weight
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
|
|
@ -452,7 +459,7 @@ 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 graph(&self) -> &StableDiGraph<CompoundWeight<PW, GW>, GeometryLabel, usize> {
|
pub fn graph(&self) -> &StableDiGraph<Compound<PW, GW>, GeometryLabel, usize> {
|
||||||
&self.graph
|
&self.graph
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use crate::{
|
||||||
drawing::graph::{GetLayer, Retag},
|
drawing::graph::{GetLayer, Retag},
|
||||||
geometry::{
|
geometry::{
|
||||||
shape::{Shape, ShapeTrait},
|
shape::{Shape, ShapeTrait},
|
||||||
BendWeightTrait, CompoundWeight, DotWeightTrait, Geometry, GeometryLabel, GetWidth,
|
BendWeightTrait, Compound, DotWeightTrait, Geometry, GeometryLabel, GetWidth,
|
||||||
SegWeightTrait,
|
SegWeightTrait,
|
||||||
},
|
},
|
||||||
graph::{GenericIndex, GetNodeIndex},
|
graph::{GenericIndex, GetNodeIndex},
|
||||||
|
|
@ -21,10 +21,8 @@ pub struct Bbox {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Bbox {
|
impl Bbox {
|
||||||
pub fn new(shape: &Shape, layer: u64) -> Bbox {
|
pub fn new(aabb: AABB<[f64; 3]>) -> Bbox {
|
||||||
Self {
|
Self { aabb }
|
||||||
aabb: shape.envelope_3d(0.0, layer),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -35,7 +33,7 @@ impl RTreeObject for Bbox {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type BboxedIndex<GI> = GeomWithData<Bbox, GI>;
|
type BboxedIndex<I> = GeomWithData<Bbox, I>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct GeometryWithRtree<
|
pub struct GeometryWithRtree<
|
||||||
|
|
@ -48,10 +46,9 @@ pub struct GeometryWithRtree<
|
||||||
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,
|
||||||
GI: GetNodeIndex + Copy,
|
|
||||||
> {
|
> {
|
||||||
geometry: Geometry<PW, DW, SW, BW, GW, PI, DI, SI, BI, GI>,
|
geometry: Geometry<PW, DW, SW, BW, GW, PI, DI, SI, BI>,
|
||||||
rtree: RTree<BboxedIndex<PI>>,
|
rtree: RTree<BboxedIndex<Compound<PI, GenericIndex<GW>>>>,
|
||||||
layer_count: u64,
|
layer_count: u64,
|
||||||
weight_marker: PhantomData<PW>,
|
weight_marker: PhantomData<PW>,
|
||||||
dot_weight_marker: PhantomData<DW>,
|
dot_weight_marker: PhantomData<DW>,
|
||||||
|
|
@ -75,12 +72,11 @@ impl<
|
||||||
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,
|
||||||
GI: GetNodeIndex + Copy,
|
> GeometryWithRtree<PW, DW, SW, BW, GW, PI, DI, SI, BI>
|
||||||
> GeometryWithRtree<PW, DW, SW, BW, GW, PI, DI, SI, BI, GI>
|
|
||||||
{
|
{
|
||||||
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, GI>::new(),
|
geometry: Geometry::<PW, DW, SW, BW, GW, PI, DI, SI, BI>::new(),
|
||||||
rtree: RTree::new(),
|
rtree: RTree::new(),
|
||||||
layer_count,
|
layer_count,
|
||||||
weight_marker: PhantomData,
|
weight_marker: PhantomData,
|
||||||
|
|
@ -101,12 +97,11 @@ impl<
|
||||||
let dot = self.geometry.add_dot(weight);
|
let dot = self.geometry.add_dot(weight);
|
||||||
self.rtree.insert(BboxedIndex::new(
|
self.rtree.insert(BboxedIndex::new(
|
||||||
Bbox::new(
|
Bbox::new(
|
||||||
&self
|
self.geometry
|
||||||
.geometry
|
.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()),
|
||||||
weight.layer(),
|
|
||||||
),
|
),
|
||||||
dot.into(),
|
Compound::Primitive(dot.into()),
|
||||||
));
|
));
|
||||||
dot
|
dot
|
||||||
}
|
}
|
||||||
|
|
@ -123,12 +118,11 @@ impl<
|
||||||
let seg = self.geometry.add_seg(from, to, weight);
|
let seg = self.geometry.add_seg(from, to, weight);
|
||||||
self.rtree.insert(BboxedIndex::new(
|
self.rtree.insert(BboxedIndex::new(
|
||||||
Bbox::new(
|
Bbox::new(
|
||||||
&self
|
self.geometry
|
||||||
.geometry
|
.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()),
|
||||||
weight.layer(),
|
|
||||||
),
|
),
|
||||||
seg.into(),
|
Compound::Primitive(seg.into()),
|
||||||
));
|
));
|
||||||
seg
|
seg
|
||||||
}
|
}
|
||||||
|
|
@ -146,16 +140,32 @@ impl<
|
||||||
let bend = self.geometry.add_bend(from, to, core, weight);
|
let bend = self.geometry.add_bend(from, to, core, weight);
|
||||||
self.rtree.insert(BboxedIndex::new(
|
self.rtree.insert(BboxedIndex::new(
|
||||||
Bbox::new(
|
Bbox::new(
|
||||||
&self
|
self.geometry
|
||||||
.geometry
|
.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()),
|
||||||
weight.layer(),
|
|
||||||
),
|
),
|
||||||
bend.into(),
|
Compound::Primitive(bend.into()),
|
||||||
));
|
));
|
||||||
bend
|
bend
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_grouping(&mut self, weight: GW) -> GenericIndex<GW> {
|
||||||
|
let grouping = self.geometry.add_grouping(weight);
|
||||||
|
self.rtree.insert(BboxedIndex::new(
|
||||||
|
Bbox::new(AABB::<[f64; 3]>::from_point([0.0, 0.0, -1.0].into())),
|
||||||
|
Compound::Grouping(grouping),
|
||||||
|
));
|
||||||
|
grouping
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn assign_to_grouping<W>(
|
||||||
|
&mut self,
|
||||||
|
primitive: GenericIndex<W>,
|
||||||
|
grouping: GenericIndex<GW>,
|
||||||
|
) {
|
||||||
|
self.geometry.assign_to_grouping(primitive, grouping)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn remove_dot(&mut self, dot: DI) -> Result<(), ()> {
|
pub fn remove_dot(&mut self, dot: DI) -> Result<(), ()> {
|
||||||
if self.geometry.joined_segs(dot).next().is_some() {
|
if self.geometry.joined_segs(dot).next().is_some() {
|
||||||
return Err(());
|
return Err(());
|
||||||
|
|
@ -166,18 +176,23 @@ impl<
|
||||||
}
|
}
|
||||||
|
|
||||||
self.rtree.remove(&self.make_dot_bbox(dot));
|
self.rtree.remove(&self.make_dot_bbox(dot));
|
||||||
self.geometry.remove(dot.into());
|
self.geometry.remove_primitive(dot.into());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_seg(&mut self, seg: SI) {
|
pub fn remove_seg(&mut self, seg: SI) {
|
||||||
self.rtree.remove(&self.make_seg_bbox(seg));
|
self.rtree.remove(&self.make_seg_bbox(seg));
|
||||||
self.geometry.remove(seg.into());
|
self.geometry.remove_primitive(seg.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_bend(&mut self, bend: BI) {
|
pub fn remove_bend(&mut self, bend: BI) {
|
||||||
self.rtree.remove(&self.make_bend_bbox(bend));
|
self.rtree.remove(&self.make_bend_bbox(bend));
|
||||||
self.geometry.remove(bend.into());
|
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 move_dot(&mut self, dot: DI, to: Point) {
|
pub fn move_dot(&mut self, dot: DI, to: Point) {
|
||||||
|
|
@ -258,27 +273,48 @@ impl<
|
||||||
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,
|
||||||
GI: GetNodeIndex + Copy,
|
> GeometryWithRtree<PW, DW, SW, BW, GW, PI, DI, SI, BI>
|
||||||
> GeometryWithRtree<PW, DW, SW, BW, GW, PI, DI, SI, BI, GI>
|
|
||||||
{
|
{
|
||||||
fn make_dot_bbox(&self, dot: DI) -> BboxedIndex<PI> {
|
fn make_dot_bbox(&self, dot: DI) -> BboxedIndex<Compound<PI, GenericIndex<GW>>> {
|
||||||
BboxedIndex::new(
|
BboxedIndex::new(
|
||||||
Bbox::new(&self.geometry.dot_shape(dot), self.layer(dot.into())),
|
Bbox::new(
|
||||||
dot.into(),
|
self.geometry
|
||||||
|
.dot_shape(dot)
|
||||||
|
.envelope_3d(0.0, self.layer(dot.into())),
|
||||||
|
),
|
||||||
|
Compound::Primitive(dot.into()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_seg_bbox(&self, seg: SI) -> BboxedIndex<PI> {
|
fn make_seg_bbox(&self, seg: SI) -> BboxedIndex<Compound<PI, GenericIndex<GW>>> {
|
||||||
BboxedIndex::new(
|
BboxedIndex::new(
|
||||||
Bbox::new(&self.geometry.seg_shape(seg), self.layer(seg.into())),
|
Bbox::new(
|
||||||
seg.into(),
|
self.geometry
|
||||||
|
.seg_shape(seg)
|
||||||
|
.envelope_3d(0.0, self.layer(seg.into())),
|
||||||
|
),
|
||||||
|
Compound::Primitive(seg.into()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_bend_bbox(&self, bend: BI) -> BboxedIndex<PI> {
|
fn make_bend_bbox(&self, bend: BI) -> BboxedIndex<Compound<PI, GenericIndex<GW>>> {
|
||||||
BboxedIndex::new(
|
BboxedIndex::new(
|
||||||
Bbox::new(&self.geometry.bend_shape(bend), self.layer(bend.into())),
|
Bbox::new(
|
||||||
bend.into(),
|
self.geometry
|
||||||
|
.bend_shape(bend)
|
||||||
|
.envelope_3d(0.0, self.layer(bend.into())),
|
||||||
|
),
|
||||||
|
Compound::Primitive(bend.into()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_grouping_bbox(
|
||||||
|
&self,
|
||||||
|
grouping: GenericIndex<GW>,
|
||||||
|
) -> BboxedIndex<Compound<PI, GenericIndex<GW>>> {
|
||||||
|
BboxedIndex::new(
|
||||||
|
Bbox::new(AABB::<[f64; 3]>::from_point([0.0, 0.0, -1.0].into())),
|
||||||
|
Compound::Grouping(grouping),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -306,24 +342,30 @@ impl<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn geometry(&self) -> &Geometry<PW, DW, SW, BW, GW, PI, DI, SI, BI, GI> {
|
pub fn geometry(&self) -> &Geometry<PW, DW, SW, BW, GW, PI, DI, SI, BI> {
|
||||||
&self.geometry
|
&self.geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rtree(&self) -> &RTree<BboxedIndex<PI>> {
|
pub fn rtree(&self) -> &RTree<BboxedIndex<Compound<PI, GenericIndex<GW>>>> {
|
||||||
&self.rtree
|
&self.rtree
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn graph(&self) -> &StableDiGraph<CompoundWeight<PW, GW>, GeometryLabel, usize> {
|
pub fn graph(&self) -> &StableDiGraph<Compound<PW, GW>, 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| {
|
||||||
let node = wrapper.data;
|
// TODO: Test envelopes of groupings too.
|
||||||
let shape = self.shape(node);
|
let Compound::Primitive(primitive_node) = wrapper.data else {
|
||||||
let layer = self.layer(node);
|
return false;
|
||||||
let wrapper = BboxedIndex::new(Bbox::new(&shape, layer), node);
|
};
|
||||||
|
let shape = self.shape(primitive_node);
|
||||||
|
let layer = self.layer(primitive_node);
|
||||||
|
let wrapper = BboxedIndex::new(
|
||||||
|
Bbox::new(shape.envelope_3d(0.0, layer)),
|
||||||
|
Compound::Primitive(primitive_node),
|
||||||
|
);
|
||||||
!self
|
!self
|
||||||
.rtree
|
.rtree
|
||||||
.locate_in_envelope(&shape.envelope_3d(0.0, layer))
|
.locate_in_envelope(&shape.envelope_3d(0.0, layer))
|
||||||
|
|
|
||||||
20
src/mesh.rs
20
src/mesh.rs
|
|
@ -13,7 +13,7 @@ use crate::{
|
||||||
drawing::{
|
drawing::{
|
||||||
bend::{FixedBendIndex, LooseBendIndex},
|
bend::{FixedBendIndex, LooseBendIndex},
|
||||||
dot::FixedDotIndex,
|
dot::FixedDotIndex,
|
||||||
graph::{GeometryIndex, MakePrimitive},
|
graph::{MakePrimitive, PrimitiveIndex},
|
||||||
primitive::{GetCore, MakeShape, Primitive},
|
primitive::{GetCore, MakeShape, Primitive},
|
||||||
Drawing,
|
Drawing,
|
||||||
},
|
},
|
||||||
|
|
@ -37,12 +37,12 @@ pub enum TriangulationVertexIndex {
|
||||||
FixedBend(FixedBendIndex),
|
FixedBend(FixedBendIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<VertexIndex> for GeometryIndex {
|
impl From<VertexIndex> for PrimitiveIndex {
|
||||||
fn from(vertex: VertexIndex) -> Self {
|
fn from(vertex: VertexIndex) -> Self {
|
||||||
match vertex {
|
match vertex {
|
||||||
VertexIndex::FixedDot(dot) => GeometryIndex::FixedDot(dot),
|
VertexIndex::FixedDot(dot) => PrimitiveIndex::FixedDot(dot),
|
||||||
VertexIndex::FixedBend(bend) => GeometryIndex::FixedBend(bend),
|
VertexIndex::FixedBend(bend) => PrimitiveIndex::FixedBend(bend),
|
||||||
VertexIndex::LooseBend(bend) => GeometryIndex::LooseBend(bend),
|
VertexIndex::LooseBend(bend) => PrimitiveIndex::LooseBend(bend),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -94,18 +94,18 @@ impl Mesh {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate(&mut self, drawing: &Drawing<impl RulesTrait>) -> Result<(), InsertionError> {
|
pub fn generate(&mut self, drawing: &Drawing<impl RulesTrait>) -> Result<(), InsertionError> {
|
||||||
for node in drawing.nodes() {
|
for node in drawing.primitive_nodes() {
|
||||||
let center = node.primitive(drawing).shape().center();
|
let center = node.primitive(drawing).shape().center();
|
||||||
|
|
||||||
match node {
|
match node {
|
||||||
GeometryIndex::FixedDot(dot) => {
|
PrimitiveIndex::FixedDot(dot) => {
|
||||||
self.triangulation.add_vertex(TriangulationWeight {
|
self.triangulation.add_vertex(TriangulationWeight {
|
||||||
vertex: dot.into(),
|
vertex: dot.into(),
|
||||||
rails: vec![],
|
rails: vec![],
|
||||||
pos: center,
|
pos: center,
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
GeometryIndex::FixedBend(bend) => {
|
PrimitiveIndex::FixedBend(bend) => {
|
||||||
self.triangulation.add_vertex(TriangulationWeight {
|
self.triangulation.add_vertex(TriangulationWeight {
|
||||||
vertex: bend.into(),
|
vertex: bend.into(),
|
||||||
rails: vec![],
|
rails: vec![],
|
||||||
|
|
@ -116,10 +116,10 @@ impl Mesh {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for node in drawing.nodes() {
|
for node in drawing.primitive_nodes() {
|
||||||
// Add rails as vertices. This is how the mesh differs from the triangulation.
|
// Add rails as vertices. This is how the mesh differs from the triangulation.
|
||||||
match node {
|
match node {
|
||||||
GeometryIndex::LooseBend(bend) => {
|
PrimitiveIndex::LooseBend(bend) => {
|
||||||
self.triangulation
|
self.triangulation
|
||||||
.weight_mut(drawing.primitive(bend).core().into())
|
.weight_mut(drawing.primitive(bend).core().into())
|
||||||
.rails
|
.rails
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use crate::astar::{astar, AstarStrategy, PathTracker};
|
||||||
use crate::draw::DrawException;
|
use crate::draw::DrawException;
|
||||||
use crate::drawing::{
|
use crate::drawing::{
|
||||||
dot::FixedDotIndex,
|
dot::FixedDotIndex,
|
||||||
graph::{GeometryIndex, MakePrimitive},
|
graph::{MakePrimitive, PrimitiveIndex},
|
||||||
primitive::MakeShape,
|
primitive::MakeShape,
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
};
|
};
|
||||||
|
|
@ -118,7 +118,7 @@ impl<'a, RO: RouterObserverTrait<R>, R: RulesTrait> AstarStrategy<&Mesh, f64>
|
||||||
|
|
||||||
fn estimate_cost(&mut self, vertex: VertexIndex) -> f64 {
|
fn estimate_cost(&mut self, vertex: VertexIndex) -> f64 {
|
||||||
self.observer.on_estimate(&self.tracer, vertex);
|
self.observer.on_estimate(&self.tracer, vertex);
|
||||||
let start_point = GeometryIndex::from(vertex)
|
let start_point = PrimitiveIndex::from(vertex)
|
||||||
.primitive(self.tracer.layout.layout())
|
.primitive(self.tracer.layout.layout())
|
||||||
.shape()
|
.shape()
|
||||||
.center();
|
.center();
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
drawing::{
|
drawing::{
|
||||||
bend::{BendIndex, FixedBendIndex, LooseBendIndex},
|
bend::{BendIndex, FixedBendIndex, LooseBendIndex},
|
||||||
dot::FixedDotIndex,
|
dot::FixedDotIndex,
|
||||||
graph::{GeometryIndex, MakePrimitive},
|
graph::{MakePrimitive, PrimitiveIndex},
|
||||||
primitive::{FixedBend, FixedDot, GetFirstRail, GetInnerOuter, LooseBend, Primitive},
|
primitive::{FixedBend, FixedDot, GetFirstRail, GetInnerOuter, LooseBend, Primitive},
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
Drawing,
|
Drawing,
|
||||||
|
|
@ -26,12 +26,12 @@ pub enum WraparoundableIndex {
|
||||||
LooseBend(LooseBendIndex),
|
LooseBend(LooseBendIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<WraparoundableIndex> for GeometryIndex {
|
impl From<WraparoundableIndex> for PrimitiveIndex {
|
||||||
fn from(wraparoundable: WraparoundableIndex) -> Self {
|
fn from(wraparoundable: WraparoundableIndex) -> Self {
|
||||||
match wraparoundable {
|
match wraparoundable {
|
||||||
WraparoundableIndex::FixedDot(dot) => GeometryIndex::FixedDot(dot),
|
WraparoundableIndex::FixedDot(dot) => PrimitiveIndex::FixedDot(dot),
|
||||||
WraparoundableIndex::FixedBend(bend) => GeometryIndex::FixedBend(bend),
|
WraparoundableIndex::FixedBend(bend) => PrimitiveIndex::FixedBend(bend),
|
||||||
WraparoundableIndex::LooseBend(bend) => GeometryIndex::LooseBend(bend),
|
WraparoundableIndex::LooseBend(bend) => PrimitiveIndex::LooseBend(bend),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue