Test chained transformations

This commit is contained in:
Savanni D'Gerinel 2024-06-10 09:40:15 -04:00
parent a2aa132886
commit 7be0baba53
1 changed files with 27 additions and 0 deletions

View File

@ -189,4 +189,31 @@ mod tests {
let p = Point::new(2., 3., 4.); let p = Point::new(2., 3., 4.);
assert_eq!(transform * p, Point::new(2., 3., 7.)); assert_eq!(transform * p, Point::new(2., 3., 7.));
} }
#[test]
fn individual_transformations_are_applied_in_sequence() {
let p = Point::new(1., 0., 1.);
let rotation = rotation_x(PI / 2.);
let scale = scaling(5., 5., 5.);
let translate = translation(10., 5., 7.);
let p2 = rotation * p;
assert_eq!(p2, Point::new(1., -1., 0.));
let p3 = scale * p2;
assert_eq!(p3, Point::new(5., -5., 0.));
let p4 = translate * p3;
assert_eq!(p4, Point::new(15., 0., 7.));
}
#[test]
fn chained_translations() {
let p = Point::new(1., 0., 1.);
let rotation = rotation_x(PI / 2.);
let scale = scaling(5., 5., 5.);
let translate = translation(10., 5., 7.);
let tr = translate * scale * rotation;
assert_eq!(tr * p, Point::new(15., 0., 7.));
}
} }