src/types.rs

branch
dev
changeset 150
c4e394a9c84c
parent 62
d8305c9b6fdf
child 195
93e003c1f0ef
--- a/src/types.rs	Mon Sep 01 00:04:22 2025 -0500
+++ b/src/types.rs	Mon Sep 01 13:51:03 2025 -0500
@@ -10,15 +10,12 @@
 */
 
 //use trait_set::trait_set;
+pub use num_traits::cast::AsPrimitive;
 pub use num_traits::Float as NumTraitsFloat; // needed to re-export functions.
-pub use num_traits::cast::AsPrimitive;
 
 pub use simba::scalar::{
-    ClosedAdd, ClosedAddAssign,
+    ClosedAdd, ClosedAddAssign, ClosedDiv, ClosedDivAssign, ClosedMul, ClosedMulAssign, ClosedNeg,
     ClosedSub, ClosedSubAssign,
-    ClosedMul, ClosedMulAssign,
-    ClosedDiv, ClosedDivAssign,
-    ClosedNeg
 };
 
 /// Typical integer type
@@ -34,8 +31,8 @@
 pub type float = f64;
 
 /// Casts of abstract numerical types to others via the standard `as` keyword.
-pub trait CastFrom<T : 'static + Copy> : num_traits::cast::AsPrimitive<T> {
-    fn cast_from(other : T) -> Self;
+pub trait CastFrom<T: 'static + Copy>: num_traits::cast::AsPrimitive<T> {
+    fn cast_from(other: T) -> Self;
 }
 
 macro_rules! impl_casts {
@@ -58,53 +55,71 @@
             f32 f64);
 
 /// Trait for general numeric types
