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::{
|
||||
graph::{
|
||||
BendIndex, DotIndex, FixedDotIndex, FixedSegWeight, GetBand, GetEnds, GetNet, Index,
|
||||
LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegWeight,
|
||||
MakePrimitive,
|
||||
BendIndex, DotIndex, FixedDotIndex, FixedSegWeight, GetBand, GetNet, Index, LooseBendIndex,
|
||||
LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegWeight, MakePrimitive,
|
||||
},
|
||||
guide::Guide,
|
||||
layout::{Band, Layout},
|
||||
layout::Layout,
|
||||
math::Circle,
|
||||
primitive::{GetOtherEnd, GetWeight},
|
||||
rules::{Conditions, Rules},
|
||||
|
|
@ -126,7 +125,7 @@ impl<'a> Draw<'a> {
|
|||
let head = self.extend_head(head, tangent.start_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(
|
||||
head.dot(),
|
||||
into.into(),
|
||||
|
|
@ -282,7 +281,7 @@ impl<'a> Draw<'a> {
|
|||
}
|
||||
|
||||
#[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 ends = self.layout.primitive(bend).ends();
|
||||
let from_head = self.rear_head(ends.0);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use enum_dispatch::enum_dispatch;
|
||||
use petgraph::stable_graph::{NodeIndex, StableDiGraph};
|
||||
use petgraph::stable_graph::NodeIndex;
|
||||
use std::{
|
||||
hash::{Hash, Hasher},
|
||||
marker::PhantomData,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use slab::Slab;
|
|||
|
||||
use crate::graph::{
|
||||
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,
|
||||
Retag, SegWeight, Weight,
|
||||
};
|
||||
|
|
@ -297,7 +297,7 @@ impl Layout {
|
|||
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.
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ mod rules;
|
|||
mod segbend;
|
||||
mod shape;
|
||||
mod tracer;
|
||||
mod traverser;
|
||||
mod triangulation;
|
||||
|
||||
use geo::point;
|
||||
|
|
@ -32,7 +31,7 @@ use mesh::{Mesh, MeshEdgeReference, VertexIndex};
|
|||
use petgraph::visit::{EdgeRef, IntoEdgeReferences};
|
||||
use primitive::MakeShape;
|
||||
use router::RouterObserver;
|
||||
use rstar::RTreeObject;
|
||||
|
||||
use sdl2::event::Event;
|
||||
use sdl2::gfx::primitives::DrawRenderer;
|
||||
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 itertools::Itertools;
|
||||
use petgraph::visit;
|
||||
use petgraph::{
|
||||
stable_graph::{NodeIndex, StableDiGraph},
|
||||
visit::EdgeRef,
|
||||
};
|
||||
use petgraph::{stable_graph::NodeIndex, visit::EdgeRef};
|
||||
use spade::{HasPosition, InsertionError, Point2};
|
||||
|
||||
use crate::primitive::{GetCore, Primitive};
|
||||
use crate::triangulation::TriangulationEdgeReference;
|
||||
use crate::{
|
||||
graph::{
|
||||
FixedBendIndex, FixedDotIndex, GetNodeIndex, Index, Label, LooseBendIndex, MakePrimitive,
|
||||
Weight,
|
||||
},
|
||||
graph::{FixedBendIndex, FixedDotIndex, GetNodeIndex, Index, LooseBendIndex, MakePrimitive},
|
||||
layout::Layout,
|
||||
primitive::MakeShape,
|
||||
shape::ShapeTrait,
|
||||
|
|
|
|||
|
|
@ -1,19 +1,18 @@
|
|||
use std::mem::swap;
|
||||
|
||||
use enum_dispatch::enum_dispatch;
|
||||
use petgraph::stable_graph::{NodeIndex, StableDiGraph};
|
||||
use petgraph::stable_graph::NodeIndex;
|
||||
use petgraph::Direction::{Incoming, Outgoing};
|
||||
|
||||
use crate::graph::{
|
||||
DotIndex, FixedBendIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight, FixedSegWeight,
|
||||
GenericIndex, GetBand, GetEnds, GetNet, GetNodeIndex, GetOffset, GetWidth, Index, Interior,
|
||||
Label, LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegIndex,
|
||||
LooseSegWeight, MakePrimitive, Retag, Weight,
|
||||
DotIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight, FixedSegWeight, GenericIndex,
|
||||
GetBand, GetEnds, GetNet, GetNodeIndex, GetOffset, GetWidth, Index, Interior, Label,
|
||||
LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegIndex, LooseSegWeight,
|
||||
MakePrimitive, Retag, Weight,
|
||||
};
|
||||
use crate::layout::Layout;
|
||||
use crate::math::{self, Circle};
|
||||
use crate::shape::{BendShape, DotShape, SegShape, Shape, ShapeTrait};
|
||||
use crate::traverser::OutwardRailTraverser;
|
||||
|
||||
#[enum_dispatch]
|
||||
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 {
|
||||
fn first_rail(&self) -> Option<LooseBendIndex> {
|
||||
self.layout()
|
||||
|
|
@ -292,7 +285,6 @@ impl<'a> MakeShape for FixedDot<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> TraverseOutward for FixedDot<'a> {}
|
||||
impl<'a> GetFirstRail for FixedDot<'a> {}
|
||||
|
||||
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> TraverseOutward 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> GetInnerOuter for FixedBend<'a> {}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,5 @@
|
|||
use petgraph::stable_graph::StableDiGraph;
|
||||
|
||||
use crate::{
|
||||
graph::{
|
||||
GetEnds, Index, Interior, Label, LooseBendIndex, LooseDotIndex, LooseSegIndex, Weight,
|
||||
},
|
||||
graph::{GetEnds, Index, Interior, LooseBendIndex, LooseDotIndex, LooseSegIndex},
|
||||
layout::Layout,
|
||||
primitive::{GetOtherEnd, LooseBend, LooseDot},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ impl ShapeTrait for SegShape {
|
|||
match other {
|
||||
Shape::Dot(..) => unreachable!(),
|
||||
Shape::Seg(other) => self.polygon().intersects(&other.polygon()),
|
||||
Shape::Bend(other) => {
|
||||
Shape::Bend(_other) => {
|
||||
/*for segment in self.polygon().exterior().lines() {
|
||||
let inner_circle = other.inner_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