Skip to content

Commit

Permalink
Rename generic parameter N -> T
Browse files Browse the repository at this point in the history
  • Loading branch information
sebcrozet committed Apr 11, 2021
1 parent 23a7d74 commit 24d546d
Show file tree
Hide file tree
Showing 217 changed files with 8,536 additions and 8,946 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ no_unsound_assume_init = [ ]
# Conversion
convert-mint = [ "mint" ]
convert-glam = [ "glam" ]
convert-glam-unchecked = [ "convert-glam" ] # Unable edgy conversions like Mat4 -> Isometry3
convert-glam-unchecked = [ "convert-glam" ] # Enable edgy conversions like Mat4 -> Isometry3
convert-bytemuck = [ "bytemuck" ]

# Serialization
Expand Down
6 changes: 3 additions & 3 deletions benches/core/matrix.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use na::{DMatrix, DVector, Matrix2, Matrix3, Matrix4, MatrixN, Vector2, Vector3, Vector4, U10};
use na::{DMatrix, DVector, Matrix2, Matrix3, Matrix4, OMatrix, Vector2, Vector3, Vector4, U10};
use rand::Rng;
use rand_isaac::IsaacRng;
use std::ops::{Add, Div, Mul, Sub};
Expand Down Expand Up @@ -116,8 +116,8 @@ fn mat10_mul_mat10(bench: &mut criterion::Criterion) {
}

fn mat10_mul_mat10_static(bench: &mut criterion::Criterion) {
let a = MatrixN::<f64, U10>::new_random();
let b = MatrixN::<f64, U10>::new_random();
let a = OMatrix::<f64, U10>::new_random();
let b = OMatrix::<f64, U10>::new_random();

bench.bench_function("mat10_mul_mat10_static", move |bh| bh.iter(|| &a * &b));
}
Expand Down
12 changes: 6 additions & 6 deletions benches/core/vector.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use na::{DVector, Vector2, Vector3, Vector4, VectorN};
use na::{DVector, OVector, Vector2, Vector3, Vector4};
use rand::Rng;
use rand_isaac::IsaacRng;
use std::ops::{Add, Div, Mul, Sub};
Expand Down Expand Up @@ -45,8 +45,8 @@ bench_unop!(vec2_normalize, Vector2<f32>, normalize);
bench_unop!(vec3_normalize, Vector3<f32>, normalize);
bench_unop!(vec4_normalize, Vector4<f32>, normalize);

bench_binop_ref!(vec10000_dot_f64, VectorN<f64, U10000>, VectorN<f64, U10000>, dot);
bench_binop_ref!(vec10000_dot_f32, VectorN<f32, U10000>, VectorN<f32, U10000>, dot);
bench_binop_ref!(vec10000_dot_f64, OVector<f64, U10000>, OVector<f64, U10000>, dot);
bench_binop_ref!(vec10000_dot_f32, OVector<f32, U10000>, OVector<f32, U10000>, dot);

