Remove NumCast bound from BaseNum

This commit is contained in:
Shane Pearman 2021-07-25 04:25:25 -07:00 committed by Dzmitry Malyshau
parent e57b543449
commit 41fb64cea0
2 changed files with 4 additions and 6 deletions

View file

@ -18,7 +18,7 @@ use approx;
use std::fmt; use std::fmt;
use std::ops::*; use std::ops::*;
use num_traits::{Float, Num, NumCast}; use num_traits::{Float, Num};
/// Base numeric types with partial ordering /// Base numeric types with partial ordering
pub trait BaseNum: pub trait BaseNum:
@ -26,7 +26,6 @@ pub trait BaseNum:
+ Clone + Clone
+ fmt::Debug + fmt::Debug
+ Num + Num
+ NumCast
+ PartialOrd + PartialOrd
+ AddAssign + AddAssign
+ SubAssign + SubAssign
@ -41,7 +40,6 @@ impl<T> BaseNum for T where
+ Clone + Clone
+ fmt::Debug + fmt::Debug
+ Num + Num
+ NumCast
+ PartialOrd + PartialOrd
+ AddAssign + AddAssign
+ SubAssign + SubAssign

View file

@ -25,7 +25,7 @@ use approx;
use angle::Rad; use angle::Rad;
use num::{BaseFloat, BaseNum}; 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` /// An array containing elements of type `Element`
pub trait Array pub trait Array
@ -388,7 +388,7 @@ where
/// ``` /// ```
#[inline] #[inline]
fn midpoint(self, other: Self) -> Self { 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. /// Returns the average position of all points in the slice.
@ -406,7 +406,7 @@ where
/// let centroid = Point2::centroid(&triangle); /// let centroid = Point2::centroid(&triangle);
/// ``` /// ```
#[inline] #[inline]
fn centroid(points: &[Self]) -> Self { fn centroid(points: &[Self]) -> Self where Self::Scalar: NumCast {
let total_displacement = points let total_displacement = points
.iter() .iter()
.fold(Self::Diff::zero(), |acc, p| acc + p.to_vec()); .fold(Self::Diff::zero(), |acc, p| acc + p.to_vec());