mirror of https://codeberg.org/topola/topola.git
Pass `width` as an argument instead of holding it in `Route`
This commit is contained in:
parent
e5ba7401c1
commit
cd5365c26f
30
src/route.rs
30
src/route.rs
|
|
@ -15,16 +15,14 @@ pub struct Route<'a> {
|
|||
layout: &'a mut Layout,
|
||||
rules: &'a Rules,
|
||||
mesh: &'a Mesh,
|
||||
width: f64,
|
||||
}
|
||||
|
||||
impl<'a> Route<'a> {
|
||||
pub fn new(layout: &'a mut Layout, rules: &'a Rules, mesh: &'a Mesh, width: f64) -> Self {
|
||||
pub fn new(layout: &'a mut Layout, rules: &'a Rules, mesh: &'a Mesh) -> Self {
|
||||
Route {
|
||||
layout,
|
||||
rules,
|
||||
mesh,
|
||||
width,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -38,13 +36,17 @@ impl<'a> Route<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn finish(&mut self, trace: Trace, into: VertexIndex) {
|
||||
pub fn finish(&mut self, trace: Trace, into: VertexIndex, width: f64) -> Result<(), ()> {
|
||||
let into_dot = self.mesh.dot(into);
|
||||
let width = self.width;
|
||||
self.draw().finish(trace.head, into_dot, width);
|
||||
self.draw().finish(trace.head, into_dot, width)
|
||||
}
|
||||
|
||||
pub fn rework_path(&mut self, mut trace: Trace, path: &[VertexIndex]) -> Result<Trace, ()> {
|
||||
pub fn rework_path(
|
||||
&mut self,
|
||||
mut trace: Trace,
|
||||
path: &[VertexIndex],
|
||||
width: f64,
|
||||
) -> Result<Trace, ()> {
|
||||
let prefix_length = trace
|
||||
.path
|
||||
.iter()
|
||||
|
|
@ -54,12 +56,17 @@ impl<'a> Route<'a> {
|
|||
|
||||
let length = trace.path.len();
|
||||
trace = self.undo_path(trace, length - prefix_length)?;
|
||||
self.path(trace, &path[prefix_length..])
|
||||
self.path(trace, &path[prefix_length..], width)
|
||||
}
|
||||
|
||||
pub fn path(&mut self, mut trace: Trace, path: &[VertexIndex]) -> Result<Trace, ()> {
|
||||
pub fn path(
|
||||
&mut self,
|
||||
mut trace: Trace,
|
||||
path: &[VertexIndex],
|
||||
width: f64,
|
||||
) -> Result<Trace, ()> {
|
||||
for vertex in path {
|
||||
trace = self.step(trace, *vertex)?;
|
||||
trace = self.step(trace, *vertex, width)?;
|
||||
}
|
||||
Ok(trace)
|
||||
}
|
||||
|
|
@ -71,9 +78,8 @@ impl<'a> Route<'a> {
|
|||
Ok(trace)
|
||||
}
|
||||
|
||||
pub fn step(&mut self, mut trace: Trace, to: VertexIndex) -> Result<Trace, ()> {
|
||||
pub fn step(&mut self, mut trace: Trace, to: VertexIndex, width: f64) -> Result<Trace, ()> {
|
||||
let to_dot = self.mesh.dot(to);
|
||||
let width = self.width;
|
||||
trace.head = self
|
||||
.draw()
|
||||
.segbend_around_dot(trace.head, to_dot, true, width)?;
|
||||
|
|
|
|||
|
|
@ -54,12 +54,12 @@ impl Router {
|
|||
.map(|vertex| self.mesh.dot(*vertex))
|
||||
.collect();*/
|
||||
|
||||
let mut trace = self.route(&mesh, 5.0).start(path[0]);
|
||||
let mut trace = self.route(&mesh).start(path[0]);
|
||||
trace = self
|
||||
.route(&mesh, 5.0)
|
||||
.path(trace, &path[1..(path.len() - 1)])
|
||||
.route(&mesh)
|
||||
.path(trace, &path[1..(path.len() - 1)], 5.0)
|
||||
.unwrap(); // TODO.
|
||||
let _ = self.route(&mesh, 5.0).finish(trace, path[path.len() - 1]);
|
||||
let _ = self.route(&mesh).finish(trace, path[path.len() - 1], 5.0);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -176,8 +176,8 @@ impl Router {
|
|||
Ok(())
|
||||
}*/
|
||||
|
||||
pub fn route<'a>(&'a mut self, mesh: &'a Mesh, width: f64) -> Route {
|
||||
Route::new(&mut self.layout, &self.rules, mesh, width)
|
||||
pub fn route<'a>(&'a mut self, mesh: &'a Mesh) -> Route {
|
||||
Route::new(&mut self.layout, &self.rules, mesh)
|
||||
}
|
||||
|
||||
/*pub fn routeedges(&self) -> impl Iterator<Item = (Point, Point)> + '_ {
|
||||
|
|
|
|||
Loading…
Reference in New Issue