mirror of https://codeberg.org/topola/topola.git
drawing: move head length measurement methods to new refstruct
This commit is contained in:
parent
3c03b2dfa1
commit
b1f60847b3
|
|
@ -35,6 +35,8 @@ use crate::geometry::{
|
||||||
use crate::graph::{GenericIndex, GetPetgraphIndex};
|
use crate::graph::{GenericIndex, GetPetgraphIndex};
|
||||||
use crate::math::NoTangents;
|
use crate::math::NoTangents;
|
||||||
|
|
||||||
|
use super::head::{Head, HeadRef};
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
#[derive(Error, Debug, Clone, Copy)]
|
#[derive(Error, Debug, Clone, Copy)]
|
||||||
pub enum LayoutException {
|
pub enum LayoutException {
|
||||||
|
|
@ -919,6 +921,10 @@ impl<CW: Copy, R: RulesTrait> Drawing<CW, R> {
|
||||||
Loose::new(index, self)
|
Loose::new(index, self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn head_ref(&self, head: Head) -> HeadRef<'_, CW, R> {
|
||||||
|
HeadRef::new(head, self)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn layer_count(&self) -> usize {
|
pub fn layer_count(&self) -> usize {
|
||||||
self.geometry_with_rtree.layer_count()
|
self.geometry_with_rtree.layer_count()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,6 @@
|
||||||
use enum_dispatch::enum_dispatch;
|
|
||||||
use geo::Line;
|
use geo::Line;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
drawing::{
|
|
||||||
bend::BendIndex,
|
|
||||||
dot::{DotIndex, FixedDotIndex, LooseDotIndex},
|
|
||||||
graph::MakePrimitive,
|
|
||||||
primitive::{GetCore, GetInnerOuter, GetOtherJoint, GetWeight, MakePrimitiveShape},
|
|
||||||
rules::GetConditions,
|
|
||||||
Drawing,
|
|
||||||
},
|
|
||||||
geometry::{
|
geometry::{
|
||||||
primitive::{PrimitiveShape, PrimitiveShapeTrait},
|
primitive::{PrimitiveShape, PrimitiveShapeTrait},
|
||||||
shape::ShapeTrait,
|
shape::ShapeTrait,
|
||||||
|
|
@ -18,47 +9,15 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
cane::Cane,
|
bend::BendIndex,
|
||||||
graph::PrimitiveIndex,
|
dot::{DotIndex, FixedDotIndex, LooseDotIndex},
|
||||||
primitive::GetJoints,
|
graph::{MakePrimitive, PrimitiveIndex},
|
||||||
rules::{Conditions, RulesTrait},
|
head::{BareHead, CaneHead, Head, HeadTrait},
|
||||||
|
primitive::{GetCore, GetInnerOuter, GetJoints, GetOtherJoint, GetWeight, MakePrimitiveShape},
|
||||||
|
rules::{Conditions, GetConditions, RulesTrait},
|
||||||
|
Drawing,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[enum_dispatch]
|
|
||||||
pub trait HeadTrait {
|
|
||||||
fn face(&self) -> DotIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[enum_dispatch(HeadTrait)]
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
pub enum Head {
|
|
||||||
Bare(BareHead),
|
|
||||||
Cane(CaneHead),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
pub struct BareHead {
|
|
||||||
pub face: FixedDotIndex,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HeadTrait for BareHead {
|
|
||||||
fn face(&self) -> DotIndex {
|
|
||||||
self.face.into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
pub struct CaneHead {
|
|
||||||
pub face: LooseDotIndex,
|
|
||||||
pub cane: Cane,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HeadTrait for CaneHead {
|
|
||||||
fn face(&self) -> DotIndex {
|
|
||||||
self.face.into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Guide<'a, CW: Copy, R: RulesTrait> {
|
pub struct Guide<'a, CW: Copy, R: RulesTrait> {
|
||||||
drawing: &'a Drawing<CW, R>,
|
drawing: &'a Drawing<CW, R>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,84 @@
|
||||||
|
use enum_dispatch::enum_dispatch;
|
||||||
|
|
||||||
|
use crate::geometry::shape::MeasureLength;
|
||||||
|
|
||||||
|
use super::{
|
||||||
|
cane::Cane,
|
||||||
|
dot::{DotIndex, FixedDotIndex, LooseDotIndex},
|
||||||
|
primitive::MakePrimitiveShape,
|
||||||
|
rules::RulesTrait,
|
||||||
|
Drawing,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[enum_dispatch]
|
||||||
|
pub trait HeadTrait {
|
||||||
|
fn face(&self) -> DotIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[enum_dispatch(HeadTrait)]
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub enum Head {
|
||||||
|
Bare(BareHead),
|
||||||
|
Cane(CaneHead),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Head {
|
||||||
|
pub fn ref_<'a, CW: Copy, R: RulesTrait>(
|
||||||
|
&self,
|
||||||
|
drawing: &'a Drawing<CW, R>,
|
||||||
|
) -> HeadRef<'a, CW, R> {
|
||||||
|
HeadRef::new(*self, drawing)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub struct BareHead {
|
||||||
|
pub face: FixedDotIndex,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HeadTrait for BareHead {
|
||||||
|
fn face(&self) -> DotIndex {
|
||||||
|
self.face.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub struct CaneHead {
|
||||||
|
pub face: LooseDotIndex,
|
||||||
|
pub cane: Cane,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HeadTrait for CaneHead {
|
||||||
|
fn face(&self) -> DotIndex {
|
||||||
|
self.face.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct HeadRef<'a, CW: Copy, R: RulesTrait> {
|
||||||
|
head: Head,
|
||||||
|
drawing: &'a Drawing<CW, R>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, CW: Copy, R: RulesTrait> HeadRef<'a, CW, R> {
|
||||||
|
pub fn new(head: Head, drawing: &'a Drawing<CW, R>) -> Self {
|
||||||
|
Self { drawing, head }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, CW: Copy, R: RulesTrait> HeadTrait for HeadRef<'a, CW, R> {
|
||||||
|
fn face(&self) -> DotIndex {
|
||||||
|
self.head.face()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, CW: Copy, R: RulesTrait> MeasureLength for HeadRef<'a, CW, R> {
|
||||||
|
fn length(&self) -> f64 {
|
||||||
|
match self.head {
|
||||||
|
Head::Bare(..) => 0.0,
|
||||||
|
Head::Cane(cane_head) => {
|
||||||
|
self.drawing.primitive(cane_head.cane.seg).shape().length()
|
||||||
|
+ self.drawing.primitive(cane_head.cane.bend).shape().length()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ pub mod collect;
|
||||||
pub mod dot;
|
pub mod dot;
|
||||||
mod drawing;
|
mod drawing;
|
||||||
pub mod guide;
|
pub mod guide;
|
||||||
|
pub mod head;
|
||||||
pub mod loose;
|
pub mod loose;
|
||||||
pub mod primitive;
|
pub mod primitive;
|
||||||
pub mod rules;
|
pub mod rules;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@ use crate::{
|
||||||
bend::{BendIndex, LooseBendWeight},
|
bend::{BendIndex, LooseBendWeight},
|
||||||
dot::{DotIndex, FixedDotIndex, LooseDotIndex, LooseDotWeight},
|
dot::{DotIndex, FixedDotIndex, LooseDotIndex, LooseDotWeight},
|
||||||
graph::{GetLayer, GetMaybeNet, MakePrimitive},
|
graph::{GetLayer, GetMaybeNet, MakePrimitive},
|
||||||
guide::{CaneHead, Guide, Head, HeadTrait},
|
guide::Guide,
|
||||||
|
head::{CaneHead, Head, HeadTrait},
|
||||||
primitive::GetOtherJoint,
|
primitive::GetOtherJoint,
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
seg::{LoneLooseSegWeight, SeqLooseSegWeight},
|
seg::{LoneLooseSegWeight, SeqLooseSegWeight},
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ use crate::{
|
||||||
band::BandFirstSegIndex,
|
band::BandFirstSegIndex,
|
||||||
dot::{DotIndex, FixedDotIndex},
|
dot::{DotIndex, FixedDotIndex},
|
||||||
graph::{MakePrimitive, PrimitiveIndex},
|
graph::{MakePrimitive, PrimitiveIndex},
|
||||||
guide::{CaneHead, Head, HeadTrait},
|
|
||||||
primitive::MakePrimitiveShape,
|
primitive::MakePrimitiveShape,
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
band::BandFirstSegIndex,
|
band::BandFirstSegIndex,
|
||||||
dot::{DotIndex, FixedDotIndex},
|
dot::{DotIndex, FixedDotIndex},
|
||||||
graph::{MakePrimitive, PrimitiveIndex},
|
graph::{MakePrimitive, PrimitiveIndex},
|
||||||
guide::{Head, HeadTrait},
|
head::{Head, HeadTrait},
|
||||||
primitive::MakePrimitiveShape,
|
primitive::MakePrimitiveShape,
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
},
|
},
|
||||||
|
|
@ -56,33 +56,17 @@ impl<'a, R: RulesTrait> RouterAstarStrategy<'a, R> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bihead_length(&self) -> f64 {
|
fn bihead_length(&self) -> f64 {
|
||||||
self.head_length(&self.trace.head)
|
self.trace.head.ref_(self.tracer.layout.drawing()).length()
|
||||||
+ match self.trace.head.face() {
|
+ match self.trace.head.face() {
|
||||||
DotIndex::Fixed(..) => 0.0,
|
DotIndex::Fixed(..) => 0.0,
|
||||||
DotIndex::Loose(face) => {
|
DotIndex::Loose(face) => self
|
||||||
self.head_length(&self.tracer.layout.drawing().guide().rear_head(face))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn head_length(&self, head: &Head) -> f64 {
|
|
||||||
match head {
|
|
||||||
Head::Bare(..) => 0.0,
|
|
||||||
Head::Cane(cane_head) => {
|
|
||||||
self.tracer
|
|
||||||
.layout
|
|
||||||
.drawing()
|
|
||||||
.primitive(cane_head.cane.seg)
|
|
||||||
.shape()
|
|
||||||
.length()
|
|
||||||
+ self
|
|
||||||
.tracer
|
.tracer
|
||||||
.layout
|
.layout
|
||||||
.drawing()
|
.drawing()
|
||||||
.primitive(cane_head.cane.bend)
|
.guide()
|
||||||
.shape()
|
.rear_head(face)
|
||||||
.length()
|
.ref_(self.tracer.layout.drawing())
|
||||||
}
|
.length(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use crate::{
|
||||||
bend::LooseBendIndex,
|
bend::LooseBendIndex,
|
||||||
dot::FixedDotIndex,
|
dot::FixedDotIndex,
|
||||||
graph::PrimitiveIndex,
|
graph::PrimitiveIndex,
|
||||||
guide::{BareHead, CaneHead, Head},
|
head::{BareHead, CaneHead, Head},
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
},
|
},
|
||||||
router::{
|
router::{
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,7 @@ use thiserror::Error;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
drawing::{
|
drawing::{
|
||||||
band::BandFirstSegIndex,
|
band::BandFirstSegIndex, bend::LooseBendIndex, dot::FixedDotIndex, graph::PrimitiveIndex,
|
||||||
bend::LooseBendIndex,
|
|
||||||
dot::FixedDotIndex,
|
|
||||||
graph::PrimitiveIndex,
|
|
||||||
guide::{BareHead, CaneHead, Head},
|
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
},
|
},
|
||||||
layout::Layout,
|
layout::Layout,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue