forked from M-Labs/nalgebra
Rename methods starting with new_with_
to from_
.
This commit is contained in:
parent
d45c242a15
commit
9c4bff1f85
10
CHANGELOG.md
10
CHANGELOG.md
@ -14,6 +14,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- `::canonical_basis_with_dim` -> `::canonical_basis_with_dimension`
|
||||
- `::from_elem` -> `::from_element`
|
||||
- `DiagMut` -> `DiagonalMut`
|
||||
- `UnitQuaternion::new` becomes `UnitQuaternion::from_scaled_axis` or
|
||||
`UnitQuaternion::from_axisangle`. The new `::new` method now requires a
|
||||
not-normalized quaternion.
|
||||
|
||||
Methods names starting with `new_with_` now start with `from_`. This is more
|
||||
idiomatic in Rust.
|
||||
|
||||
The `Norm` trait now uses an associated type instead of a type parameter.
|
||||
Other similar trait changes are to be expected in the future, e.g., for the
|
||||
@ -27,8 +33,8 @@ longer unsafe. Instead, their name end with `_unchecked`. In particular:
|
||||
|
||||
### Added
|
||||
- A `Unit<T>` type that wraps normalized values. In particular,
|
||||
`UnitQuaternion<N>` is now replaced by `Unit<Quaternion<N>>`.
|
||||
- `.ln()`, `.exp()` and `.powf(..)` for quaternions.
|
||||
`UnitQuaternion<N>` is now an alias for `Unit<Quaternion<N>>`.
|
||||
- `.ln()`, `.exp()` and `.powf(..)` for quaternions and unit quaternions.
|
||||
- `::from_parts(...)` to build a quaternion from its scalar and vector
|
||||
parts.
|
||||
- The `Norm` trait now has a `try_normalize()` that returns `None` if the
|
||||
|
@ -59,7 +59,7 @@ impl<N: BaseFloat> Isometry3<N> {
|
||||
#[inline]
|
||||
pub fn new_observer_frame(eye: &Point3<N>, target: &Point3<N>, up: &Vector3<N>) -> Isometry3<N> {
|
||||
let new_rotation_matrix = Rotation3::new_observer_frame(&(*target - *eye), up);
|
||||
Isometry3::new_with_rotation_matrix(eye.to_vector(), new_rotation_matrix)
|
||||
Isometry3::from_rotation_matrix(eye.to_vector(), new_rotation_matrix)
|
||||
}
|
||||
|
||||
/// Builds a right-handed look-at view matrix.
|
||||
@ -77,7 +77,7 @@ impl<N: BaseFloat> Isometry3<N> {
|
||||
let rotation = Rotation3::look_at_rh(&(*target - *eye), up);
|
||||
let trans = rotation * (-*eye);
|
||||
|
||||
Isometry3::new_with_rotation_matrix(trans.to_vector(), rotation)
|
||||
Isometry3::from_rotation_matrix(trans.to_vector(), rotation)
|
||||
}
|
||||
|
||||
/// Builds a left-handed look-at view matrix.
|
||||
@ -95,7 +95,7 @@ impl<N: BaseFloat> Isometry3<N> {
|
||||
let rotation = Rotation3::look_at_lh(&(*target - *eye), up);
|
||||
let trans = rotation * (-*eye);
|
||||
|
||||
Isometry3::new_with_rotation_matrix(trans.to_vector(), rotation)
|
||||
Isometry3::from_rotation_matrix(trans.to_vector(), rotation)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ macro_rules! isometry_impl(
|
||||
|
||||
/// Creates a new isometry from a rotation matrix and a vector.
|
||||
#[inline]
|
||||
pub fn new_with_rotation_matrix(translation: $vector<N>, rotation: $rotmatrix<N>) -> $t<N> {
|
||||
pub fn from_rotation_matrix(translation: $vector<N>, rotation: $rotmatrix<N>) -> $t<N> {
|
||||
$t {
|
||||
rotation: rotation,
|
||||
translation: translation
|
||||
@ -48,7 +48,7 @@ macro_rules! isometry_impl(
|
||||
impl<N: BaseFloat> One for $t<N> {
|
||||
#[inline]
|
||||
fn one() -> $t<N> {
|
||||
$t::new_with_rotation_matrix(::zero(), ::one())
|
||||
$t::from_rotation_matrix(::zero(), ::one())
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ macro_rules! isometry_impl(
|
||||
|
||||
#[inline]
|
||||
fn mul(self, right: $t<N>) -> $t<N> {
|
||||
$t::new_with_rotation_matrix(
|
||||
$t::from_rotation_matrix(
|
||||
self.translation + self.rotation * right.translation,
|
||||
self.rotation * right.rotation)
|
||||
}
|
||||
@ -88,7 +88,7 @@ macro_rules! isometry_impl(
|
||||
|
||||
#[inline]
|
||||
fn mul(self, right: $rotmatrix<N>) -> $t<N> {
|
||||
$t::new_with_rotation_matrix(self.translation, self.rotation * right)
|
||||
$t::from_rotation_matrix(self.translation, self.rotation * right)
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ macro_rules! isometry_impl(
|
||||
|
||||
#[inline]
|
||||
fn mul(self, right: $t<N>) -> $t<N> {
|
||||
$t::new_with_rotation_matrix(
|
||||
$t::from_rotation_matrix(
|
||||
self * right.translation,
|
||||
self * right.rotation)
|
||||
}
|
||||
@ -164,7 +164,7 @@ macro_rules! isometry_impl(
|
||||
|
||||
#[inline]
|
||||
fn append_translation(&self, t: &$vector<N>) -> $t<N> {
|
||||
$t::new_with_rotation_matrix(*t + self.translation, self.rotation)
|
||||
$t::from_rotation_matrix(*t + self.translation, self.rotation)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -174,7 +174,7 @@ macro_rules! isometry_impl(
|
||||
|
||||
#[inline]
|
||||
fn prepend_translation(&self, t: &$vector<N>) -> $t<N> {
|
||||
$t::new_with_rotation_matrix(self.translation + self.rotation * *t, self.rotation)
|
||||
$t::from_rotation_matrix(self.translation + self.rotation * *t, self.rotation)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -230,7 +230,7 @@ macro_rules! isometry_impl(
|
||||
fn append_rotation(&self, rotation: &$rotvector<N>) -> $t<N> {
|
||||
let delta = $rotmatrix::new(*rotation);
|
||||
|
||||
$t::new_with_rotation_matrix(delta * self.translation, delta * self.rotation)
|
||||
$t::from_rotation_matrix(delta * self.translation, delta * self.rotation)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -244,7 +244,7 @@ macro_rules! isometry_impl(
|
||||
fn prepend_rotation(&self, rotation: &$rotvector<N>) -> $t<N> {
|
||||
let delta = $rotmatrix::new(*rotation);
|
||||
|
||||
$t::new_with_rotation_matrix(self.translation, self.rotation * delta)
|
||||
$t::from_rotation_matrix(self.translation, self.rotation * delta)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -435,7 +435,7 @@ macro_rules! isometry_impl(
|
||||
#[cfg(feature="arbitrary")]
|
||||
impl<N: Arbitrary + BaseFloat> Arbitrary for $t<N> {
|
||||
fn arbitrary<G: Gen>(g: &mut G) -> $t<N> {
|
||||
$t::new_with_rotation_matrix(
|
||||
$t::from_rotation_matrix(
|
||||
Arbitrary::arbitrary(g),
|
||||
Arbitrary::arbitrary(g)
|
||||
)
|
||||
|
@ -183,7 +183,7 @@ impl<N: BaseFloat> OrthographicMatrix3<N> {
|
||||
}
|
||||
|
||||
/// Creates a new orthographic projection matrix from an aspect ratio and the vertical field of view.
|
||||
pub fn new_with_fov(aspect: N, vfov: N, znear: N, zfar: N) -> OrthographicMatrix3<N> {
|
||||
pub fn from_fov(aspect: N, vfov: N, znear: N, zfar: N) -> OrthographicMatrix3<N> {
|
||||
assert!(znear < zfar, "The far plane must be farther than the near plane.");
|
||||
assert!(!::is_zero(&aspect));
|
||||
|
||||
@ -196,7 +196,7 @@ impl<N: BaseFloat> OrthographicMatrix3<N> {
|
||||
|
||||
/// Creates a new orthographic matrix from a 4D matrix.
|
||||
#[inline]
|
||||
pub fn new_with_matrix_unchecked(matrix: Matrix4<N>) -> OrthographicMatrix3<N> {
|
||||
pub fn from_matrix_unchecked(matrix: Matrix4<N>) -> OrthographicMatrix3<N> {
|
||||
OrthographicMatrix3 {
|
||||
matrix: matrix
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ impl<N: BaseFloat> PerspectiveMatrix3<N> {
|
||||
|
||||
/// Creates a new perspective projection matrix from a 4D matrix.
|
||||
#[inline]
|
||||
pub fn new_with_matrix_unchecked(matrix: Matrix4<N>) -> PerspectiveMatrix3<N> {
|
||||
pub fn from_matrix_unchecked(matrix: Matrix4<N>) -> PerspectiveMatrix3<N> {
|
||||
PerspectiveMatrix3 {
|
||||
matrix: matrix
|
||||
}
|
||||
|
@ -337,7 +337,7 @@ impl<N: BaseFloat> UnitQuaternion<N> {
|
||||
let jk = self.as_ref().j * self.as_ref().k * ::cast(2.0);
|
||||
let wi = self.as_ref().w * self.as_ref().i * ::cast(2.0);
|
||||
|
||||
Rotation3::new_with_matrix_unchecked(
|
||||
Rotation3::from_matrix_unchecked(
|
||||
Matrix3::new(
|
||||
ww + ii - jj - kk, ij - wk, wj + ik,
|
||||
wk + ij, ww - ii + jj - kk, jk - wi,
|
||||
|
@ -157,7 +157,7 @@ impl<N: BaseFloat> Rotation3<N> {
|
||||
}
|
||||
|
||||
/// Builds a rotation matrix from an orthogonal matrix.
|
||||
pub fn new_with_matrix_unchecked(matrix: Matrix3<N>) -> Rotation3<N> {
|
||||
pub fn from_matrix_unchecked(matrix: Matrix3<N>) -> Rotation3<N> {
|
||||
Rotation3 {
|
||||
submatrix: matrix
|
||||
}
|
||||
@ -166,12 +166,12 @@ impl<N: BaseFloat> Rotation3<N> {
|
||||
/// Creates a new rotation from Euler angles.
|
||||
///
|
||||
/// The primitive rotations are applied in order: 1 roll − 2 pitch − 3 yaw.
|
||||
pub fn new_with_euler_angles(roll: N, pitch: N, yaw: N) -> Rotation3<N> {
|
||||
pub fn from_euler_angles(roll: N, pitch: N, yaw: N) -> Rotation3<N> {
|
||||
let (sr, cr) = roll.sin_cos();
|
||||
let (sp, cp) = pitch.sin_cos();
|
||||
let (sy, cy) = yaw.sin_cos();
|
||||
|
||||
Rotation3::new_with_matrix_unchecked(
|
||||
Rotation3::from_matrix_unchecked(
|
||||
Matrix3::new(
|
||||
cy * cp, cy * sp * sr - sy * cr, cy * sp * cr + sy * sr,
|
||||
sy * cp, sy * sp * sr + cy * cr, sy * sp * cr - cy * sr,
|
||||
@ -198,7 +198,7 @@ impl<N: BaseFloat> Rotation3<N> {
|
||||
let xaxis = Norm::normalize(&Cross::cross(up, &zaxis));
|
||||
let yaxis = Norm::normalize(&Cross::cross(&zaxis, &xaxis));
|
||||
|
||||
Rotation3::new_with_matrix_unchecked(Matrix3::new(
|
||||
Rotation3::from_matrix_unchecked(Matrix3::new(
|
||||
xaxis.x, yaxis.x, zaxis.x,
|
||||
xaxis.y, yaxis.y, zaxis.y,
|
||||
xaxis.z, yaxis.z, zaxis.z))
|
||||
|
@ -29,12 +29,12 @@ macro_rules! similarity_impl(
|
||||
///
|
||||
/// The scale factor may be negative but not zero.
|
||||
#[inline]
|
||||
pub fn new_with_rotation_matrix(translation: $vector<N>, rotation: $rotation_matrix<N>, scale: N) -> $t<N> {
|
||||
pub fn from_rotation_matrix(translation: $vector<N>, rotation: $rotation_matrix<N>, scale: N) -> $t<N> {
|
||||
assert!(!scale.is_zero(), "A similarity transformation scale factor cannot be zero.");
|
||||
|
||||
$t {
|
||||
scale: scale,
|
||||
isometry: $isometry::new_with_rotation_matrix(translation, rotation)
|
||||
isometry: $isometry::from_rotation_matrix(translation, rotation)
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ macro_rules! similarity_impl(
|
||||
///
|
||||
/// The scale factor may be negative but not zero.
|
||||
#[inline]
|
||||
pub fn new_with_isometry(isometry: $isometry<N>, scale: N) -> $t<N> {
|
||||
pub fn from_isometry(isometry: $isometry<N>, scale: N) -> $t<N> {
|
||||
assert!(!scale.is_zero(), "A similarity transformation scale factor cannot be zero.");
|
||||
|
||||
$t {
|
||||
@ -80,7 +80,7 @@ macro_rules! similarity_impl(
|
||||
#[inline]
|
||||
pub fn append_scale(&self, s: &N) -> $t<N> {
|
||||
assert!(!s.is_zero(), "Cannot append a zero scale to a similarity transformation.");
|
||||
$t::new_with_rotation_matrix(self.isometry.translation * *s, self.isometry.rotation, self.scale * *s)
|
||||
$t::from_rotation_matrix(self.isometry.translation * *s, self.isometry.rotation, self.scale * *s)
|
||||
}
|
||||
|
||||
/// Prepends in-place a scale to this similarity transformation.
|
||||
@ -94,7 +94,7 @@ macro_rules! similarity_impl(
|
||||
#[inline]
|
||||
pub fn prepend_scale(&self, s: &N) -> $t<N> {
|
||||
assert!(!s.is_zero(), "A similarity transformation scale must not be zero.");
|
||||
$t::new_with_isometry(self.isometry, self.scale * *s)
|
||||
$t::from_isometry(self.isometry, self.scale * *s)
|
||||
}
|
||||
|
||||
/// Sets the scale of this similarity transformation.
|
||||
@ -113,7 +113,7 @@ macro_rules! similarity_impl(
|
||||
impl<N: BaseFloat> One for $t<N> {
|
||||
#[inline]
|
||||
fn one() -> $t<N> {
|
||||
$t::new_with_isometry(::one(), ::one())
|
||||
$t::from_isometry(::one(), ::one())
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ macro_rules! similarity_impl(
|
||||
|
||||
#[inline]
|
||||
fn mul(self, right: $t<N>) -> $t<N> {
|
||||
$t::new_with_rotation_matrix(
|
||||
$t::from_rotation_matrix(
|
||||
self.isometry.translation + self.isometry.rotation * (right.isometry.translation * self.scale),
|
||||
self.isometry.rotation * right.isometry.rotation,
|
||||
self.scale * right.scale)
|
||||
@ -191,7 +191,7 @@ macro_rules! similarity_impl(
|
||||
|
||||
#[inline]
|
||||
fn mul(self, right: $isometry<N>) -> $t<N> {
|
||||
$t::new_with_rotation_matrix(
|
||||
$t::from_rotation_matrix(
|
||||
self.isometry.translation + self.isometry.rotation * (right.translation * self.scale),
|
||||
self.isometry.rotation * right.rotation,
|
||||
self.scale)
|
||||
@ -211,7 +211,7 @@ macro_rules! similarity_impl(
|
||||
|
||||
#[inline]
|
||||
fn mul(self, right: $t<N>) -> $t<N> {
|
||||
$t::new_with_rotation_matrix(
|
||||
$t::from_rotation_matrix(
|
||||
self.translation + self.rotation * right.isometry.translation,
|
||||
self.rotation * right.isometry.rotation,
|
||||
right.scale)
|
||||
@ -228,7 +228,7 @@ macro_rules! similarity_impl(
|
||||
|
||||
#[inline]
|
||||
fn mul(self, right: $rotation_matrix<N>) -> $t<N> {
|
||||
$t::new_with_rotation_matrix(
|
||||
$t::from_rotation_matrix(
|
||||
self.isometry.translation,
|
||||
self.isometry.rotation * right,
|
||||
self.scale)
|
||||
@ -247,7 +247,7 @@ macro_rules! similarity_impl(
|
||||
|
||||
#[inline]
|
||||
fn mul(self, right: $t<N>) -> $t<N> {
|
||||
$t::new_with_rotation_matrix(
|
||||
$t::from_rotation_matrix(
|
||||
self * right.isometry.translation,
|
||||
self * right.isometry.rotation,
|
||||
right.scale)
|
||||
@ -389,7 +389,7 @@ macro_rules! similarity_impl(
|
||||
scale = rng.gen();
|
||||
}
|
||||
|
||||
$t::new_with_isometry(rng.gen(), scale)
|
||||
$t::from_isometry(rng.gen(), scale)
|
||||
}
|
||||
}
|
||||
|
||||
@ -402,7 +402,7 @@ macro_rules! similarity_impl(
|
||||
#[cfg(feature="arbitrary")]
|
||||
impl<N: Arbitrary + BaseFloat> Arbitrary for $t<N> {
|
||||
fn arbitrary<G: Gen>(g: &mut G) -> $t<N> {
|
||||
$t::new_with_isometry(
|
||||
$t::from_isometry(
|
||||
Arbitrary::arbitrary(g),
|
||||
Arbitrary::arbitrary(g)
|
||||
)
|
||||
|
@ -173,7 +173,7 @@ pub trait ApproxEq<Eps>: Sized {
|
||||
impl ApproxEq<f32> for f32 {
|
||||
#[inline]
|
||||
fn approx_epsilon(_: Option<f32>) -> f32 {
|
||||
f32::EPSILON * 10.0
|
||||
1.0e-6
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -204,7 +204,7 @@ impl ApproxEq<f32> for f32 {
|
||||
impl ApproxEq<f64> for f64 {
|
||||
#[inline]
|
||||
fn approx_epsilon(_: Option<f64>) -> f64 {
|
||||
f64::EPSILON * 10.0
|
||||
1.0e-6
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -9,7 +9,7 @@ fn test_quaternion_as_matrix() {
|
||||
for _ in 0usize .. 10000 {
|
||||
let axis_angle: Vector3<f64> = random();
|
||||
|
||||
assert!(na::approx_eq(&UnitQuaternion::new(axis_angle).to_rotation_matrix(), &Rotation3::new(axis_angle)))
|
||||
assert!(na::approx_eq(&UnitQuaternion::from_scaled_axis(axis_angle).to_rotation_matrix(), &Rotation3::new(axis_angle)))
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ fn test_quaternion_mul_vec_or_point_as_matrix() {
|
||||
let point: Point3<f64> = random();
|
||||
|
||||
let matrix = Rotation3::new(axis_angle);
|
||||
let quaternion = UnitQuaternion::new(axis_angle);
|
||||
let quaternion = UnitQuaternion::from_scaled_axis(axis_angle);
|
||||
|
||||
assert!(na::approx_eq(&(matrix * vector), &(quaternion * vector)));
|
||||
assert!(na::approx_eq(&(matrix * point), &(quaternion * point)));
|
||||
@ -39,8 +39,8 @@ fn test_quaternion_div_quaternion() {
|
||||
let r1 = Rotation3::new(axis_angle1);
|
||||
let r2 = na::inverse(&Rotation3::new(axis_angle2)).unwrap();
|
||||
|
||||
let q1 = UnitQuaternion::new(axis_angle1);
|
||||
let q2 = UnitQuaternion::new(axis_angle2);
|
||||
let q1 = UnitQuaternion::from_scaled_axis(axis_angle1);
|
||||
let q2 = UnitQuaternion::from_scaled_axis(axis_angle2);
|
||||
|
||||
assert!(na::approx_eq(&(q1 / q2).to_rotation_matrix(), &(r1 * r2)))
|
||||
}
|
||||
@ -51,7 +51,7 @@ fn test_quaternion_to_axis_angle() {
|
||||
for _ in 0usize .. 10000 {
|
||||
let axis_angle: Vector3<f64> = random();
|
||||
|
||||
let q = UnitQuaternion::new(axis_angle);
|
||||
let q = UnitQuaternion::from_scaled_axis(axis_angle);
|
||||
|
||||
println!("{:?} {:?}", q.rotation(), axis_angle);
|
||||
assert!(na::approx_eq(&q.rotation(), &axis_angle))
|
||||
@ -63,8 +63,8 @@ fn test_quaternion_euler_angles() {
|
||||
for _ in 0usize .. 10000 {
|
||||
let angles: Vector3<f64> = random();
|
||||
|
||||
let q = UnitQuaternion::new_with_euler_angles(angles.x, angles.y, angles.z);
|
||||
let m = Rotation3::new_with_euler_angles(angles.x, angles.y, angles.z);
|
||||
let q = UnitQuaternion::from_euler_angles(angles.x, angles.y, angles.z);
|
||||
let m = Rotation3::from_euler_angles(angles.x, angles.y, angles.z);
|
||||
|
||||
assert!(na::approx_eq(&q.to_rotation_matrix(), &m))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user