mirror of https://codeberg.org/topola/topola.git
graph,primitive: Remove half-loose seg objects
It was complicating things too much. We would have needed a new `Head` implementation.
This commit is contained in:
parent
5b2e421493
commit
4b46b2174b
|
|
@ -5,7 +5,7 @@ use geo::{EuclideanLength, Point};
|
|||
use crate::{
|
||||
graph::{
|
||||
BendIndex, DotIndex, FixedBendIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight,
|
||||
FixedSegIndex, FixedSegWeight, GetEnds, Index, LooseBendWeight,
|
||||
FixedSegIndex, FixedSegWeight, Index,
|
||||
},
|
||||
guide::Guide,
|
||||
layout::Layout,
|
||||
|
|
|
|||
35
src/graph.rs
35
src/graph.rs
|
|
@ -5,7 +5,7 @@ use std::marker::PhantomData;
|
|||
|
||||
use crate::{
|
||||
math::Circle,
|
||||
primitive::{GenericPrimitive, GetWeight, Primitive},
|
||||
primitive::{GenericPrimitive, Primitive},
|
||||
};
|
||||
|
||||
pub trait Interior<T> {
|
||||
|
|
@ -67,8 +67,7 @@ pub enum Weight {
|
|||
FixedDot(FixedDotWeight),
|
||||
LooseDot(LooseDotWeight),
|
||||
FixedSeg(FixedSegWeight),
|
||||
HalfLooseSeg(HalfLooseSegWeight),
|
||||
FullyLooseSeg(FullyLooseSegWeight),
|
||||
LooseSeg(LooseSegWeight),
|
||||
FixedBend(FixedBendWeight),
|
||||
LooseBend(LooseBendWeight),
|
||||
}
|
||||
|
|
@ -79,8 +78,7 @@ pub enum Index {
|
|||
FixedDot(FixedDotIndex),
|
||||
LooseDot(LooseDotIndex),
|
||||
FixedSeg(FixedSegIndex),
|
||||
HalfLooseSeg(HalfLooseSegIndex),
|
||||
FullyLooseSeg(FullyLooseSegIndex),
|
||||
LooseSeg(LooseSegIndex),
|
||||
FixedBend(FixedBendIndex),
|
||||
LooseBend(LooseBendIndex),
|
||||
}
|
||||
|
|
@ -105,27 +103,18 @@ impl From<DotIndex> for Index {
|
|||
#[derive(Debug, EnumAsInner, Clone, Copy, PartialEq)]
|
||||
pub enum SegIndex {
|
||||
Fixed(FixedSegIndex),
|
||||
HalfLoose(HalfLooseSegIndex),
|
||||
FullyLoose(FullyLooseSegIndex),
|
||||
Loose(LooseSegIndex),
|
||||
}
|
||||
|
||||
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),
|
||||
SegIndex::Loose(fully_loose) => Index::LooseSeg(fully_loose),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[enum_dispatch(GetNodeIndex, MakePrimitive)]
|
||||
#[derive(Debug, EnumAsInner, Clone, Copy, PartialEq)]
|
||||
pub enum LooseSegIndex {
|
||||
Half(HalfLooseSegIndex),
|
||||
Fully(FullyLooseSegIndex),
|
||||
}
|
||||
|
||||
#[enum_dispatch(GetNodeIndex, MakePrimitive)]
|
||||
#[derive(Debug, EnumAsInner, Clone, Copy, PartialEq)]
|
||||
pub enum BendIndex {
|
||||
|
|
@ -192,20 +181,12 @@ impl GetWidth for FixedSegWeight {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct HalfLooseSegWeight {
|
||||
pub struct LooseSegWeight {
|
||||
pub net: i64,
|
||||
}
|
||||
|
||||
impl_type!(HalfLooseSegWeight, HalfLooseSeg, HalfLooseSegIndex);
|
||||
impl SegWeight for HalfLooseSegWeight {}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct FullyLooseSegWeight {
|
||||
pub net: i64,
|
||||
}
|
||||
|
||||
impl_type!(FullyLooseSegWeight, FullyLooseSeg, FullyLooseSegIndex);
|
||||
impl SegWeight for FullyLooseSegWeight {}
|
||||
impl_type!(LooseSegWeight, LooseSeg, LooseSegIndex);
|
||||
impl SegWeight for LooseSegWeight {}
|
||||
|
||||
pub trait BendWeight: GetNet + Into<Weight> + Copy {}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use geo::Line;
|
|||
|
||||
use crate::{
|
||||
draw::{Head, HeadTrait},
|
||||
graph::{BendIndex, DotIndex, FixedBendIndex, FixedDotIndex, MakePrimitive},
|
||||
graph::{BendIndex, DotIndex, FixedDotIndex, MakePrimitive},
|
||||
layout::Layout,
|
||||
math::{self, Circle},
|
||||
primitive::{GetWeight, MakeShape},
|
||||
|
|
|
|||
|
|
@ -8,10 +8,9 @@ use rstar::{RTree, RTreeObject};
|
|||
|
||||
use crate::bow::Bow;
|
||||
use crate::graph::{
|
||||
BendWeight, DotIndex, DotWeight, FixedBendIndex, FixedBendWeight, FixedDotIndex,
|
||||
FixedDotWeight, FixedSegIndex, FixedSegWeight, FullyLooseSegIndex, FullyLooseSegWeight,
|
||||
GenericIndex, GetNodeIndex, HalfLooseSegIndex, HalfLooseSegWeight, Index, Interior, Label,
|
||||
LooseDotIndex, LooseDotWeight, LooseSegIndex, MakePrimitive, Retag, SegWeight, Weight,
|
||||
BendWeight, DotWeight, FixedBendIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight,
|
||||
FixedSegIndex, FixedSegWeight, GenericIndex, GetNodeIndex, Index, Interior, Label,
|
||||
LooseDotIndex, LooseSegIndex, LooseSegWeight, MakePrimitive, Retag, SegWeight, Weight,
|
||||
};
|
||||
use crate::primitive::{GenericPrimitive, GetConnectable, GetWeight, MakeShape};
|
||||
use crate::segbend::Segbend;
|
||||
|
|
@ -100,25 +99,12 @@ impl Layout {
|
|||
#[debug_ensures(ret.is_ok() -> self.graph.edge_count() == old(self.graph.edge_count() + 2))]
|
||||
#[debug_ensures(ret.is_err() -> self.graph.node_count() == old(self.graph.node_count()))]
|
||||
#[debug_ensures(ret.is_err() -> self.graph.edge_count() == old(self.graph.edge_count()))]
|
||||
pub fn add_half_loose_seg(
|
||||
&mut self,
|
||||
from: FixedDotIndex,
|
||||
to: LooseDotIndex,
|
||||
weight: HalfLooseSegWeight,
|
||||
) -> Result<HalfLooseSegIndex, ()> {
|
||||
self.add_seg(from, to, weight)
|
||||
}
|
||||
|
||||
#[debug_ensures(ret.is_ok() -> self.graph.node_count() == old(self.graph.node_count() + 1))]
|
||||
#[debug_ensures(ret.is_ok() -> self.graph.edge_count() == old(self.graph.edge_count() + 2))]
|
||||
#[debug_ensures(ret.is_err() -> self.graph.node_count() == old(self.graph.node_count()))]
|
||||
#[debug_ensures(ret.is_err() -> self.graph.edge_count() == old(self.graph.edge_count()))]
|
||||
pub fn add_fully_loose_seg(
|
||||
pub fn add_loose_seg(
|
||||
&mut self,
|
||||
from: LooseDotIndex,
|
||||
to: LooseDotIndex,
|
||||
weight: FullyLooseSegWeight,
|
||||
) -> Result<FullyLooseSegIndex, ()> {
|
||||
weight: LooseSegWeight,
|
||||
) -> Result<LooseSegIndex, ()> {
|
||||
self.add_seg(from, to, weight)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,9 +6,8 @@ use petgraph::Direction::{Incoming, Outgoing};
|
|||
|
||||
use crate::graph::{
|
||||
FixedBendIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight, FixedSegIndex, FixedSegWeight,
|
||||
FullyLooseSegWeight, GenericIndex, GetEnds, GetNet, GetNodeIndex, GetWidth, HalfLooseSegWeight,
|
||||
Index, Interior, Label, LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight,
|
||||
MakePrimitive, Retag, Weight,
|
||||
GenericIndex, GetEnds, GetNet, GetNodeIndex, GetWidth, Index, Interior, Label, LooseBendIndex,
|
||||
LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegWeight, MakePrimitive, Retag, Weight,
|
||||
};
|
||||
use crate::math::{self, Circle};
|
||||
use crate::shape::{BendShape, DotShape, SegShape, Shape, ShapeTrait};
|
||||
|
|
@ -50,8 +49,7 @@ pub enum Primitive<'a> {
|
|||
FixedDot(FixedDot<'a>),
|
||||
LooseDot(LooseDot<'a>),
|
||||
FixedSeg(FixedSeg<'a>),
|
||||
HalfLooseSeg(HalfLooseSeg<'a>),
|
||||
FullyLooseSeg(FullyLooseSeg<'a>),
|
||||
LooseSeg(LooseSeg<'a>),
|
||||
FixedBend(FixedBend<'a>),
|
||||
LooseBend(LooseBend<'a>),
|
||||
}
|
||||
|
|
@ -269,15 +267,15 @@ impl<'a> GetEnds<FixedDotIndex, FixedDotIndex> for FixedSeg<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub type HalfLooseSeg<'a> = GenericPrimitive<'a, HalfLooseSegWeight>;
|
||||
pub type LooseSeg<'a> = GenericPrimitive<'a, LooseSegWeight>;
|
||||
|
||||
impl<'a> GetWeight<HalfLooseSegWeight> for HalfLooseSeg<'a> {
|
||||
fn weight(&self) -> HalfLooseSegWeight {
|
||||
self.tagged_weight().into_half_loose_seg().unwrap()
|
||||
impl<'a> GetWeight<LooseSegWeight> for LooseSeg<'a> {
|
||||
fn weight(&self) -> LooseSegWeight {
|
||||
self.tagged_weight().into_loose_seg().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> MakeShape for HalfLooseSeg<'a> {
|
||||
impl<'a> MakeShape for LooseSeg<'a> {
|
||||
fn shape(&self) -> Shape {
|
||||
let ends = self.ends();
|
||||
Shape::Seg(SegShape {
|
||||
|
|
@ -288,45 +286,13 @@ impl<'a> MakeShape for HalfLooseSeg<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> GetWidth for HalfLooseSeg<'a> {
|
||||
impl<'a> GetWidth for LooseSeg<'a> {
|
||||
fn width(&self) -> f64 {
|
||||
self.primitive(self.ends().1).weight().width()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetEnds<FixedDotIndex, LooseDotIndex> for HalfLooseSeg<'a> {
|
||||
fn ends(&self) -> (FixedDotIndex, LooseDotIndex) {
|
||||
let v = self.adjacents();
|
||||
(FixedDotIndex::new(v[0]), LooseDotIndex::new(v[1]))
|
||||
}
|
||||
}
|
||||
|
||||
pub type FullyLooseSeg<'a> = GenericPrimitive<'a, FullyLooseSegWeight>;
|
||||
|
||||
impl<'a> GetWeight<FullyLooseSegWeight> for FullyLooseSeg<'a> {
|
||||
fn weight(&self) -> FullyLooseSegWeight {
|
||||
self.tagged_weight().into_fully_loose_seg().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> MakeShape for FullyLooseSeg<'a> {
|
||||
fn shape(&self) -> Shape {
|
||||
let ends = self.ends();
|
||||
Shape::Seg(SegShape {
|
||||
from: self.primitive(ends.0).weight().circle.pos,
|
||||
to: self.primitive(ends.1).weight().circle.pos,
|
||||
width: self.width(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetWidth for FullyLooseSeg<'a> {
|
||||
fn width(&self) -> f64 {
|
||||
self.primitive(self.ends().1).weight().width()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetEnds<LooseDotIndex, LooseDotIndex> for FullyLooseSeg<'a> {
|
||||
impl<'a> GetEnds<LooseDotIndex, LooseDotIndex> for LooseSeg<'a> {
|
||||
fn ends(&self) -> (LooseDotIndex, LooseDotIndex) {
|
||||
let v = self.adjacents();
|
||||
(LooseDotIndex::new(v[0]), LooseDotIndex::new(v[1]))
|
||||
|
|
|
|||
Loading…
Reference in New Issue