Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate min-const-generics. #820

Merged
merged 17 commits into from
Apr 12, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
First compiling version after migrating the geometry module to const-…
…generics.
sebcrozet committed Apr 11, 2021
commit 23a7d7475b2ce308006373ab306e658fa6eb09bb
37 changes: 26 additions & 11 deletions src/base/cg.rs
Original file line number Diff line number Diff line change
@@ -11,8 +11,8 @@ use crate::base::allocator::Allocator;
use crate::base::dimension::{DimName, DimNameDiff, DimNameSub, U1};
use crate::base::storage::{Storage, StorageMut};
use crate::base::{
DefaultAllocator, Matrix3, Matrix4, MatrixN, Scalar, SquareMatrix, Unit, Vector, Vector2,
Vector3, VectorN,
Const, DefaultAllocator, Matrix3, Matrix4, MatrixN, Scalar, SquareMatrix, Unit, Vector,
Vector2, Vector3, VectorN,
};
use crate::geometry::{
Isometry, IsometryMatrix3, Orthographic3, Perspective3, Point, Point2, Point3, Rotation2,
@@ -411,18 +411,33 @@ where

transform * v
}
}

impl<N: RealField, S: Storage<N, Const<3>, Const<3>>> SquareMatrix<N, Const<3>, S> {
/// Transforms the given point, assuming the matrix `self` uses homogeneous coordinates.
#[inline]
pub fn transform_point(
&self,
pt: &Point<N, { DimNameDiff::<D, U1>::USIZE }>,
) -> Point<N, { DimNameDiff::<D, U1>::USIZE }> {
let transform = self.fixed_slice::<DimNameDiff<D, U1>, DimNameDiff<D, U1>>(0, 0);
let translation = self.fixed_slice::<DimNameDiff<D, U1>, U1>(0, D::dim() - 1);
let normalizer = self.fixed_slice::<U1, DimNameDiff<D, U1>>(D::dim() - 1, 0);
let n = normalizer.tr_dot(&pt.coords)
+ unsafe { *self.get_unchecked((D::dim() - 1, D::dim() - 1)) };
pub fn transform_point(&self, pt: &Point<N, 2>) -> Point<N, 2> {
let transform = self.fixed_slice::<Const<2>, Const<2>>(0, 0);
let translation = self.fixed_slice::<Const<2>, U1>(0, 2);
let normalizer = self.fixed_slice::<U1, Const<2>>(2, 0);
let n = normalizer.tr_dot(&pt.coords) + unsafe { *self.get_unchecked((2, 2)) };

if !n.is_zero() {
(transform * pt + translation) / n
} else {
transform * pt + translation
}
}
}

impl<N: RealField, S: Storage<N, Const<4>, Const<4>>> SquareMatrix<N, Const<4>, S> {
/// Transforms the given point, assuming the matrix `self` uses homogeneous coordinates.
#[inline]
pub fn transform_point(&self, pt: &Point<N, 3>) -> Point<N, 3> {
let transform = self.fixed_slice::<Const<3>, Const<3>>(0, 0);
let translation = self.fixed_slice::<Const<3>, U1>(0, 3);
let normalizer = self.fixed_slice::<U1, Const<3>>(3, 0);
let n = normalizer.tr_dot(&pt.coords) + unsafe { *self.get_unchecked((3, 3)) };

if !n.is_zero() {
(transform * pt + translation) / n
1 change: 0 additions & 1 deletion src/geometry/abstract_rotation.rs
Original file line number Diff line number Diff line change
@@ -39,7 +39,6 @@ pub trait AbstractRotation<N: Scalar, const D: usize>: PartialEq + ClosedMul + C
impl<N: SimdRealField, const D: usize> AbstractRotation<N, D> for Rotation<N, D>
where
N::Element: SimdRealField,
// DefaultAllocator: Allocator<N, D, D>,
{
#[inline]
fn identity() -> Self {
20 changes: 5 additions & 15 deletions src/geometry/isometry.rs
Original file line number Diff line number Diff line change
@@ -59,14 +59,14 @@ use crate::geometry::{AbstractRotation, Point, Translation};
#[cfg_attr(
feature = "serde-serialize",
serde(bound(serialize = "R: Serialize,
DefaultAllocator: Allocator<N, D>,
Owned<N, D>: Serialize"))
DefaultAllocator: Allocator<N, Const<D>>,
Owned<N, Const<D>>: Serialize"))
)]
#[cfg_attr(
feature = "serde-serialize",
serde(bound(deserialize = "R: Deserialize<'de>,
DefaultAllocator: Allocator<N, D>,
Owned<N, D>: Deserialize<'de>"))
DefaultAllocator: Allocator<N, Const<D>>,
Owned<N, Const<D>>: Deserialize<'de>"))
)]
pub struct Isometry<N: Scalar, R, const D: usize>
// where
@@ -84,7 +84,6 @@ where
N: SimdRealField,
R: Abomonation,
Translation<N, D>: Abomonation,
// DefaultAllocator: Allocator<N, D>,
{
unsafe fn entomb<W: Write>(&self, writer: &mut W) -> IOResult<()> {
self.rotation.entomb(writer)?;
@@ -104,7 +103,6 @@ where

impl<N: Scalar + hash::Hash, R: hash::Hash, const D: usize> hash::Hash for Isometry<N, R, D>
where
// DefaultAllocator: Allocator<N, D>,
Owned<N, Const<D>>: hash::Hash,
{
fn hash<H: hash::Hasher>(&self, state: &mut H) {
@@ -114,7 +112,6 @@ where
}

impl<N: Scalar + Copy, R: Copy, const D: usize> Copy for Isometry<N, R, D> where
// DefaultAllocator: Allocator<N, D>,
Owned<N, Const<D>>: Copy
{
}
@@ -163,7 +160,6 @@ impl<N: Scalar, R: AbstractRotation<N, D>, const D: usize> Isometry<N, R, D>
impl<N: SimdRealField, R: AbstractRotation<N, D>, const D: usize> Isometry<N, R, D>
where
N::Element: SimdRealField,
// DefaultAllocator: Allocator<N, D>,
{
/// Inverts `self`.
///
@@ -318,7 +314,6 @@ where
impl<N: SimdRealField, R: AbstractRotation<N, D>, const D: usize> Isometry<N, R, D>
where
N::Element: SimdRealField,
// DefaultAllocator: Allocator<N, D>,
{
/// Transform the given point by this isometry.
///
@@ -504,14 +499,13 @@ impl<N: SimdRealField, R, const D: usize> Isometry<N, R, D>
}

impl<N: SimdRealField, R, const D: usize> Eq for Isometry<N, R, D> where
R: AbstractRotation<N, D> + Eq // DefaultAllocator: Allocator<N, D>,
R: AbstractRotation<N, D> + Eq
{
}

impl<N: SimdRealField, R, const D: usize> PartialEq for Isometry<N, R, D>
where
R: AbstractRotation<N, D> + PartialEq,
// DefaultAllocator: Allocator<N, D>,
{
#[inline]
fn eq(&self, right: &Self) -> bool {
@@ -522,7 +516,6 @@ where
impl<N: RealField, R, const D: usize> AbsDiffEq for Isometry<N, R, D>
where
R: AbstractRotation<N, D> + AbsDiffEq<Epsilon = N::Epsilon>,
// DefaultAllocator: Allocator<N, D>,
N::Epsilon: Copy,
{
type Epsilon = N::Epsilon;
@@ -542,7 +535,6 @@ where
impl<N: RealField, R, const D: usize> RelativeEq for Isometry<N, R, D>
where
R: AbstractRotation<N, D> + RelativeEq<Epsilon = N::Epsilon>,
// DefaultAllocator: Allocator<N, D>,
N::Epsilon: Copy,
{
#[inline]
@@ -568,7 +560,6 @@ where
impl<N: RealField, R, const D: usize> UlpsEq for Isometry<N, R, D>
where
R: AbstractRotation<N, D> + UlpsEq<Epsilon = N::Epsilon>,
// DefaultAllocator: Allocator<N, D>,
N::Epsilon: Copy,
{
#[inline]
@@ -592,7 +583,6 @@ where
impl<N: RealField + fmt::Display, R, const D: usize> fmt::Display for Isometry<N, R, D>
where
R: fmt::Display,
// DefaultAllocator: Allocator<N, D> + Allocator<usize, D>,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let precision = f.precision().unwrap_or(3);
18 changes: 5 additions & 13 deletions src/geometry/isometry_construction.rs
Original file line number Diff line number Diff line change
@@ -13,19 +13,17 @@ use rand::{
use simba::scalar::SupersetOf;
use simba::simd::SimdRealField;

use crate::base::dimension::U2;
use crate::base::{Vector2, Vector3};

use crate::{
AbstractRotation, Isometry, Isometry2, Isometry3, IsometryMatrix2, IsometryMatrix3, Point,
Point3, Rotation, Rotation3, Scalar, Translation, Translation2, Translation3, UnitComplex,
UnitQuaternion,
AbstractRotation, Const, Isometry, Isometry2, Isometry3, IsometryMatrix2, IsometryMatrix3,
Point, Point3, Rotation, Rotation3, Scalar, Translation, Translation2, Translation3,
UnitComplex, UnitQuaternion,
};

impl<N: SimdRealField, R: AbstractRotation<N, D>, const D: usize> Isometry<N, R, D>
where
N::Element: SimdRealField,
// DefaultAllocator: Allocator<N, D>,
{
/// Creates a new identity isometry.
///
@@ -73,7 +71,6 @@ where
impl<N: SimdRealField, R: AbstractRotation<N, D>, const D: usize> One for Isometry<N, R, D>
where
N::Element: SimdRealField,
// DefaultAllocator: Allocator<N, D>,
{
/// Creates a new identity isometry.
#[inline]
@@ -87,7 +84,6 @@ impl<N: crate::RealField, R, const D: usize> Distribution<Isometry<N, R, D>> for
where
R: AbstractRotation<N, D>,
Standard: Distribution<N> + Distribution<R>,
// DefaultAllocator: Allocator<N, D>,
{
#[inline]
fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> Isometry<N, R, D> {
@@ -101,8 +97,7 @@ where
N: SimdRealField + Arbitrary + Send,
N::Element: SimdRealField,
R: AbstractRotation<N, D> + Arbitrary + Send,
Owned<N, D>: Send,
// DefaultAllocator: Allocator<N, D>,
Owned<N, Const<D>>: Send,
{
#[inline]
fn arbitrary(rng: &mut Gen) -> Self {
@@ -136,10 +131,7 @@ where
/// ```
#[inline]
pub fn new(translation: Vector2<N>, angle: N) -> Self {
Self::from_parts(
Translation::from(translation),
Rotation::<N, U2>::new(angle),
)
Self::from_parts(Translation::from(translation), Rotation::<N, 2>::new(angle))
}

/// Creates a new isometry from the given translation coordinates.
14 changes: 4 additions & 10 deletions src/geometry/isometry_conversion.rs
Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@ where
N2: RealField + SupersetOf<N1>,
R1: AbstractRotation<N1, D> + SubsetOf<R2>,
R2: AbstractRotation<N2, D>,
// DefaultAllocator: Allocator<N1, D> + Allocator<N2, D>,
{
#[inline]
fn to_superset(&self) -> Isometry<N2, R2, D> {
@@ -63,7 +62,7 @@ where
#[inline]
fn is_in_subset(dq: &UnitDualQuaternion<N2>) -> bool {
crate::is_convertible::<_, UnitQuaternion<N1>>(&dq.rotation())
&& crate::is_convertible::<_, Translation<N1, _>>(&dq.translation())
&& crate::is_convertible::<_, Translation<N1, 3>>(&dq.translation())
}

#[inline]
@@ -79,7 +78,6 @@ where
N2: RealField + SupersetOf<N1>,
R1: AbstractRotation<N1, D> + SubsetOf<R2>,
R2: AbstractRotation<N2, D>,
// DefaultAllocator: Allocator<N1, D> + Allocator<N2, D>,
{
#[inline]
fn to_superset(&self) -> Similarity<N2, R2, D> {
@@ -154,8 +152,8 @@ where

#[inline]
fn is_in_subset(m: &MatrixN<N2, DimNameSum<Const<D>, U1>>) -> bool {
let rot = m.fixed_slice::<D, D>(0, 0);
let bottom = m.fixed_slice::<U1, D>(D, 0);
let rot = m.fixed_slice::<Const<D>, Const<D>>(0, 0);
let bottom = m.fixed_slice::<U1, Const<D>>(D, 0);

// Scalar types agree.
m.iter().all(|e| SupersetOf::<N1>::is_in_subset(e)) &&
@@ -167,7 +165,7 @@ where

#[inline]
fn from_superset_unchecked(m: &MatrixN<N2, DimNameSum<Const<D>, U1>>) -> Self {
let t = m.fixed_slice::<D, U1>(0, D).into_owned();
let t = m.fixed_slice::<Const<D>, U1>(0, D).into_owned();
let t = Translation {
vector: crate::convert_unchecked(t),
};
@@ -208,7 +206,6 @@ where
R::Element: AbstractRotation<N::Element, D>,
N::Element: Scalar + Copy,
R::Element: Scalar + Copy,
// DefaultAllocator: Allocator<N, D> + Allocator<N::Element, D>,
{
#[inline]
fn from(arr: [Isometry<N::Element, R::Element, D>; 2]) -> Self {
@@ -227,7 +224,6 @@ where
R::Element: AbstractRotation<N::Element, D>,
N::Element: Scalar + Copy,
R::Element: Scalar + Copy,
// DefaultAllocator: Allocator<N, D> + Allocator<N::Element, D>,
{
#[inline]
fn from(arr: [Isometry<N::Element, R::Element, D>; 4]) -> Self {
@@ -256,7 +252,6 @@ where
R::Element: AbstractRotation<N::Element, D>,
N::Element: Scalar + Copy,
R::Element: Scalar + Copy,
// DefaultAllocator: Allocator<N, D> + Allocator<N::Element, D>,
{
#[inline]
fn from(arr: [Isometry<N::Element, R::Element, D>; 8]) -> Self {
@@ -293,7 +288,6 @@ where
R::Element: AbstractRotation<N::Element, D>,
N::Element: Scalar + Copy,
R::Element: Scalar + Copy,
// DefaultAllocator: Allocator<N, D> + Allocator<N::Element, D>,
{
#[inline]
fn from(arr: [Isometry<N::Element, R::Element, D>; 16]) -> Self {
Loading