clippy fixes

This commit is contained in:
jshipsey 2020-07-05 09:37:58 -04:00
parent 62eb66173f
commit 2c14b2f891
3 changed files with 16 additions and 21 deletions

View File

@ -75,7 +75,7 @@ impl Route {
where where
V: BaseVol<Vox = Block> + ReadVol, V: BaseVol<Vox = Block> + ReadVol,
{ {
let next0 = self.next(0).unwrap_or(pos.map(|e| e.floor() as i32)); let next0 = self.next(0).unwrap_or_else(|| pos.map(|e| e.floor() as i32));
let next1 = self.next(1).unwrap_or(next0); let next1 = self.next(1).unwrap_or(next0);
if vol.get(next0).map(|b| b.is_solid()).unwrap_or(false) { if vol.get(next0).map(|b| b.is_solid()).unwrap_or(false) {
None None
@ -122,14 +122,14 @@ impl Route {
let cb = CubicBezier2 { let cb = CubicBezier2 {
start: pos.xy(), start: pos.xy(),
ctrl0: pos.xy() + vel.xy().try_normalized().unwrap_or(Vec2::zero()), ctrl0: pos.xy() + vel.xy().try_normalized().unwrap_or_else(Vec2::zero),
ctrl1: align(next0), ctrl1: align(next0),
end: align(next1), end: align(next1),
}; };
let tgt2d = cb.evaluate(0.5); let tgt2d = cb.evaluate(0.5);
let tgt = Vec3::from(tgt2d) + Vec3::unit_z() * next_tgt.z; let tgt = Vec3::from(tgt2d) + Vec3::unit_z() * next_tgt.z;
let tgt_dir = (tgt - pos).xy().try_normalized().unwrap_or(Vec2::unit_y()); let tgt_dir = (tgt - pos).xy().try_normalized().unwrap_or_else(Vec2::unit_y);
let next_dir = cb let next_dir = cb
.evaluate_derivative(0.5) .evaluate_derivative(0.5)
.try_normalized() .try_normalized()
@ -144,7 +144,7 @@ impl Route {
Some(( Some((
tgt - pos, tgt - pos,
next_dir next_dir
.dot(vel.xy().try_normalized().unwrap_or(Vec2::zero())) .dot(vel.xy().try_normalized().unwrap_or_else(Vec2::zero))
.max(0.0) .max(0.0)
* 0.75 * 0.75
+ 0.25, + 0.25,
@ -187,21 +187,16 @@ impl Chaser {
let bearing = if let Some(end) = self.route.as_ref().and_then(|r| r.path().end().copied()) { let bearing = if let Some(end) = self.route.as_ref().and_then(|r| r.path().end().copied()) {
let end_to_tgt = end.map(|e| e as f32).distance(tgt); let end_to_tgt = end.map(|e| e as f32).distance(tgt);
if end_to_tgt > pos_to_tgt * 0.3 + 5.0 { if end_to_tgt > pos_to_tgt * 0.3 + 5.0 || thread_rng().gen::<f32>() < 0.005 {
None
} else {
if thread_rng().gen::<f32>() < 0.005 {
// Randomly repath to avoid getting stuck
None None
} else { } else {
self.route self.route
.as_mut() .as_mut()
.and_then(|r| r.traverse(vol, pos, vel, traversal_tolerance)) .and_then(|r| r.traverse(vol, pos, vel, traversal_tolerance))
} }
} } else {
} else {
None None
}; };
// TODO: What happens when we get stuck? // TODO: What happens when we get stuck?
if let Some(bearing) = bearing { if let Some(bearing) = bearing {

View File

@ -10,7 +10,7 @@ impl Animation for RunAnimation {
#[cfg(feature = "use-dyn-lib")] #[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"quadruped_low_run\0"; const UPDATE_FN: &'static [u8] = b"quadruped_low_run\0";
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_low_run")] #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_low_run")]
fn update_skeleton_inner( fn update_skeleton_inner(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,

View File

@ -10,7 +10,7 @@ impl Animation for RunAnimation {
#[cfg(feature = "use-dyn-lib")] #[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"quadruped_medium_run\0"; const UPDATE_FN: &'static [u8] = b"quadruped_medium_run\0";
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_run")] #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_run")]
fn update_skeleton_inner( fn update_skeleton_inner(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,