mirror of https://codeberg.org/topola/topola.git
graph: create `WraparoundableIndex` enum for wraparoundables
This commit is contained in:
parent
73736fef50
commit
5e3248014c
15
src/draw.rs
15
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<SegbendHead, ()> {
|
||||
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,
|
||||
|
|
|
|||
17
src/graph.rs
17
src/graph.rs
|
|
@ -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 {}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
|
|
|
|||
|
|
@ -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<LooseBendIndex, ()> {
|
||||
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!(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue