mirror of https://codeberg.org/topola/topola.git
primitive: Remove traverser objects
Tey were a bad idea. As such objects immutably borrow the layout, one cannot use tem in a for loop that mutates it.
This commit is contained in:
parent
92834c66c8
commit
0706a8c258
11
src/draw.rs
11
src/draw.rs
|
|
@ -4,12 +4,11 @@ use geo::{EuclideanLength, Point};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
graph::{
|
graph::{
|
||||||
BendIndex, DotIndex, FixedDotIndex, FixedSegWeight, GetBand, GetEnds, GetNet, Index,
|
BendIndex, DotIndex, FixedDotIndex, FixedSegWeight, GetBand, GetNet, Index, LooseBendIndex,
|
||||||
LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegWeight,
|
LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegWeight, MakePrimitive,
|
||||||
MakePrimitive,
|
|
||||||
},
|
},
|
||||||
guide::Guide,
|
guide::Guide,
|
||||||
layout::{Band, Layout},
|
layout::Layout,
|
||||||
math::Circle,
|
math::Circle,
|
||||||
primitive::{GetOtherEnd, GetWeight},
|
primitive::{GetOtherEnd, GetWeight},
|
||||||
rules::{Conditions, Rules},
|
rules::{Conditions, Rules},
|
||||||
|
|
@ -126,7 +125,7 @@ impl<'a> Draw<'a> {
|
||||||
let head = self.extend_head(head, tangent.start_point())?;
|
let head = self.extend_head(head, tangent.start_point())?;
|
||||||
let _to_head = self.extend_head(to_head.into(), tangent.end_point())?;
|
let _to_head = self.extend_head(to_head.into(), tangent.end_point())?;
|
||||||
|
|
||||||
let net = head.dot().primitive(self.layout).net();
|
let _net = head.dot().primitive(self.layout).net();
|
||||||
self.layout.add_loose_seg(
|
self.layout.add_loose_seg(
|
||||||
head.dot(),
|
head.dot(),
|
||||||
into.into(),
|
into.into(),
|
||||||
|
|
@ -282,7 +281,7 @@ impl<'a> Draw<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[debug_ensures(self.layout.node_count() == old(self.layout.node_count()))]
|
#[debug_ensures(self.layout.node_count() == old(self.layout.node_count()))]
|
||||||
pub fn update_bow(&mut self, bend: LooseBendIndex) {
|
pub fn update_bow(&mut self, _bend: LooseBendIndex) {
|
||||||
/*let cw = self.layout.primitive(bend).weight().cw;
|
/*let cw = self.layout.primitive(bend).weight().cw;
|
||||||
let ends = self.layout.primitive(bend).ends();
|
let ends = self.layout.primitive(bend).ends();
|
||||||
let from_head = self.rear_head(ends.0);
|
let from_head = self.rear_head(ends.0);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use enum_dispatch::enum_dispatch;
|
use enum_dispatch::enum_dispatch;
|
||||||
use petgraph::stable_graph::{NodeIndex, StableDiGraph};
|
use petgraph::stable_graph::NodeIndex;
|
||||||
use std::{
|
use std::{
|
||||||
hash::{Hash, Hasher},
|
hash::{Hash, Hasher},
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use slab::Slab;
|
||||||
|
|
||||||
use crate::graph::{
|
use crate::graph::{
|
||||||
BendWeight, DotIndex, DotWeight, FixedBendIndex, FixedDotIndex, FixedDotWeight, FixedSegIndex,
|
BendWeight, DotIndex, DotWeight, FixedBendIndex, FixedDotIndex, FixedDotWeight, FixedSegIndex,
|
||||||
FixedSegWeight, GenericIndex, GetNetMut, GetNodeIndex, Index, Interior, Label, LooseBendIndex,
|
FixedSegWeight, GenericIndex, GetNodeIndex, Index, Interior, Label, LooseBendIndex,
|
||||||
LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegIndex, LooseSegWeight, MakePrimitive,
|
LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegIndex, LooseSegWeight, MakePrimitive,
|
||||||
Retag, SegWeight, Weight,
|
Retag, SegWeight, Weight,
|
||||||
};
|
};
|
||||||
|
|
@ -297,7 +297,7 @@ impl Layout {
|
||||||
Ok(bend)
|
Ok(bend)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reposition_bend(&mut self, bend: LooseBendIndex, from: Point, to: Point) {
|
pub fn reposition_bend(&mut self, _bend: LooseBendIndex, _from: Point, _to: Point) {
|
||||||
// TODO.
|
// TODO.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ mod rules;
|
||||||
mod segbend;
|
mod segbend;
|
||||||
mod shape;
|
mod shape;
|
||||||
mod tracer;
|
mod tracer;
|
||||||
mod traverser;
|
|
||||||
mod triangulation;
|
mod triangulation;
|
||||||
|
|
||||||
use geo::point;
|
use geo::point;
|
||||||
|
|
@ -32,7 +31,7 @@ use mesh::{Mesh, MeshEdgeReference, VertexIndex};
|
||||||
use petgraph::visit::{EdgeRef, IntoEdgeReferences};
|
use petgraph::visit::{EdgeRef, IntoEdgeReferences};
|
||||||
use primitive::MakeShape;
|
use primitive::MakeShape;
|
||||||
use router::RouterObserver;
|
use router::RouterObserver;
|
||||||
use rstar::RTreeObject;
|
|
||||||
use sdl2::event::Event;
|
use sdl2::event::Event;
|
||||||
use sdl2::gfx::primitives::DrawRenderer;
|
use sdl2::gfx::primitives::DrawRenderer;
|
||||||
use sdl2::keyboard::Keycode;
|
use sdl2::keyboard::Keycode;
|
||||||
|
|
|
||||||
10
src/mesh.rs
10
src/mesh.rs
|
|
@ -4,19 +4,13 @@ use enum_dispatch::enum_dispatch;
|
||||||
use geo::Point;
|
use geo::Point;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use petgraph::visit;
|
use petgraph::visit;
|
||||||
use petgraph::{
|
use petgraph::{stable_graph::NodeIndex, visit::EdgeRef};
|
||||||
stable_graph::{NodeIndex, StableDiGraph},
|
|
||||||
visit::EdgeRef,
|
|
||||||
};
|
|
||||||
use spade::{HasPosition, InsertionError, Point2};
|
use spade::{HasPosition, InsertionError, Point2};
|
||||||
|
|
||||||
use crate::primitive::{GetCore, Primitive};
|
use crate::primitive::{GetCore, Primitive};
|
||||||
use crate::triangulation::TriangulationEdgeReference;
|
use crate::triangulation::TriangulationEdgeReference;
|
||||||
use crate::{
|
use crate::{
|
||||||
graph::{
|
graph::{FixedBendIndex, FixedDotIndex, GetNodeIndex, Index, LooseBendIndex, MakePrimitive},
|
||||||
FixedBendIndex, FixedDotIndex, GetNodeIndex, Index, Label, LooseBendIndex, MakePrimitive,
|
|
||||||
Weight,
|
|
||||||
},
|
|
||||||
layout::Layout,
|
layout::Layout,
|
||||||
primitive::MakeShape,
|
primitive::MakeShape,
|
||||||
shape::ShapeTrait,
|
shape::ShapeTrait,
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,18 @@
|
||||||
use std::mem::swap;
|
use std::mem::swap;
|
||||||
|
|
||||||
use enum_dispatch::enum_dispatch;
|
use enum_dispatch::enum_dispatch;
|
||||||
use petgraph::stable_graph::{NodeIndex, StableDiGraph};
|
use petgraph::stable_graph::NodeIndex;
|
||||||
use petgraph::Direction::{Incoming, Outgoing};
|
use petgraph::Direction::{Incoming, Outgoing};
|
||||||
|
|
||||||
use crate::graph::{
|
use crate::graph::{
|
||||||
DotIndex, FixedBendIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight, FixedSegWeight,
|
DotIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight, FixedSegWeight, GenericIndex,
|
||||||
GenericIndex, GetBand, GetEnds, GetNet, GetNodeIndex, GetOffset, GetWidth, Index, Interior,
|
GetBand, GetEnds, GetNet, GetNodeIndex, GetOffset, GetWidth, Index, Interior, Label,
|
||||||
Label, LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegIndex,
|
LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegIndex, LooseSegWeight,
|
||||||
LooseSegWeight, MakePrimitive, Retag, Weight,
|
MakePrimitive, Retag, Weight,
|
||||||
};
|
};
|
||||||
use crate::layout::Layout;
|
use crate::layout::Layout;
|
||||||
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};
|
||||||
use crate::traverser::OutwardRailTraverser;
|
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
pub trait GetLayout {
|
pub trait GetLayout {
|
||||||
|
|
@ -51,12 +50,6 @@ pub trait GetOtherEnd<F: GetNodeIndex, T: GetNodeIndex + Into<F>>: GetEnds<F, T>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TraverseOutward: GetFirstRail {
|
|
||||||
fn traverse_outward(&self) -> OutwardRailTraverser {
|
|
||||||
OutwardRailTraverser::new(self.first_rail(), self.layout())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait GetFirstRail: GetLayout + GetNodeIndex {
|
pub trait GetFirstRail: GetLayout + GetNodeIndex {
|
||||||
fn first_rail(&self) -> Option<LooseBendIndex> {
|
fn first_rail(&self) -> Option<LooseBendIndex> {
|
||||||
self.layout()
|
self.layout()
|
||||||
|
|
@ -292,7 +285,6 @@ impl<'a> MakeShape for FixedDot<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TraverseOutward for FixedDot<'a> {}
|
|
||||||
impl<'a> GetFirstRail for FixedDot<'a> {}
|
impl<'a> GetFirstRail for FixedDot<'a> {}
|
||||||
|
|
||||||
pub type LooseDot<'a> = GenericPrimitive<'a, LooseDotWeight>;
|
pub type LooseDot<'a> = GenericPrimitive<'a, LooseDotWeight>;
|
||||||
|
|
@ -474,7 +466,6 @@ impl<'a> GetEnds<FixedDotIndex, FixedDotIndex> for FixedBend<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> GetOtherEnd<FixedDotIndex, FixedDotIndex> for FixedBend<'a> {}
|
impl<'a> GetOtherEnd<FixedDotIndex, FixedDotIndex> for FixedBend<'a> {}
|
||||||
impl<'a> TraverseOutward for FixedBend<'a> {}
|
|
||||||
impl<'a> GetFirstRail for FixedBend<'a> {}
|
impl<'a> GetFirstRail for FixedBend<'a> {}
|
||||||
impl<'a> GetCore for FixedBend<'a> {} // TODO: Fixed bends don't have cores actually.
|
impl<'a> GetCore for FixedBend<'a> {} // TODO: Fixed bends don't have cores actually.
|
||||||
//impl<'a> GetInnerOuter for FixedBend<'a> {}
|
//impl<'a> GetInnerOuter for FixedBend<'a> {}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,5 @@
|
||||||
use petgraph::stable_graph::StableDiGraph;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
graph::{
|
graph::{GetEnds, Index, Interior, LooseBendIndex, LooseDotIndex, LooseSegIndex},
|
||||||
GetEnds, Index, Interior, Label, LooseBendIndex, LooseDotIndex, LooseSegIndex, Weight,
|
|
||||||
},
|
|
||||||
layout::Layout,
|
layout::Layout,
|
||||||
primitive::{GetOtherEnd, LooseBend, LooseDot},
|
primitive::{GetOtherEnd, LooseBend, LooseDot},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ impl ShapeTrait for SegShape {
|
||||||
match other {
|
match other {
|
||||||
Shape::Dot(..) => unreachable!(),
|
Shape::Dot(..) => unreachable!(),
|
||||||
Shape::Seg(other) => self.polygon().intersects(&other.polygon()),
|
Shape::Seg(other) => self.polygon().intersects(&other.polygon()),
|
||||||
Shape::Bend(other) => {
|
Shape::Bend(_other) => {
|
||||||
/*for segment in self.polygon().exterior().lines() {
|
/*for segment in self.polygon().exterior().lines() {
|
||||||
let inner_circle = other.inner_circle();
|
let inner_circle = other.inner_circle();
|
||||||
let outer_circle = other.outer_circle();
|
let outer_circle = other.outer_circle();
|
||||||
|
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
use petgraph::stable_graph::StableDiGraph;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
graph::{Label, LooseBendIndex, Weight},
|
|
||||||
layout::Layout,
|
|
||||||
primitive::{GenericPrimitive, GetInnerOuter},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct OutwardRailTraverser<'a> {
|
|
||||||
rail: Option<LooseBendIndex>,
|
|
||||||
layout: &'a Layout,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> OutwardRailTraverser<'a> {
|
|
||||||
pub fn new(rail: Option<LooseBendIndex>, layout: &'a Layout) -> Self {
|
|
||||||
Self { rail, layout }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Iterator for OutwardRailTraverser<'a> {
|
|
||||||
type Item = LooseBendIndex;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
self.rail.map(|rail| {
|
|
||||||
self.rail = GenericPrimitive::new(rail, self.layout).outer();
|
|
||||||
rail
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue