mirror of https://codeberg.org/topola/topola.git
primitive: Move `.weight()` method to a new `GetWeight` trait
This commit is contained in:
parent
e271c82b7e
commit
4d20362e00
|
|
@ -7,6 +7,7 @@ use crate::{
|
|||
guide::Guide,
|
||||
layout::Layout,
|
||||
math::Circle,
|
||||
primitive::GetWeight,
|
||||
rules::{Conditions, Rules},
|
||||
segbend::Segbend,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
graph::{BendIndex, DotIndex},
|
||||
layout::Layout,
|
||||
math::{self, Circle},
|
||||
primitive::MakeShape,
|
||||
primitive::{GetWeight, MakeShape},
|
||||
rules::{Conditions, Rules},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use crate::graph::{
|
|||
BendIndex, BendWeight, DotIndex, DotWeight, GenericIndex, GetNodeIndex, Index, Interior, Label,
|
||||
Retag, SegIndex, SegWeight, Weight,
|
||||
};
|
||||
use crate::primitive::{GenericPrimitive, MakeShape};
|
||||
use crate::primitive::{GenericPrimitive, GetWeight, MakeShape};
|
||||
use crate::segbend::Segbend;
|
||||
use crate::shape::{Shape, ShapeTrait};
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@ use crate::graph::{
|
|||
use crate::math::{self, Circle};
|
||||
use crate::shape::{BendShape, DotShape, SegShape, Shape, ShapeTrait};
|
||||
|
||||
#[enum_dispatch]
|
||||
pub trait GetWeight<W> {
|
||||
fn weight(&self) -> W;
|
||||
}
|
||||
|
||||
#[enum_dispatch]
|
||||
pub trait MakeShape {
|
||||
fn shape(&self) -> Shape;
|
||||
|
|
@ -248,8 +253,10 @@ impl<'a> Dot<'a> {
|
|||
.filter(|bend| self.primitive(*bend).inner().is_none())
|
||||
.next()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn weight(&self) -> DotWeight {
|
||||
impl<'a> GetWeight<DotWeight> for Dot<'a> {
|
||||
fn weight(&self) -> DotWeight {
|
||||
self.tagged_weight().into_dot().unwrap()
|
||||
}
|
||||
}
|
||||
|
|
@ -272,8 +279,10 @@ impl<'a> Seg<'a> {
|
|||
pub fn prev(&self) -> Option<DotIndex> {
|
||||
self.prev_node().map(|ni| DotIndex::new(ni))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn weight(&self) -> SegWeight {
|
||||
impl<'a> GetWeight<SegWeight> for Seg<'a> {
|
||||
fn weight(&self) -> SegWeight {
|
||||
self.tagged_weight().into_seg().unwrap()
|
||||
}
|
||||
}
|
||||
|
|
@ -334,10 +343,6 @@ impl<'a> Bend<'a> {
|
|||
self.prev_node().map(|ni| DotIndex::new(ni))
|
||||
}
|
||||
|
||||
pub fn weight(&self) -> BendWeight {
|
||||
self.tagged_weight().into_bend().unwrap()
|
||||
}
|
||||
|
||||
fn inner_radius(&self) -> f64 {
|
||||
let mut r = 0.0;
|
||||
let mut layer = BendIndex::new(self.index.node_index());
|
||||
|
|
@ -368,6 +373,12 @@ impl<'a> Bend<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> GetWeight<BendWeight> for Bend<'a> {
|
||||
fn weight(&self) -> BendWeight {
|
||||
self.tagged_weight().into_bend().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> MakeShape for Bend<'a> {
|
||||
fn shape(&self) -> Shape {
|
||||
let ends = self.ends();
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use crate::layout::Layout;
|
|||
|
||||
use crate::math::Circle;
|
||||
use crate::mesh::{Mesh, MeshEdgeReference, VertexIndex};
|
||||
use crate::primitive::GetWeight;
|
||||
use crate::rules::Rules;
|
||||
use crate::tracer::{Trace, Tracer};
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
graph::{BendIndex, DotIndex, Ends},
|
||||
layout::Layout,
|
||||
mesh::{Mesh, VertexIndex},
|
||||
primitive::MakeShape,
|
||||
primitive::{GetWeight, MakeShape},
|
||||
rules::Rules,
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue