guide: Take unqualified `{Dot,Seg,Bend}Index` unions as arguments

This commit is contained in:
Mikolaj Wielgus 2023-10-25 08:40:38 +00:00
parent cedc2253ca
commit 6f5a73759a
4 changed files with 64 additions and 27 deletions

View File

@ -4,8 +4,8 @@ use geo::{EuclideanLength, Point};
use crate::{ use crate::{
graph::{ graph::{
Ends, FixedBendIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight, FixedSegIndex, DotIndex, Ends, FixedBendIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight,
FixedSegWeight, Index, FixedSegIndex, FixedSegWeight, Index,
}, },
guide::Guide, guide::Guide,
layout::Layout, layout::Layout,
@ -100,9 +100,12 @@ impl<'a> Draw<'a> {
) -> Result<(), ()> { ) -> Result<(), ()> {
let to_head = self.head(into); let to_head = self.head(into);
let to_cw = self.guide(&Default::default()).head_cw(&to_head).unwrap(); let to_cw = self.guide(&Default::default()).head_cw(&to_head).unwrap();
let tangent = self let tangent = self.guide(&Default::default()).head_around_bend_segment(
.guide(&Default::default()) &head,
.head_around_bend_segment(&head, into_bend, to_cw, width)?; into_bend.into(),
to_cw,
width,
)?;
let head = self.extend_head(head, tangent.start_point())?; let head = self.extend_head(head, tangent.start_point())?;
let _to_head = self.extend_head(to_head, tangent.end_point())?; let _to_head = self.extend_head(to_head, tangent.end_point())?;
@ -118,7 +121,7 @@ impl<'a> Draw<'a> {
pub fn segbend_around_dot( pub fn segbend_around_dot(
&mut self, &mut self,
head: Head, head: Head,
around: FixedDotIndex, around: DotIndex,
width: f64, width: f64,
) -> Result<SegbendHead, ()> { ) -> Result<SegbendHead, ()> {
let mut tangents = self let mut tangents = self
@ -156,9 +159,11 @@ impl<'a> Draw<'a> {
around: FixedBendIndex, around: FixedBendIndex,
width: f64, width: f64,
) -> Result<SegbendHead, ()> { ) -> Result<SegbendHead, ()> {
let mut tangents = self let mut tangents = self.guide(&Default::default()).head_around_bend_segments(
.guide(&Default::default()) &head,
.head_around_bend_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() {

View File

@ -87,6 +87,15 @@ pub enum DotIndex {
Loose(LooseDotIndex), Loose(LooseDotIndex),
} }
impl From<DotIndex> for Index {
fn from(dot: DotIndex) -> Self {
match dot {
DotIndex::Fixed(fixed) => Index::FixedDot(fixed),
DotIndex::Loose(loose) => Index::LooseDot(loose),
}
}
}
#[enum_dispatch(GetNodeIndex, MakePrimitive)] #[enum_dispatch(GetNodeIndex, MakePrimitive)]
#[derive(Debug, EnumAsInner, Clone, Copy, PartialEq)] #[derive(Debug, EnumAsInner, Clone, Copy, PartialEq)]
pub enum SegIndex { pub enum SegIndex {
@ -95,6 +104,16 @@ pub enum SegIndex {
FullyLoose(FullyLooseSegIndex), FullyLoose(FullyLooseSegIndex),
} }
impl From<SegIndex> 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),
}
}
}
#[enum_dispatch(GetNodeIndex, MakePrimitive)] #[enum_dispatch(GetNodeIndex, MakePrimitive)]
#[derive(Debug, EnumAsInner, Clone, Copy, PartialEq)] #[derive(Debug, EnumAsInner, Clone, Copy, PartialEq)]
pub enum LooseSegIndex { pub enum LooseSegIndex {
@ -109,6 +128,15 @@ pub enum BendIndex {
Loose(LooseBendIndex), Loose(LooseBendIndex),
} }
impl From<BendIndex> for Index {
fn from(bend: BendIndex) -> Self {
match bend {
BendIndex::Fixed(fixed) => Index::FixedBend(fixed),
BendIndex::Loose(loose) => Index::LooseBend(loose),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct FixedDotWeight { pub struct FixedDotWeight {
pub net: i64, pub net: i64,

View File

@ -2,11 +2,12 @@ use geo::Line;
use crate::{ use crate::{
draw::{Head, HeadTrait}, draw::{Head, HeadTrait},
graph::{FixedBendIndex, FixedDotIndex}, graph::{BendIndex, DotIndex, FixedBendIndex, FixedDotIndex, MakePrimitive},
layout::Layout, layout::Layout,
math::{self, Circle}, math::{self, Circle},
primitive::{GetWeight, MakeShape}, primitive::{GetWeight, MakeShape},
rules::{Conditions, Rules}, rules::{Conditions, Rules},
shape::ShapeTrait,
}; };
pub struct Guide<'a, 'b> { pub struct Guide<'a, 'b> {
@ -43,7 +44,7 @@ impl<'a, 'b> Guide<'a, 'b> {
pub fn head_around_dot_segments( pub fn head_around_dot_segments(
&self, &self,
head: &Head, head: &Head,
around: FixedDotIndex, around: DotIndex,
width: f64, width: f64,
) -> Result<(Line, Line), ()> { ) -> Result<(Line, Line), ()> {
let from_circle = self.head_circle(head, width); let from_circle = self.head_circle(head, width);
@ -58,7 +59,7 @@ impl<'a, 'b> Guide<'a, 'b> {
pub fn head_around_dot_segment( pub fn head_around_dot_segment(
&self, &self,
head: &Head, head: &Head,
around: FixedDotIndex, around: DotIndex,
cw: bool, cw: bool,
width: f64, width: f64,
) -> Result<Line, ()> { ) -> Result<Line, ()> {
@ -72,7 +73,7 @@ impl<'a, 'b> Guide<'a, 'b> {
pub fn head_around_bend_segments( pub fn head_around_bend_segments(
&self, &self,
head: &Head, head: &Head,
around: FixedBendIndex, around: BendIndex,
width: f64, width: f64,
) -> Result<(Line, Line), ()> { ) -> Result<(Line, Line), ()> {
let from_circle = self.head_circle(head, width); let from_circle = self.head_circle(head, width);
@ -87,7 +88,7 @@ impl<'a, 'b> Guide<'a, 'b> {
pub fn head_around_bend_segment( pub fn head_around_bend_segment(
&self, &self,
head: &Head, head: &Head,
around: FixedBendIndex, around: BendIndex,
cw: bool, cw: bool,
width: f64, width: f64,
) -> Result<Line, ()> { ) -> Result<Line, ()> {
@ -121,10 +122,14 @@ impl<'a, 'b> Guide<'a, 'b> {
}, },
Head::Segbend(head) => { Head::Segbend(head) => {
if let Some(inner) = self.layout.primitive(head.segbend.bend).inner() { if let Some(inner) = self.layout.primitive(head.segbend.bend).inner() {
self.bend_circle(inner, width) self.bend_circle(inner.into(), width)
} else { } else {
self.dot_circle( self.dot_circle(
self.layout.primitive(head.segbend.bend).core().unwrap(), self.layout
.primitive(head.segbend.bend)
.core()
.unwrap()
.into(),
width, width,
) )
} }
@ -132,10 +137,9 @@ impl<'a, 'b> Guide<'a, 'b> {
} }
} }
fn bend_circle(&self, bend: FixedBendIndex, _width: f64) -> Circle { fn bend_circle(&self, bend: BendIndex, _width: f64) -> Circle {
let mut circle = self let mut circle = bend
.layout .primitive(&self.layout.graph)
.primitive(bend)
.shape() .shape()
.into_bend() .into_bend()
.unwrap() .unwrap()
@ -144,11 +148,11 @@ impl<'a, 'b> Guide<'a, 'b> {
circle circle
} }
fn dot_circle(&self, dot: FixedDotIndex, width: f64) -> Circle { fn dot_circle(&self, dot: DotIndex, width: f64) -> Circle {
let circle = self.layout.primitive(dot).weight().circle; let shape = dot.primitive(&self.layout.graph).shape();
Circle { Circle {
pos: circle.pos, pos: shape.center(),
r: circle.r + width + self.rules.ruleset(self.conditions).clearance.min, r: shape.width() / 2.0 + width + self.rules.ruleset(self.conditions).clearance.min,
} }
} }
} }

View File

@ -119,7 +119,7 @@ impl<'a> Tracer<'a> {
} }
} }
self.draw().segbend_around_dot(head, around, width) self.draw().segbend_around_dot(head, around.into(), width)
} }
fn is_under( fn is_under(
@ -153,7 +153,7 @@ impl<'a> Tracer<'a> {
let outer = self.layout.primitive(around).outer().unwrap(); let outer = self.layout.primitive(around).outer().unwrap();
let head = self let head = self
.draw() .draw()
.segbend_around_dot(Head::from(head), around, width)?; .segbend_around_dot(Head::from(head), around.into(), width)?;
self.layout.reattach_bend(outer, head.segbend.bend); self.layout.reattach_bend(outer, head.segbend.bend);
self.redraw_outward(outer)?; self.redraw_outward(outer)?;
@ -204,7 +204,7 @@ impl<'a> Tracer<'a> {
let segbend_head = if let Some(inner) = maybe_inner { let segbend_head = if let Some(inner) = maybe_inner {
self.draw().segbend_around_bend(head, inner, width)? self.draw().segbend_around_bend(head, inner, width)?
} else { } else {
self.draw().segbend_around_dot(head, core, width)? self.draw().segbend_around_dot(head, core.into(), width)?
}; };
maybe_inner = Some(segbend_head.segbend.bend); maybe_inner = Some(segbend_head.segbend.bend);