From 5e3248014c836bccce221f4178cc40c3fc1979d1 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Sun, 17 Dec 2023 01:38:49 +0000 Subject: [PATCH] graph: create `WraparoundableIndex` enum for wraparoundables --- src/draw.rs | 15 +++++++++------ src/graph.rs | 17 +++++++++++++++++ src/layout.rs | 12 ++++++------ 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/draw.rs b/src/draw.rs index 921eab4..865430f 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -6,6 +6,7 @@ use crate::{ graph::{ BendIndex, DotIndex, FixedDotIndex, FixedSegWeight, GetBand, GetNet, Index, LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegWeight, MakePrimitive, + WraparoundableIndex, }, guide::Guide, layout::Layout, @@ -139,12 +140,14 @@ impl<'a> Draw<'a> { pub fn segbend_around_dot( &mut self, head: Head, - around: DotIndex, + around: FixedDotIndex, width: f64, ) -> Result { - let mut tangents = self - .guide(&Default::default()) - .head_around_dot_segments(&head, around, width)?; + let mut tangents = self.guide(&Default::default()).head_around_dot_segments( + &head, + around.into(), + width, + )?; let mut dirs = [true, false]; if tangents.1.euclidean_length() < tangents.0.euclidean_length() { @@ -211,7 +214,7 @@ impl<'a> Draw<'a> { fn segbend_around( &mut self, head: Head, - around: Index, + around: WraparoundableIndex, from: Point, to: Point, cw: bool, @@ -236,7 +239,7 @@ impl<'a> Draw<'a> { fn segbend( &mut self, head: Head, - around: Index, + around: WraparoundableIndex, to: Point, cw: bool, width: f64, diff --git a/src/graph.rs b/src/graph.rs index 7fba2d3..2f9839c 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -167,6 +167,23 @@ impl From for Index { } } +impl From for WraparoundableIndex { + fn from(bend: BendIndex) -> Self { + match bend { + BendIndex::Fixed(bend) => WraparoundableIndex::FixedBend(bend), + BendIndex::Loose(bend) => WraparoundableIndex::LooseBend(bend), + } + } +} + +#[enum_dispatch(GetNodeIndex, MakePrimitive, GetWraparound)] +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum WraparoundableIndex { + FixedBend(FixedBendIndex), + LooseBend(LooseBendIndex), + FixedDot(FixedDotIndex), +} + pub trait DotWeight: GetWidth + Into + Copy {} #[derive(Debug, Clone, Copy, PartialEq)] diff --git a/src/layout.rs b/src/layout.rs index 3347298..3aa05b1 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -11,7 +11,7 @@ use crate::graph::{ BendWeight, DotIndex, DotWeight, FixedBendIndex, FixedDotIndex, FixedDotWeight, FixedSegIndex, FixedSegWeight, GenericIndex, GetNodeIndex, Index, Interior, Label, LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegIndex, LooseSegWeight, MakePrimitive, - Retag, SegWeight, Weight, + Retag, SegWeight, Weight, WraparoundableIndex, }; use crate::primitive::{GenericPrimitive, GetConnectable, GetWeight, MakeShape}; use crate::segbend::Segbend; @@ -123,7 +123,7 @@ impl Layout { pub fn add_segbend( &mut self, from: DotIndex, - around: Index, + around: WraparoundableIndex, dot_weight: LooseDotWeight, seg_weight: LooseSegWeight, bend_weight: LooseBendWeight, @@ -215,13 +215,13 @@ impl Layout { &mut self, from: LooseDotIndex, to: LooseDotIndex, - around: Index, + around: WraparoundableIndex, weight: LooseBendWeight, ) -> Result { match around { - Index::FixedDot(core) => self.add_core_bend(from, to, core, weight), - Index::FixedBend(around) => self.add_outer_bend(from, to, around, weight), - Index::LooseBend(around) => self.add_outer_bend(from, to, around, weight), + WraparoundableIndex::FixedDot(core) => self.add_core_bend(from, to, core, weight), + WraparoundableIndex::FixedBend(around) => self.add_outer_bend(from, to, around, weight), + WraparoundableIndex::LooseBend(around) => self.add_outer_bend(from, to, around, weight), _ => unreachable!(), } }