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::{
|
use crate::{
|
||||||
graph::{
|
graph::{
|
||||||
BendIndex, DotIndex, FixedBendIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight,
|
BendIndex, DotIndex, FixedBendIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight,
|
||||||
FixedSegIndex, FixedSegWeight, GetEnds, Index, LooseBendWeight,
|
FixedSegIndex, FixedSegWeight, Index,
|
||||||
},
|
},
|
||||||
guide::Guide,
|
guide::Guide,
|
||||||
layout::Layout,
|
layout::Layout,
|
||||||
|
|
|
||||||
35
src/graph.rs
35
src/graph.rs
|
|
@ -5,7 +5,7 @@ use std::marker::PhantomData;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
math::Circle,
|
math::Circle,
|
||||||
primitive::{GenericPrimitive, GetWeight, Primitive},
|
primitive::{GenericPrimitive, Primitive},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait Interior<T> {
|
pub trait Interior<T> {
|
||||||
|
|
@ -67,8 +67,7 @@ pub enum Weight {
|
||||||
FixedDot(FixedDotWeight),
|
FixedDot(FixedDotWeight),
|
||||||
LooseDot(LooseDotWeight),
|
LooseDot(LooseDotWeight),
|
||||||
FixedSeg(FixedSegWeight),
|
FixedSeg(FixedSegWeight),
|
||||||
HalfLooseSeg(HalfLooseSegWeight),
|
LooseSeg(LooseSegWeight),
|
||||||
FullyLooseSeg(FullyLooseSegWeight),
|
|
||||||
FixedBend(FixedBendWeight),
|
FixedBend(FixedBendWeight),
|
||||||
LooseBend(LooseBendWeight),
|
LooseBend(LooseBendWeight),
|
||||||
}
|
}
|
||||||
|
|
@ -79,8 +78,7 @@ pub enum Index {
|
||||||
FixedDot(FixedDotIndex),
|
FixedDot(FixedDotIndex),
|
||||||
LooseDot(LooseDotIndex),
|
LooseDot(LooseDotIndex),
|
||||||
FixedSeg(FixedSegIndex),
|
FixedSeg(FixedSegIndex),
|
||||||
HalfLooseSeg(HalfLooseSegIndex),
|
LooseSeg(LooseSegIndex),
|
||||||
FullyLooseSeg(FullyLooseSegIndex),
|
|
||||||
FixedBend(FixedBendIndex),
|
FixedBend(FixedBendIndex),
|
||||||
LooseBend(LooseBendIndex),
|
LooseBend(LooseBendIndex),
|
||||||
}
|
}
|
||||||
|
|
@ -105,27 +103,18 @@ impl From<DotIndex> for Index {
|
||||||
#[derive(Debug, EnumAsInner, Clone, Copy, PartialEq)]
|
#[derive(Debug, EnumAsInner, Clone, Copy, PartialEq)]
|
||||||
pub enum SegIndex {
|
pub enum SegIndex {
|
||||||
Fixed(FixedSegIndex),
|
Fixed(FixedSegIndex),
|
||||||
HalfLoose(HalfLooseSegIndex),
|
Loose(LooseSegIndex),
|
||||||
FullyLoose(FullyLooseSegIndex),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SegIndex> for Index {
|
impl From<SegIndex> for Index {
|
||||||
fn from(seg: SegIndex) -> Self {
|
fn from(seg: SegIndex) -> Self {
|
||||||
match seg {
|
match seg {
|
||||||
SegIndex::Fixed(fixed) => Index::FixedSeg(fixed),
|
SegIndex::Fixed(fixed) => Index::FixedSeg(fixed),
|
||||||
SegIndex::HalfLoose(half_loose) => Index::HalfLooseSeg(half_loose),
|
SegIndex::Loose(fully_loose) => Index::LooseSeg(fully_loose),
|
||||||
SegIndex::FullyLoose(fully_loose) => Index::FullyLooseSeg(fully_loose),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[enum_dispatch(GetNodeIndex, MakePrimitive)]
|
|
||||||
#[derive(Debug, EnumAsInner, Clone, Copy, PartialEq)]
|
|
||||||
pub enum LooseSegIndex {
|
|
||||||
Half(HalfLooseSegIndex),
|
|
||||||
Fully(FullyLooseSegIndex),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[enum_dispatch(GetNodeIndex, MakePrimitive)]
|
#[enum_dispatch(GetNodeIndex, MakePrimitive)]
|
||||||
#[derive(Debug, EnumAsInner, Clone, Copy, PartialEq)]
|
#[derive(Debug, EnumAsInner, Clone, Copy, PartialEq)]
|
||||||
pub enum BendIndex {
|
pub enum BendIndex {
|
||||||
|
|
@ -192,20 +181,12 @@ impl GetWidth for FixedSegWeight {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct HalfLooseSegWeight {
|
pub struct LooseSegWeight {
|
||||||
pub net: i64,
|
pub net: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_type!(HalfLooseSegWeight, HalfLooseSeg, HalfLooseSegIndex);
|
impl_type!(LooseSegWeight, LooseSeg, LooseSegIndex);
|
||||||
impl SegWeight for HalfLooseSegWeight {}
|
impl SegWeight for LooseSegWeight {}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
||||||
pub struct FullyLooseSegWeight {
|
|
||||||
pub net: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl_type!(FullyLooseSegWeight, FullyLooseSeg, FullyLooseSegIndex);
|
|
||||||
impl SegWeight for FullyLooseSegWeight {}
|
|
||||||
|
|
||||||
pub trait BendWeight: GetNet + Into<Weight> + Copy {}
|
pub trait BendWeight: GetNet + Into<Weight> + Copy {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use geo::Line;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
draw::{Head, HeadTrait},
|
draw::{Head, HeadTrait},
|
||||||
graph::{BendIndex, DotIndex, FixedBendIndex, FixedDotIndex, MakePrimitive},
|
graph::{BendIndex, DotIndex, FixedDotIndex, MakePrimitive},
|
||||||
layout::Layout,
|
layout::Layout,
|
||||||
math::{self, Circle},
|
math::{self, Circle},
|
||||||
primitive::{GetWeight, MakeShape},
|
primitive::{GetWeight, MakeShape},
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,9 @@ use rstar::{RTree, RTreeObject};
|
||||||
|
|
||||||
use crate::bow::Bow;
|
use crate::bow::Bow;
|
||||||
use crate::graph::{
|
use crate::graph::{
|
||||||
BendWeight, DotIndex, DotWeight, FixedBendIndex, FixedBendWeight, FixedDotIndex,
|
BendWeight, DotWeight, FixedBendIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight,
|
||||||
FixedDotWeight, FixedSegIndex, FixedSegWeight, FullyLooseSegIndex, FullyLooseSegWeight,
|
FixedSegIndex, FixedSegWeight, GenericIndex, GetNodeIndex, Index, Interior, Label,
|
||||||
GenericIndex, GetNodeIndex, HalfLooseSegIndex, HalfLooseSegWeight, Index, Interior, Label,
|
LooseDotIndex, LooseSegIndex, LooseSegWeight, MakePrimitive, Retag, SegWeight, Weight,
|
||||||
LooseDotIndex, LooseDotWeight, LooseSegIndex, MakePrimitive, Retag, SegWeight, Weight,
|
|
||||||
};
|
};
|
||||||
use crate::primitive::{GenericPrimitive, GetConnectable, GetWeight, MakeShape};
|
use crate::primitive::{GenericPrimitive, GetConnectable, GetWeight, MakeShape};
|
||||||
use crate::segbend::Segbend;
|
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_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.node_count() == old(self.graph.node_count()))]
|
||||||
#[debug_ensures(ret.is_err() -> self.graph.edge_count() == old(self.graph.edge_count()))]
|
#[debug_ensures(ret.is_err() -> self.graph.edge_count() == old(self.graph.edge_count()))]
|
||||||
pub fn add_half_loose_seg(
|
pub fn add_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(
|
|
||||||
&mut self,
|
&mut self,
|
||||||
from: LooseDotIndex,
|
from: LooseDotIndex,
|
||||||
to: LooseDotIndex,
|
to: LooseDotIndex,
|
||||||
weight: FullyLooseSegWeight,
|
weight: LooseSegWeight,
|
||||||
) -> Result<FullyLooseSegIndex, ()> {
|
) -> Result<LooseSegIndex, ()> {
|
||||||
self.add_seg(from, to, weight)
|
self.add_seg(from, to, weight)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,8 @@ use petgraph::Direction::{Incoming, Outgoing};
|
||||||
|
|
||||||
use crate::graph::{
|
use crate::graph::{
|
||||||
FixedBendIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight, FixedSegIndex, FixedSegWeight,
|
FixedBendIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight, FixedSegIndex, FixedSegWeight,
|
||||||
FullyLooseSegWeight, GenericIndex, GetEnds, GetNet, GetNodeIndex, GetWidth, HalfLooseSegWeight,
|
GenericIndex, GetEnds, GetNet, GetNodeIndex, GetWidth, Index, Interior, Label, LooseBendIndex,
|
||||||
Index, Interior, Label, LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight,
|
LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegWeight, MakePrimitive, Retag, Weight,
|
||||||
MakePrimitive, Retag, Weight,
|
|
||||||
};
|
};
|
||||||
use crate::math::{self, Circle};
|
use crate::math::{self, Circle};
|
||||||
use crate::shape::{BendShape, DotShape, SegShape, Shape, ShapeTrait};
|
use crate::shape::{BendShape, DotShape, SegShape, Shape, ShapeTrait};
|
||||||
|
|
@ -50,8 +49,7 @@ pub enum Primitive<'a> {
|
||||||
FixedDot(FixedDot<'a>),
|
FixedDot(FixedDot<'a>),
|
||||||
LooseDot(LooseDot<'a>),
|
LooseDot(LooseDot<'a>),
|
||||||
FixedSeg(FixedSeg<'a>),
|
FixedSeg(FixedSeg<'a>),
|
||||||
HalfLooseSeg(HalfLooseSeg<'a>),
|
LooseSeg(LooseSeg<'a>),
|
||||||
FullyLooseSeg(FullyLooseSeg<'a>),
|
|
||||||
FixedBend(FixedBend<'a>),
|
FixedBend(FixedBend<'a>),
|
||||||
LooseBend(LooseBend<'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> {
|
impl<'a> GetWeight<LooseSegWeight> for LooseSeg<'a> {
|
||||||
fn weight(&self) -> HalfLooseSegWeight {
|
fn weight(&self) -> LooseSegWeight {
|
||||||
self.tagged_weight().into_half_loose_seg().unwrap()
|
self.tagged_weight().into_loose_seg().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> MakeShape for HalfLooseSeg<'a> {
|
impl<'a> MakeShape for LooseSeg<'a> {
|
||||||
fn shape(&self) -> Shape {
|
fn shape(&self) -> Shape {
|
||||||
let ends = self.ends();
|
let ends = self.ends();
|
||||||
Shape::Seg(SegShape {
|
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 {
|
fn width(&self) -> f64 {
|
||||||
self.primitive(self.ends().1).weight().width()
|
self.primitive(self.ends().1).weight().width()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> GetEnds<FixedDotIndex, LooseDotIndex> for HalfLooseSeg<'a> {
|
impl<'a> GetEnds<LooseDotIndex, LooseDotIndex> for LooseSeg<'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> {
|
|
||||||
fn ends(&self) -> (LooseDotIndex, LooseDotIndex) {
|
fn ends(&self) -> (LooseDotIndex, LooseDotIndex) {
|
||||||
let v = self.adjacents();
|
let v = self.adjacents();
|
||||||
(LooseDotIndex::new(v[0]), LooseDotIndex::new(v[1]))
|
(LooseDotIndex::new(v[0]), LooseDotIndex::new(v[1]))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue