Further relax InnerSpace and is_finite BaseFloat bounds

This commit is contained in:
Egor Larionov 2020-05-21 12:06:34 -07:00 committed by Dzmitry Malyshau
parent b9e82914db
commit 753773cfcd
3 changed files with 12 additions and 12 deletions

View file

@ -17,7 +17,7 @@
//! distinguishes them from vectors, which have a length and direction, but do //! distinguishes them from vectors, which have a length and direction, but do
//! not have a fixed position. //! not have a fixed position.
use num_traits::{Bounded, NumCast}; use num_traits::{Float, Bounded, NumCast};
use std::fmt; use std::fmt;
use std::mem; use std::mem;
use std::ops::*; use std::ops::*;
@ -135,7 +135,7 @@ macro_rules! impl_point {
fold_array!(mul, { $(self.$field),+ }) fold_array!(mul, { $(self.$field),+ })
} }
fn is_finite(&self) -> bool where S: BaseFloat { fn is_finite(&self) -> bool where S: Float {
$(self.$field.is_finite())&&+ $(self.$field.is_finite())&&+
} }
} }

View file

@ -91,7 +91,7 @@ where
/// Whether all elements of the array are finite /// Whether all elements of the array are finite
fn is_finite(&self) -> bool fn is_finite(&self) -> bool
where where
Self::Element: BaseFloat; Self::Element: Float;
} }
/// Element-wise arithmetic operations. These are supplied for pragmatic /// Element-wise arithmetic operations. These are supplied for pragmatic

View file

@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use num_traits::{Bounded, NumCast}; use num_traits::{Float, Bounded, NumCast};
#[cfg(feature = "rand")] #[cfg(feature = "rand")]
use rand::{ use rand::{
distributions::{Distribution, Standard}, distributions::{Distribution, Standard},
@ -139,7 +139,7 @@ macro_rules! impl_vector {
} }
} }
impl<S: BaseFloat> MetricSpace for $VectorN<S> { impl<S: BaseNum + Float> MetricSpace for $VectorN<S> {
type Metric = S; type Metric = S;
#[inline] #[inline]
@ -171,7 +171,7 @@ macro_rules! impl_vector {
fold_array!(mul, { $(self.$field),+ }) fold_array!(mul, { $(self.$field),+ })
} }
fn is_finite(&self) -> bool where S: BaseFloat { fn is_finite(&self) -> bool where S: Float {
$(self.$field.is_finite())&&+ $(self.$field.is_finite())&&+
} }
} }
@ -525,38 +525,38 @@ where
V::dot(a, b) V::dot(a, b)
} }
impl<S: BaseFloat> InnerSpace for Vector1<S> { impl<S: BaseNum + Float> InnerSpace for Vector1<S> {
#[inline] #[inline]
fn dot(self, other: Vector1<S>) -> S { fn dot(self, other: Vector1<S>) -> S {
Vector1::mul_element_wise(self, other).sum() Vector1::mul_element_wise(self, other).sum()
} }
} }
impl<S: BaseFloat> InnerSpace for Vector2<S> { impl<S: BaseNum + Float> InnerSpace for Vector2<S> {
#[inline] #[inline]
fn dot(self, other: Vector2<S>) -> S { fn dot(self, other: Vector2<S>) -> S {
Vector2::mul_element_wise(self, other).sum() Vector2::mul_element_wise(self, other).sum()
} }
#[inline] #[inline]
fn angle(self, other: Vector2<S>) -> Rad<S> { fn angle(self, other: Vector2<S>) -> Rad<S> where S: BaseFloat {
Rad::atan2(Self::perp_dot(self, other), Self::dot(self, other)) Rad::atan2(Self::perp_dot(self, other), Self::dot(self, other))
} }
} }
impl<S: BaseFloat> InnerSpace for Vector3<S> { impl<S: BaseNum + Float> InnerSpace for Vector3<S> {
#[inline] #[inline]
fn dot(self, other: Vector3<S>) -> S { fn dot(self, other: Vector3<S>) -> S {
Vector3::mul_element_wise(self, other).sum() Vector3::mul_element_wise(self, other).sum()
} }
#[inline] #[inline]
fn angle(self, other: Vector3<S>) -> Rad<S> { fn angle(self, other: Vector3<S>) -> Rad<S> where S: BaseFloat {
Rad::atan2(self.cross(other).magnitude(), Self::dot(self, other)) Rad::atan2(self.cross(other).magnitude(), Self::dot(self, other))
} }
} }
impl<S: BaseFloat> InnerSpace for Vector4<S> { impl<S: BaseNum + Float> InnerSpace for Vector4<S> {
#[inline] #[inline]
fn dot(self, other: Vector4<S>) -> S { fn dot(self, other: Vector4<S>) -> S {
Vector4::mul_element_wise(self, other).sum() Vector4::mul_element_wise(self, other).sum()