Add another ray-sphere intersection unit test

This commit is contained in:
Matthew Gordon 2019-11-13 17:28:43 -05:00
parent 700de75337
commit 3c24a084b9
1 changed files with 8 additions and 1 deletions

View File

@ -175,12 +175,19 @@ mod tests {
} }
#[test] #[test]
fn ray_does_not_intersect_sphere() { fn ray_does_not_intersect_sphere_when_sphere_is_in_front() {
let r = Ray::new(Vector3::new(1.0, 2.0, 3.0), Vector3::new(0.0, 0.0, 1.0)); let r = Ray::new(Vector3::new(1.0, 2.0, 3.0), Vector3::new(0.0, 0.0, 1.0));
let s = Sphere::new(Vector3::new(-5.0, 1.5, 15.0), 5.0); let s = Sphere::new(Vector3::new(-5.0, 1.5, 15.0), 5.0);
assert_matches!(s.intersect(&r), None); assert_matches!(s.intersect(&r), None);
} }
#[test]
fn ray_does_not_intersect_sphere_when_sphere_is_behind() {
let r = Ray::new(Vector3::new(1.0, 2.0, 3.0), Vector3::new(0.0, 0.0, 1.0));
let s = Sphere::new(Vector3::new(1.5, 1.5, -15.0), 5.0);
assert_matches!(s.intersect(&r), None);
}
#[test] #[test]
fn ray_intersects_plane() { fn ray_intersects_plane() {
let r = Ray::new(Vector3::new(1.0, 2.0, 3.0), Vector3::new(-1.0, 0.0, 1.0)); let r = Ray::new(Vector3::new(1.0, 2.0, 3.0), Vector3::new(-1.0, 0.0, 1.0));