From 4b46b2174b1103bc104b752feedf6b68aa7f1030 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Fri, 27 Oct 2023 15:44:36 +0000 Subject: [PATCH] graph,primitive: Remove half-loose seg objects It was complicating things too much. We would have needed a new `Head` implementation. --- src/draw.rs | 2 +- src/graph.rs | 35 +++++++------------------------ src/guide.rs | 2 +- src/layout.rs | 26 ++++++----------------- src/primitive.rs | 54 +++++++++--------------------------------------- 5 files changed, 26 insertions(+), 93 deletions(-) diff --git a/src/draw.rs b/src/draw.rs index 3eb13d1..2d1953d 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -5,7 +5,7 @@ use geo::{EuclideanLength, Point}; use crate::{ graph::{ BendIndex, DotIndex, FixedBendIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight, - FixedSegIndex, FixedSegWeight, GetEnds, Index, LooseBendWeight, + FixedSegIndex, FixedSegWeight, Index, }, guide::Guide, layout::Layout, diff --git a/src/graph.rs b/src/graph.rs index 228d0f4..8171348 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -5,7 +5,7 @@ use std::marker::PhantomData; use crate::{ math::Circle, - primitive::{GenericPrimitive, GetWeight, Primitive}, + primitive::{GenericPrimitive, Primitive}, }; pub trait Interior { @@ -67,8 +67,7 @@ pub enum Weight { FixedDot(FixedDotWeight), LooseDot(LooseDotWeight), FixedSeg(FixedSegWeight), - HalfLooseSeg(HalfLooseSegWeight), - FullyLooseSeg(FullyLooseSegWeight), + LooseSeg(LooseSegWeight), FixedBend(FixedBendWeight), LooseBend(LooseBendWeight), } @@ -79,8 +78,7 @@ pub enum Index { FixedDot(FixedDotIndex), LooseDot(LooseDotIndex), FixedSeg(FixedSegIndex), - HalfLooseSeg(HalfLooseSegIndex), - FullyLooseSeg(FullyLooseSegIndex), + LooseSeg(LooseSegIndex), FixedBend(FixedBendIndex), LooseBend(LooseBendIndex), } @@ -105,27 +103,18 @@ impl From for Index { #[derive(Debug, EnumAsInner, Clone, Copy, PartialEq)] pub enum SegIndex { Fixed(FixedSegIndex), - HalfLoose(HalfLooseSegIndex), - FullyLoose(FullyLooseSegIndex), + Loose(LooseSegIndex), } impl From for Index { fn from(seg: SegIndex) -> Self { match seg { SegIndex::Fixed(fixed) => Index::FixedSeg(fixed), - SegIndex::HalfLoose(half_loose) => Index::HalfLooseSeg(half_loose), - SegIndex::FullyLoose(fully_loose) => Index::FullyLooseSeg(fully_loose), + SegIndex::Loose(fully_loose) => Index::LooseSeg(fully_loose), } } } -#[enum_dispatch(GetNodeIndex, MakePrimitive)] -#[derive(Debug, EnumAsInner, Clone, Copy, PartialEq)] -pub enum LooseSegIndex { - Half(HalfLooseSegIndex), - Fully(FullyLooseSegIndex), -} - #[enum_dispatch(GetNodeIndex, MakePrimitive)] #[derive(Debug, EnumAsInner, Clone, Copy, PartialEq)] pub enum BendIndex { @@ -192,20 +181,12 @@ impl GetWidth for FixedSegWeight { } #[derive(Debug, Clone, Copy, PartialEq)] -pub struct HalfLooseSegWeight { +pub struct LooseSegWeight { pub net: i64, } -impl_type!(HalfLooseSegWeight, HalfLooseSeg, HalfLooseSegIndex); -impl SegWeight for HalfLooseSegWeight {} - -#[derive(Debug, Clone, Copy, PartialEq)] -pub struct FullyLooseSegWeight { - pub net: i64, -} - -impl_type!(FullyLooseSegWeight, FullyLooseSeg, FullyLooseSegIndex); -impl SegWeight for FullyLooseSegWeight {} +impl_type!(LooseSegWeight, LooseSeg, LooseSegIndex); +impl SegWeight for LooseSegWeight {} pub trait BendWeight: GetNet + Into + Copy {} diff --git a/src/guide.rs b/src/guide.rs index 5b5ffc1..f861398 100644 --- a/src/guide.rs +++ b/src/guide.rs @@ -2,7 +2,7 @@ use geo::Line; use crate::{ draw::{Head, HeadTrait}, - graph::{BendIndex, DotIndex, FixedBendIndex, FixedDotIndex, MakePrimitive}, + graph::{BendIndex, DotIndex, FixedDotIndex, MakePrimitive}, layout::Layout, math::{self, Circle}, primitive::{GetWeight, MakeShape}, diff --git a/src/layout.rs b/src/layout.rs index 4bdff32..52483c4 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -8,10 +8,9 @@ use rstar::{RTree, RTreeObject}; use crate::bow::Bow; use crate::graph::{ - BendWeight, DotIndex, DotWeight, FixedBendIndex, FixedBendWeight, FixedDotIndex, - FixedDotWeight, FixedSegIndex, FixedSegWeight, FullyLooseSegIndex, FullyLooseSegWeight, - GenericIndex, GetNodeIndex, HalfLooseSegIndex, HalfLooseSegWeight, Index, Interior, Label, - LooseDotIndex, LooseDotWeight, LooseSegIndex, MakePrimitive, Retag, SegWeight, Weight, + BendWeight, DotWeight, FixedBendIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight, + FixedSegIndex, FixedSegWeight, GenericIndex, GetNodeIndex, Index, Interior, Label, + LooseDotIndex, LooseSegIndex, LooseSegWeight, MakePrimitive, Retag, SegWeight, Weight, }; use crate::primitive::{GenericPrimitive, GetConnectable, GetWeight, MakeShape}; use crate::segbend::Segbend; @@ -100,25 +99,12 @@ impl Layout { #[debug_ensures(ret.is_ok() -> self.graph.edge_count() == old(self.graph.edge_count() + 2))] #[debug_ensures(ret.is_err() -> self.graph.node_count() == old(self.graph.node_count()))] #[debug_ensures(ret.is_err() -> self.graph.edge_count() == old(self.graph.edge_count()))] - pub fn add_half_loose_seg( - &mut self, - from: FixedDotIndex, - to: LooseDotIndex, - weight: HalfLooseSegWeight, - ) -> Result { - self.add_seg(from, to, weight) - } - - #[debug_ensures(ret.is_ok() -> self.graph.node_count() == old(self.graph.node_count() + 1))] - #[debug_ensures(ret.is_ok() -> self.graph.edge_count() == old(self.graph.edge_count() + 2))] - #[debug_ensures(ret.is_err() -> self.graph.node_count() == old(self.graph.node_count()))] - #[debug_ensures(ret.is_err() -> self.graph.edge_count() == old(self.graph.edge_count()))] - pub fn add_fully_loose_seg( + pub fn add_loose_seg( &mut self, from: LooseDotIndex, to: LooseDotIndex, - weight: FullyLooseSegWeight, - ) -> Result { + weight: LooseSegWeight, + ) -> Result { self.add_seg(from, to, weight) } diff --git a/src/primitive.rs b/src/primitive.rs index 3b97e26..a04b23b 100644 --- a/src/primitive.rs +++ b/src/primitive.rs @@ -6,9 +6,8 @@ use petgraph::Direction::{Incoming, Outgoing}; use crate::graph::{ FixedBendIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight, FixedSegIndex, FixedSegWeight, - FullyLooseSegWeight, GenericIndex, GetEnds, GetNet, GetNodeIndex, GetWidth, HalfLooseSegWeight, - Index, Interior, Label, LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight, - MakePrimitive, Retag, Weight, + GenericIndex, GetEnds, GetNet, GetNodeIndex, GetWidth, Index, Interior, Label, LooseBendIndex, + LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegWeight, MakePrimitive, Retag, Weight, }; use crate::math::{self, Circle}; use crate::shape::{BendShape, DotShape, SegShape, Shape, ShapeTrait}; @@ -50,8 +49,7 @@ pub enum Primitive<'a> { FixedDot(FixedDot<'a>), LooseDot(LooseDot<'a>), FixedSeg(FixedSeg<'a>), - HalfLooseSeg(HalfLooseSeg<'a>), - FullyLooseSeg(FullyLooseSeg<'a>), + LooseSeg(LooseSeg<'a>), FixedBend(FixedBend<'a>), LooseBend(LooseBend<'a>), } @@ -269,15 +267,15 @@ impl<'a> GetEnds for FixedSeg<'a> { } } -pub type HalfLooseSeg<'a> = GenericPrimitive<'a, HalfLooseSegWeight>; +pub type LooseSeg<'a> = GenericPrimitive<'a, LooseSegWeight>; -impl<'a> GetWeight for HalfLooseSeg<'a> { - fn weight(&self) -> HalfLooseSegWeight { - self.tagged_weight().into_half_loose_seg().unwrap() +impl<'a> GetWeight for LooseSeg<'a> { + fn weight(&self) -> LooseSegWeight { + self.tagged_weight().into_loose_seg().unwrap() } } -impl<'a> MakeShape for HalfLooseSeg<'a> { +impl<'a> MakeShape for LooseSeg<'a> { fn shape(&self) -> Shape { let ends = self.ends(); Shape::Seg(SegShape { @@ -288,45 +286,13 @@ impl<'a> MakeShape for HalfLooseSeg<'a> { } } -impl<'a> GetWidth for HalfLooseSeg<'a> { +impl<'a> GetWidth for LooseSeg<'a> { fn width(&self) -> f64 { self.primitive(self.ends().1).weight().width() } } -impl<'a> GetEnds for HalfLooseSeg<'a> { - fn ends(&self) -> (FixedDotIndex, LooseDotIndex) { - let v = self.adjacents(); - (FixedDotIndex::new(v[0]), LooseDotIndex::new(v[1])) - } -} - -pub type FullyLooseSeg<'a> = GenericPrimitive<'a, FullyLooseSegWeight>; - -impl<'a> GetWeight for FullyLooseSeg<'a> { - fn weight(&self) -> FullyLooseSegWeight { - self.tagged_weight().into_fully_loose_seg().unwrap() - } -} - -impl<'a> MakeShape for FullyLooseSeg<'a> { - fn shape(&self) -> Shape { - let ends = self.ends(); - Shape::Seg(SegShape { - from: self.primitive(ends.0).weight().circle.pos, - to: self.primitive(ends.1).weight().circle.pos, - width: self.width(), - }) - } -} - -impl<'a> GetWidth for FullyLooseSeg<'a> { - fn width(&self) -> f64 { - self.primitive(self.ends().1).weight().width() - } -} - -impl<'a> GetEnds for FullyLooseSeg<'a> { +impl<'a> GetEnds for LooseSeg<'a> { fn ends(&self) -> (LooseDotIndex, LooseDotIndex) { let v = self.adjacents(); (LooseDotIndex::new(v[0]), LooseDotIndex::new(v[1]))