From 480e3cc6a5fbde3409df1836294d85a405d89c35 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Wed, 18 May 2022 10:28:19 -0500 Subject: [PATCH] Consistently convert coordinates. --- src/core.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core.rs b/src/core.rs index 28918c9..18c7f80 100644 --- a/src/core.rs +++ b/src/core.rs @@ -222,19 +222,19 @@ pub trait PointLike { fn y(&self) -> f32; fn x_i32(&self) -> i32 { - self.x() as i32 + self.x().trunc() as i32 } fn y_i32(&self) -> i32 { - self.y() as i32 + self.y().trunc() as i32 } fn x_usize(&self) -> usize { - self.x() as usize + self.x().trunc() as usize } fn y_usize(&self) -> usize { - self.y() as usize + self.y().trunc() as usize } fn f32(&self) -> (f32, f32) { @@ -248,6 +248,7 @@ pub trait PointLike { fn floor(&self) -> (f32, f32) { (self.x().floor(), self.y().floor()) } + fn to_index(&self, width: usize) -> usize { ((self.y_i32() * width as i32) + self.x_i32()) as usize }