From 8e4369163a7b2c81227e50b0adb2a13b2f327e4f Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Tue, 28 Mar 2023 08:49:46 -0500 Subject: [PATCH] Truncate coordinates rather than using floor. --- src/core.rs | 10 +++++----- src/exploration.rs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core.rs b/src/core.rs index 29e4223..4ab55b5 100644 --- a/src/core.rs +++ b/src/core.rs @@ -298,11 +298,11 @@ pub trait PointLike { fn y(&self) -> f32; fn x_i32(&self) -> i32 { - self.x().round() as i32 + self.x().trunc() as i32 } fn y_i32(&self) -> i32 { - self.y().round() as i32 + self.y().trunc() as i32 } fn x_usize(&self) -> usize { @@ -321,12 +321,12 @@ pub trait PointLike { (self.x_i32(), self.y_i32()) } - fn floor(&self) -> (f32, f32) { - (self.x().floor(), self.y().floor()) + fn trunc(&self) -> (f32, f32) { + (self.x().trunc(), self.y().trunc()) } fn to_index(&self, width: usize) -> usize { - ((self.y_i32() * width as i32) + self.x_i32()) as usize + (self.y_usize() * width) + self.x_usize() } fn distance_squared(&self, other: &dyn PointLike) -> f32 { diff --git a/src/exploration.rs b/src/exploration.rs index b79a6b6..f4e7453 100644 --- a/src/exploration.rs +++ b/src/exploration.rs @@ -132,7 +132,7 @@ where let mut features = features .iter() .filter(|v| visible_entities.contains(&v.0)) - .map(|v| (v.1.floor(), v.2)) + .map(|v| (v.1.trunc(), v.2)) .collect::>(); if features.is_empty() { tts.speak("Nothing visible.", true)?; @@ -166,7 +166,7 @@ where if let Some((coordinates, _)) = target { commands .entity(entity) - .insert(Exploring(coordinates.floor())); + .insert(Exploring(coordinates.trunc())); } } Ok(()) @@ -291,7 +291,7 @@ where MapData: 'static + Clone + Default + Send + Sync, { if let Ok((coordinates, exploring, viewshed)) = explorer.get_single() { - let coordinates = coordinates.floor(); + let coordinates = coordinates.trunc(); let point = **exploring; let shape = Collider::cuboid(0.5 - f32::EPSILON, 0.5 - f32::EPSILON); let (known, idx) = if let Ok((map, revealed_tiles)) = map.get_single() {