-pub trait Num : 'static + Copy + Sync + Send + num::Num + num_traits::NumAssign
-                 + std::iter::Sum + std::iter::Product
-                 + std::fmt::Debug + std::fmt::Display + serde::Serialize
-                 + CastFrom<u8>   + CastFrom<u16> + CastFrom<u32> + CastFrom<u64>
-                 + CastFrom<u128> + CastFrom<usize>
-                 + CastFrom<i8>   + CastFrom<i16> + CastFrom<i32> + CastFrom<i64>
-                 + CastFrom<i128> + CastFrom<isize>
-                 + CastFrom<f32>  + CastFrom<f64>
-                 + crate::instance::Space {
-
-    const ZERO : Self;
-    const ONE : Self;
-    const TWO : Self;
+pub trait Num:
+    'static
+    + Copy
+    + Sync
+    + Send
+    + num::Num
+    + num_traits::NumAssign
+    + std::iter::Sum
+    + std::iter::Product
+    + std::fmt::Debug
+    + std::fmt::Display
+    + serde::Serialize
+    + CastFrom<u8>
+    + CastFrom<u16>
+    + CastFrom<u32>
+    + CastFrom<u64>
+    + CastFrom<u128>
+    + CastFrom<usize>
+    + CastFrom<i8>
+    + CastFrom<i16>
+    + CastFrom<i32>
+    + CastFrom<i64>
+    + CastFrom<i128>
+    + CastFrom<isize>
+    + CastFrom<f32>
+    + CastFrom<f64>
+    + crate::instance::ClosedSpace
+{
+    const ZERO: Self;
+    const ONE: Self;
+    const TWO: Self;
     /// Generic version of `Self::MAX`
-    const RANGE_MAX : Self;
+    const RANGE_MAX: Self;
     /// Generic version of `Self::MIN`
-    const RANGE_MIN : Self;
+    const RANGE_MIN: Self;
 }
 
 /// Trait for signed numeric types
-pub trait SignedNum : Num + num::Signed + std::ops::Neg<Output=Self> {}
-impl<U : Num + num::Signed + std::ops::Neg<Output=Self>> SignedNum for U { }
+pub trait SignedNum: Num + num::Signed + std::ops::Neg<Output = Self> {}
+impl<U: Num + num::Signed + std::ops::Neg<Output = Self>> SignedNum for U {}
 
 /// Trait for floating point numbers
-pub trait Float : SignedNum + num::Float /*+ From<Self::CompatibleSize>*/ {
+pub trait Float: SignedNum + num::Float /*+ From<Self::CompatibleSize>*/ {
     // An unsigned integer that can be used for indexing operations and
     // converted to F without loss.
     //type CompatibleSize : CompatibleUnsigned<Self>;
 
-    const PI : Self;
-    const E : Self;
-    const EPSILON : Self;
-    const SQRT_2 : Self;
-    const INFINITY : Self;
-    const NEG_INFINITY : Self;
-    const NAN : Self;
-    const FRAC_2_SQRT_PI : Self;
+    const PI: Self;
+    const E: Self;
+    const EPSILON: Self;
+    const SQRT_2: Self;
+    const INFINITY: Self;
+    const NEG_INFINITY: Self;
+    const NAN: Self;
+    const FRAC_2_SQRT_PI: Self;
 }
 
 /// Trait for integers
-pub trait Integer : Num + num::Integer {}
+pub trait Integer: Num + num::Integer {}
 
 /// Trait for unsigned integers
-pub trait Unsigned : Num + Integer + num::Unsigned {}
+pub trait Unsigned: Num + Integer + num::Unsigned {}
 
 /// Trait for signed integers
-pub trait Signed : SignedNum + Integer {}
+pub trait Signed: SignedNum + Integer {}
 
 macro_rules! impl_num_consts {
     ($($type:ty)*) => { $(
@@ -137,14 +152,14 @@
     #[cfg(any(target_pointer_width = "32", target_pointer_width = "16"))]
     type CompatibleSize = usize;*/
 
-    const PI : Self = std::f64::consts::PI;
-    const E : Self = std::f64::consts::E;
-    const EPSILON : Self = std::f64::EPSILON;
-    const SQRT_2 : Self = std::f64::consts::SQRT_2;
-    const INFINITY : Self = std::f64::INFINITY;
-    const NEG_INFINITY : Self = std::f64::NEG_INFINITY;
-    const NAN : Self = std::f64::NAN;
-    const FRAC_2_SQRT_PI : Self = std::f64::consts::FRAC_2_SQRT_PI;
+    const PI: Self = std::f64::consts::PI;
+    const E: Self = std::f64::consts::E;
+    const EPSILON: Self = std::f64::EPSILON;
+    const SQRT_2: Self = std::f64::consts::SQRT_2;
+    const INFINITY: Self = std::f64::INFINITY;
+    const NEG_INFINITY: Self = std::f64::NEG_INFINITY;
+    const NAN: Self = std::f64::NAN;
+    const FRAC_2_SQRT_PI: Self = std::f64::consts::FRAC_2_SQRT_PI;
 }
 
 impl Float for f32 {
@@ -155,14 +170,14 @@
     type CompatibleSize = usize;
     */
 
-    const PI : Self = std::f32::consts::PI;
-    const E : Self = std::f32::consts::E;
-    const EPSILON : Self = std::f32::EPSILON;
-    const SQRT_2 : Self = std::f32::consts::SQRT_2;
-    const INFINITY : Self = std::f32::INFINITY;
-    const NEG_INFINITY : Self = std::f32::NEG_INFINITY;
-    const NAN : Self = std::f32::NAN;
-    const FRAC_2_SQRT_PI : Self = std::f32::consts::FRAC_2_SQRT_PI;
+    const PI: Self = std::f32::consts::PI;
+    const E: Self = std::f32::consts::E;
+    const EPSILON: Self = std::f32::EPSILON;
+    const SQRT_2: Self = std::f32::consts::SQRT_2;
+    const INFINITY: Self = std::f32::INFINITY;
+    const NEG_INFINITY: Self = std::f32::NEG_INFINITY;
+    const NAN: Self = std::f32::NAN;
+    const FRAC_2_SQRT_PI: Self = std::f32::consts::FRAC_2_SQRT_PI;
 }
 
 /*
@@ -171,4 +186,3 @@
     pub trait CompatibleSigned<F : Float> = Signed + Into<F>;
 }
 */
-

mercurial