mirror of https://codeberg.org/topola/topola.git
router: don't panic if wraparound navvertex has no cw
This may happen if target's guidecircle is in line of sight but its center is not.
This commit is contained in:
parent
3ce8cfcabc
commit
b6cfcc8518
|
|
@ -1,5 +1,6 @@
|
||||||
use contracts::{debug_ensures, debug_requires};
|
use contracts::{debug_ensures, debug_requires};
|
||||||
use petgraph::graph::{NodeIndex, UnGraph};
|
use petgraph::graph::{NodeIndex, UnGraph};
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
drawing::{
|
drawing::{
|
||||||
|
|
@ -17,6 +18,14 @@ use crate::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Error, Debug, Clone, Copy)]
|
||||||
|
pub enum TracerException {
|
||||||
|
#[error(transparent)]
|
||||||
|
CannotDraw(#[from] DrawException),
|
||||||
|
#[error("cannot wrap")]
|
||||||
|
CannotWrap,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Trace {
|
pub struct Trace {
|
||||||
pub path: Vec<NodeIndex<usize>>,
|
pub path: Vec<NodeIndex<usize>>,
|
||||||
|
|
@ -54,8 +63,8 @@ impl<'a, R: RulesTrait> Tracer<'a, R> {
|
||||||
trace: &mut Trace,
|
trace: &mut Trace,
|
||||||
target: FixedDotIndex,
|
target: FixedDotIndex,
|
||||||
width: f64,
|
width: f64,
|
||||||
) -> Result<BandFirstSegIndex, DrawException> {
|
) -> Result<BandFirstSegIndex, TracerException> {
|
||||||
Draw::new(self.layout).finish_in_dot(trace.head, target, width)
|
Ok(Draw::new(self.layout).finish_in_dot(trace.head, target, width)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[debug_requires(path[0] == trace.path[0])]
|
#[debug_requires(path[0] == trace.path[0])]
|
||||||
|
|
@ -66,7 +75,7 @@ impl<'a, R: RulesTrait> Tracer<'a, R> {
|
||||||
trace: &mut Trace,
|
trace: &mut Trace,
|
||||||
path: &[NodeIndex<usize>],
|
path: &[NodeIndex<usize>],
|
||||||
width: f64,
|
width: f64,
|
||||||
) -> Result<(), DrawException> {
|
) -> Result<(), TracerException> {
|
||||||
let prefix_length = trace
|
let prefix_length = trace
|
||||||
.path
|
.path
|
||||||
.iter()
|
.iter()
|
||||||
|
|
@ -76,7 +85,7 @@ impl<'a, R: RulesTrait> Tracer<'a, R> {
|
||||||
|
|
||||||
let length = trace.path.len();
|
let length = trace.path.len();
|
||||||
self.undo_path(graph, trace, length - prefix_length);
|
self.undo_path(graph, trace, length - prefix_length);
|
||||||
self.path(graph, trace, &path[prefix_length..], width)
|
Ok::<(), TracerException>(self.path(graph, trace, &path[prefix_length..], width)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[debug_ensures(ret.is_ok() -> trace.path.len() == old(trace.path.len() + path.len()))]
|
#[debug_ensures(ret.is_ok() -> trace.path.len() == old(trace.path.len() + path.len()))]
|
||||||
|
|
@ -86,11 +95,11 @@ impl<'a, R: RulesTrait> Tracer<'a, R> {
|
||||||
trace: &mut Trace,
|
trace: &mut Trace,
|
||||||
path: &[NodeIndex<usize>],
|
path: &[NodeIndex<usize>],
|
||||||
width: f64,
|
width: f64,
|
||||||
) -> Result<(), DrawException> {
|
) -> Result<(), TracerException> {
|
||||||
for (i, vertex) in path.iter().enumerate() {
|
for (i, vertex) in path.iter().enumerate() {
|
||||||
if let Err(err) = self.step(graph, trace, *vertex, width) {
|
if let Err(err) = self.step(graph, trace, *vertex, width) {
|
||||||
self.undo_path(graph, trace, i);
|
self.undo_path(graph, trace, i);
|
||||||
return Err(err);
|
return Err(err.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,11 +127,11 @@ impl<'a, R: RulesTrait> Tracer<'a, R> {
|
||||||
trace: &mut Trace,
|
trace: &mut Trace,
|
||||||
to: NodeIndex<usize>,
|
to: NodeIndex<usize>,
|
||||||
width: f64,
|
width: f64,
|
||||||
) -> Result<(), DrawException> {
|
) -> Result<(), TracerException> {
|
||||||
trace.head = self.wrap(graph, trace.head, to, width)?.into();
|
trace.head = self.wrap(graph, trace.head, to, width)?.into();
|
||||||
trace.path.push(to);
|
trace.path.push(to);
|
||||||
|
|
||||||
Ok::<(), DrawException>(())
|
Ok::<(), TracerException>(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wrap(
|
fn wrap(
|
||||||
|
|
@ -131,8 +140,10 @@ impl<'a, R: RulesTrait> Tracer<'a, R> {
|
||||||
head: Head,
|
head: Head,
|
||||||
around: NodeIndex<usize>,
|
around: NodeIndex<usize>,
|
||||||
width: f64,
|
width: f64,
|
||||||
) -> Result<CaneHead, DrawException> {
|
) -> Result<CaneHead, TracerException> {
|
||||||
let cw = self.maybe_cw(graph, around).unwrap();
|
let cw = self
|
||||||
|
.maybe_cw(graph, around)
|
||||||
|
.ok_or(TracerException::CannotWrap)?;
|
||||||
|
|
||||||
match self.binavvertex(graph, around) {
|
match self.binavvertex(graph, around) {
|
||||||
BinavvertexNodeIndex::FixedDot(dot) => {
|
BinavvertexNodeIndex::FixedDot(dot) => {
|
||||||
|
|
@ -152,9 +163,8 @@ impl<'a, R: RulesTrait> Tracer<'a, R> {
|
||||||
around: FixedDotIndex,
|
around: FixedDotIndex,
|
||||||
cw: bool,
|
cw: bool,
|
||||||
width: f64,
|
width: f64,
|
||||||
) -> Result<CaneHead, DrawException> {
|
) -> Result<CaneHead, TracerException> {
|
||||||
let head = Draw::new(self.layout).cane_around_dot(head, around.into(), cw, width)?;
|
Ok(Draw::new(self.layout).cane_around_dot(head, around.into(), cw, width)?)
|
||||||
Ok(head)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wrap_around_loose_bend(
|
fn wrap_around_loose_bend(
|
||||||
|
|
@ -164,10 +174,8 @@ impl<'a, R: RulesTrait> Tracer<'a, R> {
|
||||||
around: LooseBendIndex,
|
around: LooseBendIndex,
|
||||||
cw: bool,
|
cw: bool,
|
||||||
width: f64,
|
width: f64,
|
||||||
) -> Result<CaneHead, DrawException> {
|
) -> Result<CaneHead, TracerException> {
|
||||||
let head = Draw::new(self.layout).cane_around_bend(head, around.into(), cw, width)?;
|
Ok(Draw::new(self.layout).cane_around_bend(head, around.into(), cw, width)?)
|
||||||
|
|
||||||
Ok(head)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[debug_ensures(trace.path.len() == old(trace.path.len() - 1))]
|
#[debug_ensures(trace.path.len() == old(trace.path.len() - 1))]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue