diff --git a/Cargo.toml b/Cargo.toml index 8ed05a0..296f2d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nalgebra-spacetime" -version = "0.1.1" +version = "0.1.2" authors = ["Rouven Spreckels "] edition = "2018" description = "Spacetime Extension for nalgebra" @@ -17,7 +17,7 @@ keywords = [ ] categories = [ "science", - "mathematics" + "mathematics", ] include = [ "src/**/*.rs", diff --git a/src/lib.rs b/src/lib.rs index 48feec4..0bf645b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,7 +38,7 @@ use nalgebra::{ DimEq, }, storage::{Storage, Owned}, - DefaultAllocator, base::allocator::{Allocator, SameShapeAllocator}, + DefaultAllocator, base::allocator::Allocator, }; use num_traits::{sign::Signed, real::Real}; use approx::{AbsDiffEq, abs_diff_eq}; @@ -54,8 +54,8 @@ use LightCone::*; pub trait LorentzianMN where N: Scalar, - R: Dim, - C: Dim, + R: DimName, + C: DimName, { /// Lorentzian metric tensor $\eta_{\mu \nu}$: /// @@ -105,8 +105,6 @@ where /// ``` fn metric() -> Self where - R: DimName, - C: DimName, ShapeConstraint: SameDimension; /// Raises/Lowers *all* of its degree-1/degree-2 tensor indices. @@ -245,15 +243,9 @@ where /// /// * `is_present = |time| abs_diff_eq!(time, N::zero())`, and /// * `is_lightlike = |interval| abs_diff_eq!(interval, N::zero())`. - fn interval(&self, rhs: &Matrix) - -> (N, LightCone) + fn interval(&self, rhs: &Self) -> (N, LightCone) where - R2: Dim, - C2: Dim, - SB: Storage, - ShapeConstraint: SameNumberOfRows + SameNumberOfColumns - + DimEq + DimEq, - DefaultAllocator: SameShapeAllocator; + ShapeConstraint: DimEq; /// Spacetime interval between two events and region of `self`'s light cone. /// @@ -271,16 +263,11 @@ where /// See `interval()` for using defaults and [approx] for further details. /// /// [approx]: https://docs.rs/approx - fn interval_fn(&self, rhs: &Matrix, + fn interval_fn(&self, rhs: &Self, is_present: P, is_lightlike: L) -> (N, LightCone) where - R2: Dim, - C2: Dim, - SB: Storage, - ShapeConstraint: SameNumberOfRows + SameNumberOfColumns - + DimEq + DimEq, - DefaultAllocator: SameShapeAllocator, + ShapeConstraint: DimEq, P: Fn(N) -> bool, L: Fn(N) -> bool; @@ -321,8 +308,6 @@ where /// $$ fn new_boost(frame: &FrameN) -> Self where - R: DimName, - C: DimName, D: DimNameSub, ShapeConstraint: AreMultipliable + DimEq, DefaultAllocator: Allocator>; @@ -345,8 +330,6 @@ where /// See `boost_mut()` for further details. fn boost(&self, frame: &FrameN) -> Self where - R: DimName, - C: DimName, D: DimNameSub, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, DefaultAllocator: Allocator>; @@ -370,8 +353,6 @@ where /// Equals relativistic velocity addition $v \oplus u$ in case $x \equiv v$. fn boost_mut(&mut self, frame: &FrameN) where - R: DimName, - C: DimName, D: DimNameSub, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, DefaultAllocator: Allocator>; @@ -379,8 +360,6 @@ where /// Velocity $u^\mu$ of inertial `frame` of reference. fn new_velocity(frame: &FrameN) -> VectorN where - R: DimName, - C: DimName, D: DimNameSub, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, DefaultAllocator: Allocator> + Allocator; @@ -389,7 +368,6 @@ where fn frame(&self) -> FrameN where R: DimNameSub, - C: DimName, ShapeConstraint: SameNumberOfColumns, DefaultAllocator: Allocator>; } @@ -397,15 +375,13 @@ where impl LorentzianMN for MatrixMN where N: SimdRealField + Signed + Real + AbsDiffEq, - R: Dim, - C: Dim, + R: DimName, + C: DimName, DefaultAllocator: Allocator, { #[inline] fn metric() -> Self where - R: DimName, - C: DimName, ShapeConstraint: SameDimension, { let mut m = Self::identity(); @@ -437,24 +413,29 @@ where fn dual_mut(&mut self) { if R::is::() || C::is::() { neg(unsafe { self.get_unchecked_mut(0) }); - } else { - for c in 1..self.ncols() { - neg(unsafe { self.get_unchecked_mut((0, c)) }); + } else if R::is::() { + for i in 1..R::dim() { + neg(unsafe { self.get_unchecked_mut((i, 0)) }); + neg(unsafe { self.get_unchecked_mut((0, i)) }); } - for r in 1..self.nrows() { + } else { + for r in 1..R::dim() { neg(unsafe { self.get_unchecked_mut((r, 0)) }); } + for c in 1..C::dim() { + neg(unsafe { self.get_unchecked_mut((0, c)) }); + } } } fn r_dual_mut(&mut self) { - for c in 0..self.ncols() { + for c in 0..C::dim() { neg(unsafe { self.get_unchecked_mut((0, c)) }); } } fn c_dual_mut(&mut self) { - for r in 0..self.nrows() { + for r in 0..R::dim() { neg(unsafe { self.get_unchecked_mut((r, 0)) }); } } @@ -552,15 +533,9 @@ where } #[inline] - fn interval(&self, rhs: &Matrix) - -> (N, LightCone) + fn interval(&self, rhs: &Self) -> (N, LightCone) where - R2: Dim, - C2: Dim, - SB: Storage, - ShapeConstraint: SameNumberOfRows + SameNumberOfColumns - + DimEq + DimEq, - DefaultAllocator: SameShapeAllocator + ShapeConstraint: DimEq, { self.interval_fn(rhs, |time| abs_diff_eq!(time, N::zero()), @@ -568,16 +543,11 @@ where ) } - fn interval_fn(&self, rhs: &Matrix, + fn interval_fn(&self, rhs: &Self, is_present: P, is_lightlike: L) -> (N, LightCone) where - R2: Dim, - C2: Dim, - SB: Storage, - ShapeConstraint: SameNumberOfRows + SameNumberOfColumns - + DimEq + DimEq, - DefaultAllocator: SameShapeAllocator, + ShapeConstraint: DimEq, P: Fn(N) -> bool, L: Fn(N) -> bool, { @@ -604,8 +574,6 @@ where fn new_boost(frame: &FrameN) -> Self where - R: DimName, - C: DimName, D: DimNameSub, ShapeConstraint: AreMultipliable + DimEq, DefaultAllocator: Allocator>, @@ -629,8 +597,6 @@ where #[inline] fn boost(&self, frame: &FrameN) -> Self where - R: DimName, - C: DimName, D: DimNameSub, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, DefaultAllocator: Allocator>, @@ -642,8 +608,6 @@ where fn boost_mut(&mut self, frame: &FrameN) where - R: DimName, - C: DimName, D: DimNameSub, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, DefaultAllocator: Allocator>, @@ -660,8 +624,6 @@ where #[inline] fn new_velocity(frame: &FrameN) -> VectorN where - R: DimName, - C: DimName, D: DimNameSub, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, DefaultAllocator: Allocator> + Allocator, @@ -673,7 +635,6 @@ where fn frame(&self) -> FrameN where R: DimNameSub, - C: DimName, ShapeConstraint: SameNumberOfColumns, DefaultAllocator: Allocator>, { @@ -751,8 +712,8 @@ where /// Inertial frame of reference with velocity $u^\mu$. pub fn from_velocity(u: &MatrixMN) -> Self where - R: DimName, - C: DimName, + R: Dim, + C: Dim, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, DefaultAllocator: Allocator {