mirror of https://codeberg.org/topola/topola.git
refactor(NavcordStepper): struct already stores 'width', don't pass it as argument
This commit is contained in:
parent
cf36177097
commit
ba8aa2fe5a
|
|
@ -60,19 +60,16 @@ impl NavcordStepper {
|
|||
navmesh: &Navmesh,
|
||||
head: Head,
|
||||
around: NavvertexIndex,
|
||||
width: f64,
|
||||
) -> Result<CaneHead, NavcorderException> {
|
||||
let cw = self
|
||||
.maybe_cw(navmesh, around)
|
||||
.ok_or(NavcorderException::CannotWrap)?;
|
||||
let cw = Self::maybe_cw(navmesh, around).ok_or(NavcorderException::CannotWrap)?;
|
||||
|
||||
match self.binavvertex(navmesh, around) {
|
||||
match Self::binavvertex(navmesh, around) {
|
||||
BinavvertexNodeIndex::FixedDot(dot) => {
|
||||
self.wrap_around_fixed_dot(layout, head, dot, cw, width)
|
||||
self.wrap_around_fixed_dot(layout, head, dot, cw)
|
||||
}
|
||||
BinavvertexNodeIndex::FixedBend(_fixed_bend) => todo!(),
|
||||
BinavvertexNodeIndex::LooseBend(loose_bend) => {
|
||||
self.wrap_around_loose_bend(layout, head, loose_bend, cw, width)
|
||||
self.wrap_around_loose_bend(layout, head, loose_bend, cw)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -83,9 +80,8 @@ impl NavcordStepper {
|
|||
head: Head,
|
||||
around: FixedDotIndex,
|
||||
cw: bool,
|
||||
width: f64,
|
||||
) -> Result<CaneHead, NavcorderException> {
|
||||
Ok(layout.cane_around_dot(&mut self.recorder, head, around, cw, width)?)
|
||||
Ok(layout.cane_around_dot(&mut self.recorder, head, around, cw, self.width)?)
|
||||
}
|
||||
|
||||
fn wrap_around_loose_bend(
|
||||
|
|
@ -94,20 +90,15 @@ impl NavcordStepper {
|
|||
head: Head,
|
||||
around: LooseBendIndex,
|
||||
cw: bool,
|
||||
width: f64,
|
||||
) -> Result<CaneHead, NavcorderException> {
|
||||
Ok(layout.cane_around_bend(&mut self.recorder, head, around.into(), cw, width)?)
|
||||
Ok(layout.cane_around_bend(&mut self.recorder, head, around.into(), cw, self.width)?)
|
||||
}
|
||||
|
||||
fn binavvertex(&self, navmesh: &Navmesh, navvertex: NavvertexIndex) -> BinavvertexNodeIndex {
|
||||
fn binavvertex(navmesh: &Navmesh, navvertex: NavvertexIndex) -> BinavvertexNodeIndex {
|
||||
navmesh.node_weight(navvertex).unwrap().node
|
||||
}
|
||||
|
||||
fn primitive(&self, navmesh: &Navmesh, navvertex: NavvertexIndex) -> PrimitiveIndex {
|
||||
self.binavvertex(navmesh, navvertex).into()
|
||||
}
|
||||
|
||||
fn maybe_cw(&self, navmesh: &Navmesh, navvertex: NavvertexIndex) -> Option<bool> {
|
||||
fn maybe_cw(navmesh: &Navmesh, navvertex: NavvertexIndex) -> Option<bool> {
|
||||
navmesh.node_weight(navvertex).unwrap().maybe_cw
|
||||
}
|
||||
}
|
||||
|
|
@ -116,7 +107,6 @@ pub struct NavcordStepContext<'a, R> {
|
|||
pub layout: &'a mut Layout<R>,
|
||||
pub navmesh: &'a Navmesh,
|
||||
pub to: NavvertexIndex,
|
||||
pub width: f64,
|
||||
}
|
||||
|
||||
impl NavcordStepper {
|
||||
|
|
@ -128,13 +118,7 @@ impl NavcordStepper {
|
|||
input: &mut NavcordStepContext<'_, R>,
|
||||
) -> Result<(), NavcorderException> {
|
||||
self.head = self
|
||||
.wrap(
|
||||
input.layout,
|
||||
input.navmesh,
|
||||
self.head,
|
||||
input.to,
|
||||
input.width,
|
||||
)?
|
||||
.wrap(input.layout, input.navmesh, self.head, input.to)?
|
||||
.into();
|
||||
self.path.push(input.to);
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ pub trait Navcorder {
|
|||
_navmesh: &Navmesh,
|
||||
navcord: &mut NavcordStepper,
|
||||
target: FixedDotIndex,
|
||||
width: f64,
|
||||
) -> Result<BandTermsegIndex, NavcorderException>;
|
||||
|
||||
fn rework_path(
|
||||
|
|
@ -46,7 +45,6 @@ pub trait Navcorder {
|
|||
navmesh: &Navmesh,
|
||||
navcord: &mut NavcordStepper,
|
||||
path: &[NavvertexIndex],
|
||||
width: f64,
|
||||
) -> Result<(), NavcorderException>;
|
||||
|
||||
fn path(
|
||||
|
|
@ -54,7 +52,6 @@ pub trait Navcorder {
|
|||
navmesh: &Navmesh,
|
||||
navcord: &mut NavcordStepper,
|
||||
path: &[NavvertexIndex],
|
||||
width: f64,
|
||||
) -> Result<(), NavcorderException>;
|
||||
|
||||
fn undo_path(&mut self, navcord: &mut NavcordStepper, step_count: usize);
|
||||
|
|
@ -76,9 +73,8 @@ impl<R: AccessRules> Navcorder for Layout<R> {
|
|||
_navmesh: &Navmesh,
|
||||
navcord: &mut NavcordStepper,
|
||||
target: FixedDotIndex,
|
||||
width: f64,
|
||||
) -> Result<BandTermsegIndex, NavcorderException> {
|
||||
Ok(self.finish_in_dot(&mut navcord.recorder, navcord.head, target, width)?)
|
||||
Ok(self.finish_in_dot(&mut navcord.recorder, navcord.head, target, navcord.width)?)
|
||||
}
|
||||
|
||||
#[debug_requires(path[0] == navcord.path[0])]
|
||||
|
|
@ -88,7 +84,6 @@ impl<R: AccessRules> Navcorder for Layout<R> {
|
|||
navmesh: &Navmesh,
|
||||
navcord: &mut NavcordStepper,
|
||||
path: &[NavvertexIndex],
|
||||
width: f64,
|
||||
) -> Result<(), NavcorderException> {
|
||||
let prefix_length = navcord
|
||||
.path
|
||||
|
|
@ -99,7 +94,7 @@ impl<R: AccessRules> Navcorder for Layout<R> {
|
|||
|
||||
let length = navcord.path.len();
|
||||
self.undo_path(navcord, length - prefix_length);
|
||||
self.path(navmesh, navcord, &path[prefix_length..], width)
|
||||
self.path(navmesh, navcord, &path[prefix_length..])
|
||||
}
|
||||
|
||||
#[debug_ensures(ret.is_ok() -> navcord.path.len() == old(navcord.path.len() + path.len()))]
|
||||
|
|
@ -108,14 +103,12 @@ impl<R: AccessRules> Navcorder for Layout<R> {
|
|||
navmesh: &Navmesh,
|
||||
navcord: &mut NavcordStepper,
|
||||
path: &[NavvertexIndex],
|
||||
width: f64,
|
||||
) -> Result<(), NavcorderException> {
|
||||
for (i, vertex) in path.iter().enumerate() {
|
||||
if let Err(err) = navcord.step(&mut NavcordStepContext {
|
||||
layout: self,
|
||||
navmesh,
|
||||
to: *vertex,
|
||||
width,
|
||||
}) {
|
||||
self.undo_path(navcord, i);
|
||||
return Err(err);
|
||||
|
|
|
|||
|
|
@ -91,15 +91,12 @@ impl<'a, R: AccessRules> AstarStrategy<Navmesh, f64, BandTermsegIndex>
|
|||
tracker: &PathTracker<Navmesh>,
|
||||
) -> Option<BandTermsegIndex> {
|
||||
let new_path = tracker.reconstruct_path_to(vertex);
|
||||
let width = self.navcord.width;
|
||||
|
||||
self.layout
|
||||
.rework_path(navmesh, self.navcord, &new_path[..], width)
|
||||
.rework_path(navmesh, self.navcord, &new_path[..])
|
||||
.unwrap();
|
||||
|
||||
self.layout
|
||||
.finish(navmesh, self.navcord, self.target, width)
|
||||
.ok()
|
||||
self.layout.finish(navmesh, self.navcord, self.target).ok()
|
||||
}
|
||||
|
||||
fn place_probe(&mut self, navmesh: &Navmesh, edge: NavmeshEdgeReference) -> Option<f64> {
|
||||
|
|
@ -109,12 +106,10 @@ impl<'a, R: AccessRules> AstarStrategy<Navmesh, f64, BandTermsegIndex>
|
|||
|
||||
let prev_bihead_length = self.bihead_length();
|
||||
|
||||
let width = self.navcord.width;
|
||||
let result = self.navcord.step(&mut NavcordStepContext {
|
||||
layout: self.layout,
|
||||
navmesh,
|
||||
to: edge.target(),
|
||||
width,
|
||||
});
|
||||
|
||||
let probe_length = self.bihead_length() - prev_bihead_length;
|
||||
|
|
|
|||
Loading…
Reference in New Issue