Skip to content

Commit

Permalink
Matrix::transform_point: correctly take the normalization term into a…
Browse files Browse the repository at this point in the history
…ccount.

Fix #640
  • Loading branch information
sebcrozet committed Aug 27, 2019
1 parent e170729 commit cfb6542
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/base/cg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,10 @@ where DefaultAllocator: Allocator<N, D, D>
+ unsafe { *self.get_unchecked((D::dim() - 1, D::dim() - 1)) };

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

transform * pt + translation
}
}

Expand Down
15 changes: 14 additions & 1 deletion tests/geometry/projection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use na::{Orthographic3, Perspective3};
use na::{Orthographic3, Perspective3, Point3};

#[test]
fn perspective_inverse() {
Expand All @@ -20,6 +20,19 @@ fn orthographic_inverse() {
assert!(id.is_identity(1.0e-7));
}

#[test]
fn perspective_matrix_point_transformation() {
// https://github.com/rustsim/nalgebra/issues/640
let proj = Perspective3::new(4.0 / 3.0, 90.0, 0.1, 100.0);
let perspective_inv = proj.as_matrix().try_inverse().unwrap();
let some_point = Point3::new(1.0, 2.0, 0.0);

assert_eq!(
perspective_inv.transform_point(&some_point),
Point3::from_homogeneous(perspective_inv * some_point.coords.push(1.0)).unwrap()
);
}

#[cfg(feature = "arbitrary")]
mod quickcheck_tests {
use na::{Orthographic3, Perspective3, Point3};
Expand Down

0 comments on commit cfb6542

Please sign in to comment.