From 41fb64cea0c549107552ef135737258d4d208a5b Mon Sep 17 00:00:00 2001 From: Shane Pearman Date: Sun, 25 Jul 2021 04:25:25 -0700 Subject: [PATCH] Remove NumCast bound from BaseNum --- src/num.rs | 4 +--- src/structure.rs | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/num.rs b/src/num.rs index 3278721..fe2b84b 100644 --- a/src/num.rs +++ b/src/num.rs @@ -18,7 +18,7 @@ use approx; use std::fmt; use std::ops::*; -use num_traits::{Float, Num, NumCast}; +use num_traits::{Float, Num}; /// Base numeric types with partial ordering pub trait BaseNum: @@ -26,7 +26,6 @@ pub trait BaseNum: + Clone + fmt::Debug + Num - + NumCast + PartialOrd + AddAssign + SubAssign @@ -41,7 +40,6 @@ impl BaseNum for T where + Clone + fmt::Debug + Num - + NumCast + PartialOrd + AddAssign + SubAssign diff --git a/src/structure.rs b/src/structure.rs index 9344814..06e08cb 100644 --- a/src/structure.rs +++ b/src/structure.rs @@ -25,7 +25,7 @@ use approx; use angle::Rad; use num::{BaseFloat, BaseNum}; -pub use num_traits::{Bounded, One, Zero}; +pub use num_traits::{Bounded, NumCast, One, Zero}; /// An array containing elements of type `Element` pub trait Array @@ -388,7 +388,7 @@ where /// ``` #[inline] fn midpoint(self, other: Self) -> Self { - self + (other - self) / cast(2).unwrap() + self + (other - self) / (Self::Scalar::one() + Self::Scalar::one()) } /// Returns the average position of all points in the slice. @@ -406,7 +406,7 @@ where /// let centroid = Point2::centroid(&triangle); /// ``` #[inline] - fn centroid(points: &[Self]) -> Self { + fn centroid(points: &[Self]) -> Self where Self::Scalar: NumCast { let total_displacement = points .iter() .fold(Self::Diff::zero(), |acc, p| acc + p.to_vec());