graph: create `WraparoundableIndex` enum for wraparoundables

This commit is contained in:
Mikolaj Wielgus 2023-12-17 01:38:49 +00:00
parent 73736fef50
commit 5e3248014c
3 changed files with 32 additions and 12 deletions

View File

@ -6,6 +6,7 @@ use crate::{
graph::{ graph::{
BendIndex, DotIndex, FixedDotIndex, FixedSegWeight, GetBand, GetNet, Index, LooseBendIndex, BendIndex, DotIndex, FixedDotIndex, FixedSegWeight, GetBand, GetNet, Index, LooseBendIndex,
LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegWeight, MakePrimitive, LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegWeight, MakePrimitive,
WraparoundableIndex,
}, },
guide::Guide, guide::Guide,
layout::Layout, layout::Layout,
@ -139,12 +140,14 @@ impl<'a> Draw<'a> {
pub fn segbend_around_dot( pub fn segbend_around_dot(
&mut self, &mut self,
head: Head, head: Head,
around: DotIndex, around: FixedDotIndex,
width: f64, width: f64,
) -> Result<SegbendHead, ()> { ) -> Result<SegbendHead, ()> {
let mut tangents = self let mut tangents = self.guide(&Default::default()).head_around_dot_segments(
.guide(&Default::default()) &head,
.head_around_dot_segments(&head, around, width)?; around.into(),
width,
)?;
let mut dirs = [true, false]; let mut dirs = [true, false];
if tangents.1.euclidean_length() < tangents.0.euclidean_length() { if tangents.1.euclidean_length() < tangents.0.euclidean_length() {
@ -211,7 +214,7 @@ impl<'a> Draw<'a> {
fn segbend_around( fn segbend_around(
&mut self, &mut self,
head: Head, head: Head,
around: Index, around: WraparoundableIndex,
from: Point, from: Point,
to: Point, to: Point,
cw: bool, cw: bool,
@ -236,7 +239,7 @@ impl<'a> Draw<'a> {
fn segbend( fn segbend(
&mut self, &mut self,
head: Head, head: Head,
around: Index, around: WraparoundableIndex,
to: Point, to: Point,
cw: bool, cw: bool,
width: f64, width: f64,

View File

@ -167,6 +167,23 @@ impl From<BendIndex> for Index {
} }
} }
impl From<BendIndex> 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<Weight> + Copy {} pub trait DotWeight: GetWidth + Into<Weight> + Copy {}
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]

View File

@ -11,7 +11,7 @@ use crate::graph::{
BendWeight, DotIndex, DotWeight, FixedBendIndex, FixedDotIndex, FixedDotWeight, FixedSegIndex, BendWeight, DotIndex, DotWeight, FixedBendIndex, FixedDotIndex, FixedDotWeight, FixedSegIndex,
FixedSegWeight, GenericIndex, GetNodeIndex, Index, Interior, Label, LooseBendIndex, FixedSegWeight, GenericIndex, GetNodeIndex, Index, Interior, Label, LooseBendIndex,
LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegIndex, LooseSegWeight, MakePrimitive, LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegIndex, LooseSegWeight, MakePrimitive,
Retag, SegWeight, Weight, Retag, SegWeight, Weight, WraparoundableIndex,
}; };
use crate::primitive::{GenericPrimitive, GetConnectable, GetWeight, MakeShape}; use crate::primitive::{GenericPrimitive, GetConnectable, GetWeight, MakeShape};
use crate::segbend::Segbend; use crate::segbend::Segbend;
@ -123,7 +123,7 @@ impl Layout {
pub fn add_segbend( pub fn add_segbend(
&mut self, &mut self,
from: DotIndex, from: DotIndex,
around: Index, around: WraparoundableIndex,
dot_weight: LooseDotWeight, dot_weight: LooseDotWeight,
seg_weight: LooseSegWeight, seg_weight: LooseSegWeight,
bend_weight: LooseBendWeight, bend_weight: LooseBendWeight,
@ -215,13 +215,13 @@ impl Layout {
&mut self, &mut self,
from: LooseDotIndex, from: LooseDotIndex,
to: LooseDotIndex, to: LooseDotIndex,
around: Index, around: WraparoundableIndex,
weight: LooseBendWeight, weight: LooseBendWeight,
) -> Result<LooseBendIndex, ()> { ) -> Result<LooseBendIndex, ()> {
match around { match around {
Index::FixedDot(core) => self.add_core_bend(from, to, core, weight), WraparoundableIndex::FixedDot(core) => self.add_core_bend(from, to, core, weight),
Index::FixedBend(around) => self.add_outer_bend(from, to, around, weight), WraparoundableIndex::FixedBend(around) => self.add_outer_bend(from, to, around, weight),
Index::LooseBend(around) => self.add_outer_bend(from, to, around, weight), WraparoundableIndex::LooseBend(around) => self.add_outer_bend(from, to, around, weight),
_ => unreachable!(), _ => unreachable!(),
} }
} }