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::math::NoTangents;
|
||||
|
||||
use super::head::{Head, HeadRef};
|
||||
|
||||
#[enum_dispatch]
|
||||
#[derive(Error, Debug, Clone, Copy)]
|
||||
pub enum LayoutException {
|
||||
|
|
@ -919,6 +921,10 @@ impl<CW: Copy, R: RulesTrait> Drawing<CW, R> {
|
|||
Loose::new(index, self)
|
||||
}
|
||||
|
||||
pub fn head_ref(&self, head: Head) -> HeadRef<'_, CW, R> {
|
||||
HeadRef::new(head, self)
|
||||
}
|
||||
|
||||
pub fn layer_count(&self) -> usize {
|
||||
self.geometry_with_rtree.layer_count()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,6 @@
|
|||
use enum_dispatch::enum_dispatch;
|
||||
use geo::Line;
|
||||
|
||||
use crate::{
|
||||
drawing::{
|
||||
bend::BendIndex,
|
||||
dot::{DotIndex, FixedDotIndex, LooseDotIndex},
|
||||
graph::MakePrimitive,
|
||||
primitive::{GetCore, GetInnerOuter, GetOtherJoint, GetWeight, MakePrimitiveShape},
|
||||
rules::GetConditions,
|
||||
Drawing,
|
||||
},
|
||||
geometry::{
|
||||
primitive::{PrimitiveShape, PrimitiveShapeTrait},
|
||||
shape::ShapeTrait,
|
||||
|
|
@ -18,47 +9,15 @@ use crate::{
|
|||
};
|
||||
|
||||
use super::{
|
||||
cane::Cane,
|
||||
graph::PrimitiveIndex,
|
||||
primitive::GetJoints,
|
||||
rules::{Conditions, RulesTrait},
|
||||
bend::BendIndex,
|
||||
dot::{DotIndex, FixedDotIndex, LooseDotIndex},
|
||||
graph::{MakePrimitive, PrimitiveIndex},
|
||||
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> {
|
||||
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;
|
||||
mod drawing;
|
||||
pub mod guide;
|
||||
pub mod head;
|
||||
pub mod loose;
|
||||
pub mod primitive;
|
||||
pub mod rules;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ use crate::{
|
|||
bend::{BendIndex, LooseBendWeight},
|
||||
dot::{DotIndex, FixedDotIndex, LooseDotIndex, LooseDotWeight},
|
||||
graph::{GetLayer, GetMaybeNet, MakePrimitive},
|
||||
guide::{CaneHead, Guide, Head, HeadTrait},
|
||||
guide::Guide,
|
||||
head::{CaneHead, Head, HeadTrait},
|
||||
primitive::GetOtherJoint,
|
||||
rules::RulesTrait,
|
||||
seg::{LoneLooseSegWeight, SeqLooseSegWeight},
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ use crate::{
|
|||
band::BandFirstSegIndex,
|
||||
dot::{DotIndex, FixedDotIndex},
|
||||
graph::{MakePrimitive, PrimitiveIndex},
|
||||
guide::{CaneHead, Head, HeadTrait},
|
||||
primitive::MakePrimitiveShape,
|
||||
rules::RulesTrait,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
band::BandFirstSegIndex,
|
||||
dot::{DotIndex, FixedDotIndex},
|
||||
graph::{MakePrimitive, PrimitiveIndex},
|
||||
guide::{Head, HeadTrait},
|
||||
head::{Head, HeadTrait},
|
||||
primitive::MakePrimitiveShape,
|
||||
rules::RulesTrait,
|
||||
},
|
||||
|
|
@ -56,33 +56,17 @@ impl<'a, R: RulesTrait> RouterAstarStrategy<'a, R> {
|
|||
}
|
||||
|
||||
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() {
|
||||
DotIndex::Fixed(..) => 0.0,
|
||||
DotIndex::Loose(face) => {
|
||||
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
|
||||
DotIndex::Loose(face) => self
|
||||
.tracer
|
||||
.layout
|
||||
.drawing()
|
||||
.primitive(cane_head.cane.bend)
|
||||
.shape()
|
||||
.length()
|
||||
}
|
||||
.guide()
|
||||
.rear_head(face)
|
||||
.ref_(self.tracer.layout.drawing())
|
||||
.length(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
bend::LooseBendIndex,
|
||||
dot::FixedDotIndex,
|
||||
graph::PrimitiveIndex,
|
||||
guide::{BareHead, CaneHead, Head},
|
||||
head::{BareHead, CaneHead, Head},
|
||||
rules::RulesTrait,
|
||||
},
|
||||
router::{
|
||||
|
|
|
|||
|
|
@ -7,11 +7,7 @@ use thiserror::Error;
|
|||
|
||||
use crate::{
|
||||
drawing::{
|
||||
band::BandFirstSegIndex,
|
||||
bend::LooseBendIndex,
|
||||
dot::FixedDotIndex,
|
||||
graph::PrimitiveIndex,
|
||||
guide::{BareHead, CaneHead, Head},
|
||||
band::BandFirstSegIndex, bend::LooseBendIndex, dot::FixedDotIndex, graph::PrimitiveIndex,
|
||||
rules::RulesTrait,
|
||||
},
|
||||
layout::Layout,
|
||||
|
|
|
|||
Loading…
Reference in New Issue