fn vec10000_axpy_f64(bh: &mut criterion::Criterion) {
use rand::SeedableRng;
Expand Down Expand Up @@ -93,11 +93,11 @@ fn vec10000_axpy_f64_slice(bh: &mut criterion::Criterion) {
fn vec10000_axpy_f64_static(bh: &mut criterion::Criterion) {
use rand::SeedableRng;
let mut rng = IsaacRng::seed_from_u64(0);
let mut a = VectorN::<f64, U10000>::new_random();
let b = VectorN::<f64, U10000>::new_random();
let mut a = OVector::<f64, U10000>::new_random();
let b = OVector::<f64, U10000>::new_random();
let n = rng.gen::<f64>();

// NOTE: for some reasons, it is much faster if the arument are boxed (Box::new(VectorN...)).
// NOTE: for some reasons, it is much faster if the arument are boxed (Box::new(OVector...)).
bh.bench_function("vec10000_axpy_f64_static", move |bh| {
bh.iter(|| a.axpy(n, &b, 1.0))
});
Expand Down
22 changes: 11 additions & 11 deletions examples/dimensional_genericity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@ extern crate nalgebra as na;

use na::allocator::Allocator;
use na::dimension::Dim;
use na::{DefaultAllocator, RealField, Unit, Vector2, Vector3, VectorN};
use na::{DefaultAllocator, OVector, RealField, Unit, Vector2, Vector3};

/// Reflects a vector wrt. the hyperplane with normal `plane_normal`.
fn reflect_wrt_hyperplane_with_dimensional_genericity<N: RealField, D: Dim>(
plane_normal: &Unit<VectorN<N, D>>,
vector: &VectorN<N, D>,
) -> VectorN<N, D>
fn reflect_wrt_hyperplane_with_dimensional_genericity<T: RealField, D: Dim>(
plane_normal: &Unit<OVector<T, D>>,
vector: &OVector<T, D>,
) -> OVector<T, D>
where
N: RealField,
T: RealField,
D: Dim,
DefaultAllocator: Allocator<N, D>,
DefaultAllocator: Allocator<T, D>,
{
let n = plane_normal.as_ref(); // Get the underlying V.
vector - n * (n.dot(vector) * na::convert(2.0))
}

/// Reflects a 2D vector wrt. the 2D line with normal `plane_normal`.
fn reflect_wrt_hyperplane2<N>(plane_normal: &Unit<Vector2<N>>, vector: &Vector2<N>) -> Vector2<N>
fn reflect_wrt_hyperplane2<T>(plane_normal: &Unit<Vector2<T>>, vector: &Vector2<T>) -> Vector2<T>
where
N: RealField,
T: RealField,
{
let n = plane_normal.as_ref(); // Get the underlying Vector2
vector - n * (n.dot(vector) * na::convert(2.0))
}

/// Reflects a 3D vector wrt. the 3D plane with normal `plane_normal`.
/// /!\ This is an exact replicate of `reflect_wrt_hyperplane2, but for 3D.
fn reflect_wrt_hyperplane3<N>(plane_normal: &Unit<Vector3<N>>, vector: &Vector3<N>) -> Vector3<N>
fn reflect_wrt_hyperplane3<T>(plane_normal: &Unit<Vector3<T>>, vector: &Vector3<T>) -> Vector3<T>
where
N: RealField,
T: RealField,
{
let n = plane_normal.as_ref(); // Get the underlying Vector3
vector - n * (n.dot(vector) * na::convert(2.0))
Expand Down
14 changes: 7 additions & 7 deletions examples/matrixcompare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ extern crate nalgebra as na;

use matrixcompare::comparators::{AbsoluteElementwiseComparator, ExactElementwiseComparator};
use matrixcompare::compare_matrices;
use na::{MatrixMN, U3, U4};
use na::{OMatrix, U3, U4};

fn compare_integers_fail() {
println!("Comparing two integer matrices.");

#[rustfmt::skip]
let a = MatrixMN::<_, U3, U4>::from_row_slice(&[
let a = OMatrix::<_, U3, U4>::from_row_slice(&[
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, -2, 11
]);

#[rustfmt::skip]
let b = MatrixMN::<_, U3, U4>::from_row_slice(&[
let b = OMatrix::<_, U3, U4>::from_row_slice(&[
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11
Expand All @@ -29,14 +29,14 @@ fn compare_integers_fail() {
fn compare_different_size() {
println!("Comparing matrices of different size.");
#[rustfmt::skip]
let a = MatrixMN::<_, U3, U3>::from_row_slice(&[
let a = OMatrix::<_, U3, U3>::from_row_slice(&[
0, 1, 2,
4, 5, 6,
8, 9, 10,
]);

#[rustfmt::skip]
let b = MatrixMN::<_, U3, U4>::from_row_slice(&[
let b = OMatrix::<_, U3, U4>::from_row_slice(&[
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11
Expand All @@ -51,14 +51,14 @@ fn compare_f64_abs_tol_fail() {
println!("Comparing two f64 matrices.");

#[rustfmt::skip]
let a = MatrixMN::<f64, U3, U3>::from_row_slice(&[
let a = OMatrix::<f64, U3, U3>::from_row_slice(&[
0.0, 1.0, 2.0 + 1e-10,
4.0, 5.0, 6.0,
8.0, 9.0, 10.0,
]);

#[rustfmt::skip]
let b = MatrixMN::<_, U3, U3>::from_row_slice(&[
let b = OMatrix::<_, U3, U3>::from_row_slice(&[
0.0, 1.0, 2.0,
4.0, 5.0, 6.0,
8.0, 9.0, 10.0
Expand Down
6 changes: 3 additions & 3 deletions examples/scalar_genericity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ extern crate nalgebra as na;
use na::{Scalar, Vector3};
use simba::scalar::RealField;

fn print_vector<N: Scalar>(m: &Vector3<N>) {
fn print_vector<T: Scalar>(m: &Vector3<T>) {
println!("{:?}", m)
}

fn print_norm<N: RealField>(v: &Vector3<N>) {
fn print_norm<T: RealField>(v: &Vector3<T>) {
// NOTE: alternatively, nalgebra already defines `v.norm()`.
let norm = v.dot(v).sqrt();

// The RealField bound implies that N is Display so we can
// The RealField bound implies that T is Display so we can
// use "{}" instead of "{:?}" for the format string.
println!("{}", norm)
}
Expand Down
80 changes: 40 additions & 40 deletions nalgebra-glm/src/aliases.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use na::{
Matrix2, Matrix2x3, Matrix2x4, Matrix3, Matrix3x2, Matrix3x4, Matrix4, Matrix4x2, Matrix4x3,
MatrixMN, Quaternion, VectorN, U1, U2, U3, U4,
Quaternion, SMatrix, SVector,
};

/// A matrix with components of type `N`. It has `R` rows, and `C` columns.
/// A matrix with components of type `T`. It has `R` rows, and `C` columns.
///
/// In this library, vectors, represented as [`TVec`](type.TVec.html) and
/// friends, are also matrices. Operations that operate on a matrix will
Expand All @@ -24,8 +24,8 @@ use na::{
/// * [`TMat4x3`](type.TMat4x3.html)
/// * [`TMat4x4`](type.TMat4x4.html)
/// * [`TVec`](type.TVec.html)
pub type TMat<N, R, C> = MatrixMN<N, R, C>;
/// A column vector with components of type `N`. It has `D` rows (and one column).
pub type TMat<T, const R: usize, const C: usize> = SMatrix<T, R, C>;
/// A column vector with components of type `T`. It has `D` rows (and one column).
///
/// In this library, vectors are represented as a single column matrix, so
/// operations on [`TMat`](type.TMat.html) are also valid on vectors.
Expand All @@ -37,11 +37,11 @@ pub type TMat<N, R, C> = MatrixMN<N, R, C>;
/// * [`TVec2`](type.TVec2.html)
/// * [`TVec3`](type.TVec3.html)
/// * [`TVec4`](type.TVec4.html)
pub type TVec<N, R> = VectorN<N, R>;
/// A quaternion with components of type `N`.
pub type Qua<N> = Quaternion<N>;
pub type TVec<T, const R: usize> = SVector<T, R>;
/// A quaternion with components of type `T`.
pub type Qua<T> = Quaternion<T>;

/// A 1D vector with components of type `N`.
/// A 1D vector with components of type `T`.
///
/// # See also:
///
Expand Down Expand Up @@ -69,8 +69,8 @@ pub type Qua<N> = Quaternion<N>;
/// * [`U64Vec1`](type.U64Vec1.html)
/// * [`U8Vec1`](type.U8Vec1.html)
/// * [`Vec1`](type.Vec1.html)
pub type TVec1<N> = TVec<N, U1>;
/// A 2D vector with components of type `N`.
pub type TVec1<T> = TVec<T, 1>;
/// A 2D vector with components of type `T`.
///
/// # See also:
///
Expand Down Expand Up @@ -99,8 +99,8 @@ pub type TVec1<N> = TVec<N, U1>;
/// * [`U64Vec2`](type.U64Vec2.html)
/// * [`U8Vec2`](type.U8Vec2.html)
/// * [`Vec2`](type.Vec2.html)
pub type TVec2<N> = TVec<N, U2>;
/// A 3D vector with components of type `N`.
pub type TVec2<T> = TVec<T, 2>;
/// A 3D vector with components of type `T`.
///
/// # See also:
///
Expand Down Expand Up @@ -129,8 +129,8 @@ pub type TVec2<N> = TVec<N, U2>;
/// * [`U64Vec3`](type.U64Vec3.html)
/// * [`U8Vec3`](type.U8Vec3.html)
/// * [`Vec3`](type.Vec3.html)
pub type TVec3<N> = TVec<N, U3>;
/// A 4D vector with components of type `N`.
pub type TVec3<T> = TVec<T, 3>;
/// A 4D vector with components of type `T`.
///
/// # See also:
///
Expand Down Expand Up @@ -158,7 +158,7 @@ pub type TVec3<N> = TVec<N, U3>;
/// * [`U64Vec4`](type.U64Vec4.html)
/// * [`U8Vec4`](type.U8Vec4.html)
/// * [`Vec4`](type.Vec4.html)
pub type TVec4<N> = TVec<N, U4>;
pub type TVec4<T> = TVec<T, 4>;
/// A 1D vector with boolean components.
pub type BVec1 = TVec1<bool>;
/// A 2D vector with boolean components.
Expand Down Expand Up @@ -268,31 +268,31 @@ pub type I8Vec3 = TVec3<i8>;
/// A 4D vector with `i8` components.
pub type I8Vec4 = TVec4<i8>;

/// A 2x2 matrix with components of type `N`.
pub type TMat2<N> = Matrix2<N>;
/// A 2x2 matrix with components of type `N`.
pub type TMat2x2<N> = Matrix2<N>;
/// A 2x3 matrix with components of type `N`.
pub type TMat2x3<N> = Matrix2x3<N>;
/// A 2x4 matrix with components of type `N`.
pub type TMat2x4<N> = Matrix2x4<N>;
/// A 3x3 matrix with components of type `N`.
pub type TMat3<N> = Matrix3<N>;
/// A 3x2 matrix with components of type `N`.
pub type TMat3x2<N> = Matrix3x2<N>;
/// A 3x3 matrix with components of type `N`.
pub type TMat3x3<N> = Matrix3<N>;
/// A 3x4 matrix with components of type `N`.
pub type TMat3x4<N> = Matrix3x4<N>;
/// A 4x4 matrix with components of type `N`.
pub type TMat4<N> = Matrix4<N>;
/// A 4x2 matrix with components of type `N`.
pub type TMat4x2<N> = Matrix4x2<N>;
/// A 4x3 matrix with components of type `N`.
pub type TMat4x3<N> = Matrix4x3<N>;
/// A 4x4 matrix with components of type `N`.
pub type TMat4x4<N> = Matrix4<N>;
/// A 2x2 matrix with components of type `N`.
/// A 2x2 matrix with components of type `T`.
pub type TMat2<T> = Matrix2<T>;
/// A 2x2 matrix with components of type `T`.
pub type TMat2x2<T> = Matrix2<T>;
/// A 2x3 matrix with components of type `T`.
pub type TMat2x3<T> = Matrix2x3<T>;
/// A 2x4 matrix with components of type `T`.
pub type TMat2x4<T> = Matrix2x4<T>;
/// A 3x3 matrix with components of type `T`.
pub type TMat3<T> = Matrix3<T>;
/// A 3x2 matrix with components of type `T`.
pub type TMat3x2<T> = Matrix3x2<T>;
/// A 3x3 matrix with components of type `T`.
pub type TMat3x3<T> = Matrix3<T>;
/// A 3x4 matrix with components of type `T`.
pub type TMat3x4<T> = Matrix3x4<T>;
/// A 4x4 matrix with components of type `T`.
pub type TMat4<T> = Matrix4<T>;
/// A 4x2 matrix with components of type `T`.
pub type TMat4x2<T> = Matrix4x2<T>;
/// A 4x3 matrix with components of type `T`.
pub type TMat4x3<T> = Matrix4x3<T>;
/// A 4x4 matrix with components of type `T`.
pub type TMat4x4<T> = Matrix4<T>;
/// A 2x2 matrix with components of type `T`.
pub type DMat2 = Matrix2<f64>;
/// A 2x2 matrix with `f64` components.
pub type DMat2x2 = Matrix2<f64>;
Expand Down
Loading

0 comments on commit 24d546d

Please sign in to comment.