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::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<T> BaseNum for T where
+ Clone
+ fmt::Debug
+ Num
+ NumCast
+ PartialOrd
+ AddAssign
+ SubAssign

View file

@ -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());