mirror of https://codeberg.org/topola/topola.git
guide: Take unqualified `{Dot,Seg,Bend}Index` unions as arguments
This commit is contained in:
parent
cedc2253ca
commit
6f5a73759a
23
src/draw.rs
23
src/draw.rs
|
|
@ -4,8 +4,8 @@ use geo::{EuclideanLength, Point};
|
|||
|
||||
use crate::{
|
||||
graph::{
|
||||
Ends, FixedBendIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight, FixedSegIndex,
|
||||
FixedSegWeight, Index,
|
||||
DotIndex, Ends, FixedBendIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight,
|
||||
FixedSegIndex, FixedSegWeight, Index,
|
||||
},
|
||||
guide::Guide,
|
||||
layout::Layout,
|
||||
|
|
@ -100,9 +100,12 @@ impl<'a> Draw<'a> {
|
|||
) -> Result<(), ()> {
|
||||
let to_head = self.head(into);
|
||||
let to_cw = self.guide(&Default::default()).head_cw(&to_head).unwrap();
|
||||
let tangent = self
|
||||
.guide(&Default::default())
|
||||
.head_around_bend_segment(&head, into_bend, to_cw, width)?;
|
||||
let tangent = self.guide(&Default::default()).head_around_bend_segment(
|
||||
&head,
|
||||
into_bend.into(),
|
||||
to_cw,
|
||||
width,
|
||||
)?;
|
||||
|
||||
let head = self.extend_head(head, tangent.start_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(
|
||||
&mut self,
|
||||
head: Head,
|
||||
around: FixedDotIndex,
|
||||
around: DotIndex,
|
||||
width: f64,
|
||||
) -> Result<SegbendHead, ()> {
|
||||
let mut tangents = self
|
||||
|
|
@ -156,9 +159,11 @@ impl<'a> Draw<'a> {
|
|||
around: FixedBendIndex,
|
||||
width: f64,
|
||||
) -> Result<SegbendHead, ()> {
|
||||
let mut tangents = self
|
||||
.guide(&Default::default())
|
||||
.head_around_bend_segments(&head, around, width)?;
|
||||
let mut tangents = self.guide(&Default::default()).head_around_bend_segments(
|
||||
&head,
|
||||
around.into(),
|
||||
width,
|
||||
)?;
|
||||
let mut dirs = [true, false];
|
||||
|
||||
if tangents.1.euclidean_length() < tangents.0.euclidean_length() {
|
||||
|
|
|
|||
28
src/graph.rs
28
src/graph.rs
|
|
@ -87,6 +87,15 @@ pub enum DotIndex {
|
|||
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)]
|
||||
#[derive(Debug, EnumAsInner, Clone, Copy, PartialEq)]
|
||||
pub enum SegIndex {
|
||||
|
|
@ -95,6 +104,16 @@ pub enum SegIndex {
|
|||
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)]
|
||||
#[derive(Debug, EnumAsInner, Clone, Copy, PartialEq)]
|
||||
pub enum LooseSegIndex {
|
||||
|
|
@ -109,6 +128,15 @@ pub enum BendIndex {
|
|||
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)]
|
||||
pub struct FixedDotWeight {
|
||||
pub net: i64,
|
||||
|
|
|
|||
34
src/guide.rs
34
src/guide.rs
|
|
@ -2,11 +2,12 @@ use geo::Line;
|
|||
|
||||
use crate::{
|
||||
draw::{Head, HeadTrait},
|
||||
graph::{FixedBendIndex, FixedDotIndex},
|
||||
graph::{BendIndex, DotIndex, FixedBendIndex, FixedDotIndex, MakePrimitive},
|
||||
layout::Layout,
|
||||
math::{self, Circle},
|
||||
primitive::{GetWeight, MakeShape},
|
||||
rules::{Conditions, Rules},
|
||||
shape::ShapeTrait,
|
||||
};
|
||||
|
||||
pub struct Guide<'a, 'b> {
|
||||
|
|
@ -43,7 +44,7 @@ impl<'a, 'b> Guide<'a, 'b> {
|
|||
pub fn head_around_dot_segments(
|
||||
&self,
|
||||
head: &Head,
|
||||
around: FixedDotIndex,
|
||||
around: DotIndex,
|
||||
width: f64,
|
||||
) -> Result<(Line, Line), ()> {
|
||||
let from_circle = self.head_circle(head, width);
|
||||
|
|
@ -58,7 +59,7 @@ impl<'a, 'b> Guide<'a, 'b> {
|
|||
pub fn head_around_dot_segment(
|
||||
&self,
|
||||
head: &Head,
|
||||
around: FixedDotIndex,
|
||||
around: DotIndex,
|
||||
cw: bool,
|
||||
width: f64,
|
||||
) -> Result<Line, ()> {
|
||||
|
|
@ -72,7 +73,7 @@ impl<'a, 'b> Guide<'a, 'b> {
|
|||
pub fn head_around_bend_segments(
|
||||
&self,
|
||||
head: &Head,
|
||||
around: FixedBendIndex,
|
||||
around: BendIndex,
|
||||
width: f64,
|
||||
) -> Result<(Line, Line), ()> {
|
||||
let from_circle = self.head_circle(head, width);
|
||||
|
|
@ -87,7 +88,7 @@ impl<'a, 'b> Guide<'a, 'b> {
|
|||
pub fn head_around_bend_segment(
|
||||
&self,
|
||||
head: &Head,
|
||||
around: FixedBendIndex,
|
||||
around: BendIndex,
|
||||
cw: bool,
|
||||
width: f64,
|
||||
) -> Result<Line, ()> {
|
||||
|
|
@ -121,10 +122,14 @@ impl<'a, 'b> Guide<'a, 'b> {
|
|||
},
|
||||
Head::Segbend(head) => {
|
||||
if let Some(inner) = self.layout.primitive(head.segbend.bend).inner() {
|
||||
self.bend_circle(inner, width)
|
||||
self.bend_circle(inner.into(), width)
|
||||
} else {
|
||||
self.dot_circle(
|
||||
self.layout.primitive(head.segbend.bend).core().unwrap(),
|
||||
self.layout
|
||||
.primitive(head.segbend.bend)
|
||||
.core()
|
||||
.unwrap()
|
||||
.into(),
|
||||
width,
|
||||
)
|
||||
}
|
||||
|
|
@ -132,10 +137,9 @@ impl<'a, 'b> Guide<'a, 'b> {
|
|||
}
|
||||
}
|
||||
|
||||
fn bend_circle(&self, bend: FixedBendIndex, _width: f64) -> Circle {
|
||||
let mut circle = self
|
||||
.layout
|
||||
.primitive(bend)
|
||||
fn bend_circle(&self, bend: BendIndex, _width: f64) -> Circle {
|
||||
let mut circle = bend
|
||||
.primitive(&self.layout.graph)
|
||||
.shape()
|
||||
.into_bend()
|
||||
.unwrap()
|
||||
|
|
@ -144,11 +148,11 @@ impl<'a, 'b> Guide<'a, 'b> {
|
|||
circle
|
||||
}
|
||||
|
||||
fn dot_circle(&self, dot: FixedDotIndex, width: f64) -> Circle {
|
||||
let circle = self.layout.primitive(dot).weight().circle;
|
||||
fn dot_circle(&self, dot: DotIndex, width: f64) -> Circle {
|
||||
let shape = dot.primitive(&self.layout.graph).shape();
|
||||
Circle {
|
||||
pos: circle.pos,
|
||||
r: circle.r + width + self.rules.ruleset(self.conditions).clearance.min,
|
||||
pos: shape.center(),
|
||||
r: shape.width() / 2.0 + width + self.rules.ruleset(self.conditions).clearance.min,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
@ -153,7 +153,7 @@ impl<'a> Tracer<'a> {
|
|||
let outer = self.layout.primitive(around).outer().unwrap();
|
||||
let head = self
|
||||
.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.redraw_outward(outer)?;
|
||||
|
|
@ -204,7 +204,7 @@ impl<'a> Tracer<'a> {
|
|||
let segbend_head = if let Some(inner) = maybe_inner {
|
||||
self.draw().segbend_around_bend(head, inner, width)?
|
||||
} 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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue