router: TraceStepper is not a real stepper

Contributes towards solving #82 properly later.
This commit is contained in:
Alain Emilia Anna Zscheile 2024-10-05 23:10:08 +02:00
parent 74ef5e356f
commit 04ab1ce69b
3 changed files with 15 additions and 37 deletions

View File

@ -19,7 +19,6 @@ use crate::{
}, },
graph::{GetPetgraphIndex, MakeRef}, graph::{GetPetgraphIndex, MakeRef},
layout::Layout, layout::Layout,
stepper::{Step, StepBack},
}; };
use super::{ use super::{

View File

@ -1,21 +1,17 @@
use contracts::debug_ensures; use contracts::debug_ensures;
use petgraph::data::DataMap; use petgraph::data::DataMap;
use crate::{ use crate::drawing::{
drawing::{
bend::LooseBendIndex, bend::LooseBendIndex,
dot::FixedDotIndex, dot::FixedDotIndex,
graph::PrimitiveIndex, graph::PrimitiveIndex,
head::{BareHead, CaneHead, Head}, head::{BareHead, CaneHead, Head},
rules::AccessRules, rules::AccessRules,
},
stepper::{Step, StepBack},
}; };
use super::{ use super::{
draw::Draw, draw::Draw,
navmesh::{BinavvertexNodeIndex, Navmesh, NavvertexIndex}, navmesh::{BinavvertexNodeIndex, Navmesh, NavvertexIndex},
tracer::TracerStatus,
tracer::{Tracer, TracerException}, tracer::{Tracer, TracerException},
}; };
@ -104,16 +100,14 @@ pub struct TraceStepContext<'a: 'b, 'b, R: AccessRules> {
pub width: f64, pub width: f64,
} }
impl<'a, 'b, R: AccessRules> Step<TraceStepContext<'a, 'b, R>, TracerStatus, TracerException, ()> impl TraceStepper {
for TraceStepper
{
#[debug_ensures(ret.is_ok() -> matches!(self.head, Head::Cane(..)))] #[debug_ensures(ret.is_ok() -> matches!(self.head, Head::Cane(..)))]
#[debug_ensures(ret.is_ok() -> self.path.len() == old(self.path.len() + 1))] #[debug_ensures(ret.is_ok() -> self.path.len() == old(self.path.len() + 1))]
#[debug_ensures(ret.is_err() -> self.path.len() == old(self.path.len()))] #[debug_ensures(ret.is_err() -> self.path.len() == old(self.path.len()))]
fn step( pub fn step<'a, 'b, R: AccessRules>(
&mut self, &mut self,
input: &mut TraceStepContext<'a, 'b, R>, input: &mut TraceStepContext<'a, 'b, R>,
) -> Result<TracerStatus, TracerException> { ) -> Result<(), TracerException> {
self.head = self self.head = self
.wrap( .wrap(
input.tracer, input.tracer,
@ -125,13 +119,14 @@ impl<'a, 'b, R: AccessRules> Step<TraceStepContext<'a, 'b, R>, TracerStatus, Tra
.into(); .into();
self.path.push(input.to); self.path.push(input.to);
Ok(TracerStatus::Running) Ok(())
} }
}
impl<'a, R: AccessRules> StepBack<Tracer<'a, R>, TracerStatus, TracerException> for TraceStepper {
#[debug_ensures(self.path.len() == old(self.path.len() - 1))] #[debug_ensures(self.path.len() == old(self.path.len() - 1))]
fn step_back(&mut self, tracer: &mut Tracer<'a, R>) -> Result<TracerStatus, TracerException> { pub fn step_back<'a, R: AccessRules>(
&mut self,
tracer: &mut Tracer<'a, R>,
) -> Result<(), TracerException> {
if let Head::Cane(head) = self.head { if let Head::Cane(head) = self.head {
self.head = Draw::new(tracer.layout).undo_cane(head).unwrap(); self.head = Draw::new(tracer.layout).undo_cane(head).unwrap();
} else { } else {
@ -139,6 +134,6 @@ impl<'a, R: AccessRules> StepBack<Tracer<'a, R>, TracerStatus, TracerException>
} }
self.path.pop(); self.path.pop();
Ok(TracerStatus::Running) Ok(())
} }
} }

View File

@ -4,7 +4,6 @@ use thiserror::Error;
use crate::{ use crate::{
drawing::{band::BandTermsegIndex, dot::FixedDotIndex, rules::AccessRules}, drawing::{band::BandTermsegIndex, dot::FixedDotIndex, rules::AccessRules},
layout::Layout, layout::Layout,
stepper::{Step, StepBack},
}; };
use super::{ use super::{
@ -21,21 +20,6 @@ pub enum TracerException {
CannotWrap, CannotWrap,
} }
pub enum TracerStatus {
Running,
Finished,
}
impl TryInto<()> for TracerStatus {
type Error = ();
fn try_into(self) -> Result<(), ()> {
match self {
TracerStatus::Running => Err(()),
TracerStatus::Finished => Ok(()),
}
}
}
#[derive(Debug)] #[derive(Debug)]
pub struct Tracer<'a, R: AccessRules> { pub struct Tracer<'a, R: AccessRules> {
pub layout: &'a mut Layout<R>, pub layout: &'a mut Layout<R>,