diff options
| author | Max Pernklau | 2020-11-29 21:28:39 +0100 |
|---|---|---|
| committer | GitHub | 2020-11-29 21:28:39 +0100 |
| commit | 4f2eab931bed0ec86c6136e365ad3a1b3b8c4e87 (patch) | |
| tree | 010339f867d90c2c6293ddd16c4151ec220c7b8e /src/math/mod.rs | |
| parent | 4d3ee44eb4892bd454a1289f7fed308f82ec6a3b (diff) | |
| parent | 90db142588e1b78250dc9b266bae359cf9e22721 (diff) | |
| download | graf_karto-4f2eab931bed0ec86c6136e365ad3a1b3b8c4e87.tar.gz graf_karto-4f2eab931bed0ec86c6136e365ad3a1b3b8c4e87.zip | |
Merge branch 'master' into wall-join
Diffstat (limited to 'src/math/mod.rs')
| -rw-r--r-- | src/math/mod.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/math/mod.rs b/src/math/mod.rs index b84d270..279affc 100644 --- a/src/math/mod.rs +++ b/src/math/mod.rs @@ -11,6 +11,7 @@ pub use self::triangle::*; pub use self::vec2::*; use nalgebra::Scalar; +use num_traits::Float; use std::cmp::Ordering; /// Trait that describes an area in the vector space on the field of T @@ -31,11 +32,14 @@ pub trait Surface<T: Scalar + Copy> { /// Round a floating point number to the nearest step given by the step argument. For instance, if /// the step is 0.5, then all numbers from 0.0 to 0.24999... will be 0., while all numbers from /// 0.25 to 0.74999... will be 0.5 and so on. -pub fn round(num: f32, step: f32) -> f32 { +pub fn round<T>(num: T, step: T) -> T +where + T: Float, +{ // Only positive steps will be accepted. - assert!(step > 0.); + assert!(step > T::zero()); - let lower_bound = ((num / step) as i32) as f32 * step; + let lower_bound = (num / step).floor() * step; let upper_bound = lower_bound + step; // Compare the distances and prefer the smaller. If they are the same, prefer the upper bound. |
