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,
|
navmesh: &Navmesh,
|
||||||
head: Head,
|
head: Head,
|
||||||
around: NavvertexIndex,
|
around: NavvertexIndex,
|
||||||
width: f64,
|
|
||||||
) -> Result<CaneHead, NavcorderException> {
|
) -> Result<CaneHead, NavcorderException> {
|
||||||
let cw = self
|
let cw = Self::maybe_cw(navmesh, around).ok_or(NavcorderException::CannotWrap)?;
|
||||||
.maybe_cw(navmesh, around)
|
|
||||||
.ok_or(NavcorderException::CannotWrap)?;
|
|
||||||
|
|
||||||
match self.binavvertex(navmesh, around) {
|
match Self::binavvertex(navmesh, around) {
|
||||||
BinavvertexNodeIndex::FixedDot(dot) => {
|
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::FixedBend(_fixed_bend) => todo!(),
|
||||||
BinavvertexNodeIndex::LooseBend(loose_bend) => {
|
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,
|
head: Head,
|
||||||
around: FixedDotIndex,
|
around: FixedDotIndex,
|
||||||
cw: bool,
|
cw: bool,
|
||||||
width: f64,
|
|
||||||
) -> Result<CaneHead, NavcorderException> {
|
) -> 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(
|
fn wrap_around_loose_bend(
|
||||||
|
|
@ -94,20 +90,15 @@ impl NavcordStepper {
|
||||||
head: Head,
|
head: Head,
|
||||||
around: LooseBendIndex,
|
around: LooseBendIndex,
|
||||||
cw: bool,
|
cw: bool,
|
||||||
width: f64,
|
|
||||||
) -> Result<CaneHead, NavcorderException> {
|
) -> 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
|
navmesh.node_weight(navvertex).unwrap().node
|
||||||
}
|
}
|
||||||
|
|
||||||
fn primitive(&self, navmesh: &Navmesh, navvertex: NavvertexIndex) -> PrimitiveIndex {
|
fn maybe_cw(navmesh: &Navmesh, navvertex: NavvertexIndex) -> Option<bool> {
|
||||||
self.binavvertex(navmesh, navvertex).into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn maybe_cw(&self, navmesh: &Navmesh, navvertex: NavvertexIndex) -> Option<bool> {
|
|
||||||
navmesh.node_weight(navvertex).unwrap().maybe_cw
|
navmesh.node_weight(navvertex).unwrap().maybe_cw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -116,7 +107,6 @@ pub struct NavcordStepContext<'a, R> {
|
||||||
pub layout: &'a mut Layout<R>,
|
pub layout: &'a mut Layout<R>,
|
||||||
pub navmesh: &'a Navmesh,
|
pub navmesh: &'a Navmesh,
|
||||||
pub to: NavvertexIndex,
|
pub to: NavvertexIndex,
|
||||||
pub width: f64,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NavcordStepper {
|
impl NavcordStepper {
|
||||||
|
|
@ -128,13 +118,7 @@ impl NavcordStepper {
|
||||||
input: &mut NavcordStepContext<'_, R>,
|
input: &mut NavcordStepContext<'_, R>,
|
||||||
) -> Result<(), NavcorderException> {
|
) -> Result<(), NavcorderException> {
|
||||||
self.head = self
|
self.head = self
|
||||||
.wrap(
|
.wrap(input.layout, input.navmesh, self.head, input.to)?
|
||||||
input.layout,
|
|
||||||
input.navmesh,
|
|
||||||
self.head,
|
|
||||||
input.to,
|
|
||||||
input.width,
|
|
||||||
)?
|
|
||||||
.into();
|
.into();
|
||||||
self.path.push(input.to);
|
self.path.push(input.to);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,6 @@ pub trait Navcorder {
|
||||||
_navmesh: &Navmesh,
|
_navmesh: &Navmesh,
|
||||||
navcord: &mut NavcordStepper,
|
navcord: &mut NavcordStepper,
|
||||||
target: FixedDotIndex,
|
target: FixedDotIndex,
|
||||||
width: f64,
|
|
||||||
) -> Result<BandTermsegIndex, NavcorderException>;
|
) -> Result<BandTermsegIndex, NavcorderException>;
|
||||||
|
|
||||||
fn rework_path(
|
fn rework_path(
|
||||||
|
|
@ -46,7 +45,6 @@ pub trait Navcorder {
|
||||||
navmesh: &Navmesh,
|
navmesh: &Navmesh,
|
||||||
navcord: &mut NavcordStepper,
|
navcord: &mut NavcordStepper,
|
||||||
path: &[NavvertexIndex],
|
path: &[NavvertexIndex],
|
||||||
width: f64,
|
|
||||||
) -> Result<(), NavcorderException>;
|
) -> Result<(), NavcorderException>;
|
||||||
|
|
||||||
fn path(
|
fn path(
|
||||||
|
|
@ -54,7 +52,6 @@ pub trait Navcorder {
|
||||||
navmesh: &Navmesh,
|
navmesh: &Navmesh,
|
||||||
navcord: &mut NavcordStepper,
|
navcord: &mut NavcordStepper,
|
||||||
path: &[NavvertexIndex],
|
path: &[NavvertexIndex],
|
||||||
width: f64,
|
|
||||||
) -> Result<(), NavcorderException>;
|
) -> Result<(), NavcorderException>;
|
||||||
|
|
||||||
fn undo_path(&mut self, navcord: &mut NavcordStepper, step_count: usize);
|
fn undo_path(&mut self, navcord: &mut NavcordStepper, step_count: usize);
|
||||||
|
|
@ -76,9 +73,8 @@ impl<R: AccessRules> Navcorder for Layout<R> {
|
||||||
_navmesh: &Navmesh,
|
_navmesh: &Navmesh,
|
||||||
navcord: &mut NavcordStepper,
|
navcord: &mut NavcordStepper,
|
||||||
target: FixedDotIndex,
|
target: FixedDotIndex,
|
||||||
width: f64,
|
|
||||||
) -> Result<BandTermsegIndex, NavcorderException> {
|
) -> 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])]
|
#[debug_requires(path[0] == navcord.path[0])]
|
||||||
|
|
@ -88,7 +84,6 @@ impl<R: AccessRules> Navcorder for Layout<R> {
|
||||||
navmesh: &Navmesh,
|
navmesh: &Navmesh,
|
||||||
navcord: &mut NavcordStepper,
|
navcord: &mut NavcordStepper,
|
||||||
path: &[NavvertexIndex],
|
path: &[NavvertexIndex],
|
||||||
width: f64,
|
|
||||||
) -> Result<(), NavcorderException> {
|
) -> Result<(), NavcorderException> {
|
||||||
let prefix_length = navcord
|
let prefix_length = navcord
|
||||||
.path
|
.path
|
||||||
|
|
@ -99,7 +94,7 @@ impl<R: AccessRules> Navcorder for Layout<R> {
|
||||||
|
|
||||||
let length = navcord.path.len();
|
let length = navcord.path.len();
|
||||||
self.undo_path(navcord, length - prefix_length);
|
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()))]
|
#[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,
|
navmesh: &Navmesh,
|
||||||
navcord: &mut NavcordStepper,
|
navcord: &mut NavcordStepper,
|
||||||
path: &[NavvertexIndex],
|
path: &[NavvertexIndex],
|
||||||
width: f64,
|
|
||||||
) -> Result<(), NavcorderException> {
|
) -> Result<(), NavcorderException> {
|
||||||
for (i, vertex) in path.iter().enumerate() {
|
for (i, vertex) in path.iter().enumerate() {
|
||||||
if let Err(err) = navcord.step(&mut NavcordStepContext {
|
if let Err(err) = navcord.step(&mut NavcordStepContext {
|
||||||
layout: self,
|
layout: self,
|
||||||
navmesh,
|
navmesh,
|
||||||
to: *vertex,
|
to: *vertex,
|
||||||
width,
|
|
||||||
}) {
|
}) {
|
||||||
self.undo_path(navcord, i);
|
self.undo_path(navcord, i);
|
||||||
return Err(err);
|
return Err(err);
|
||||||
|
|
|
||||||
|
|
@ -91,15 +91,12 @@ impl<'a, R: AccessRules> AstarStrategy<Navmesh, f64, BandTermsegIndex>
|
||||||
tracker: &PathTracker<Navmesh>,
|
tracker: &PathTracker<Navmesh>,
|
||||||
) -> Option<BandTermsegIndex> {
|
) -> Option<BandTermsegIndex> {
|
||||||
let new_path = tracker.reconstruct_path_to(vertex);
|
let new_path = tracker.reconstruct_path_to(vertex);
|
||||||
let width = self.navcord.width;
|
|
||||||
|
|
||||||
self.layout
|
self.layout
|
||||||
.rework_path(navmesh, self.navcord, &new_path[..], width)
|
.rework_path(navmesh, self.navcord, &new_path[..])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
self.layout
|
self.layout.finish(navmesh, self.navcord, self.target).ok()
|
||||||
.finish(navmesh, self.navcord, self.target, width)
|
|
||||||
.ok()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn place_probe(&mut self, navmesh: &Navmesh, edge: NavmeshEdgeReference) -> Option<f64> {
|
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 prev_bihead_length = self.bihead_length();
|
||||||
|
|
||||||
let width = self.navcord.width;
|
|
||||||
let result = self.navcord.step(&mut NavcordStepContext {
|
let result = self.navcord.step(&mut NavcordStepContext {
|
||||||
layout: self.layout,
|
layout: self.layout,
|
||||||
navmesh,
|
navmesh,
|
||||||
to: edge.target(),
|
to: edge.target(),
|
||||||
width,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let probe_length = self.bihead_length() - prev_bihead_length;
|
let probe_length = self.bihead_length() - prev_bihead_length;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue