Translate method for AABBs
This commit is contained in:
parent
6ac1f09750
commit
ff9fc767d4
2 changed files with 8 additions and 0 deletions
|
@ -51,6 +51,11 @@ pub trait Aabb
|
||||||
let mx : P = build(|i| self.max().i(i).max(p.i(i)));
|
let mx : P = build(|i| self.max().i(i).max(p.i(i)));
|
||||||
Aabb::new(&mn, &mx)
|
Aabb::new(&mn, &mx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns a new AABB that has its points translated by the given vector.
|
||||||
|
fn translate(&self, v: &V) -> Self {
|
||||||
|
Aabb::new(&self.min().add_v(v), &self.max().add_v(v))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, Eq)]
|
#[deriving(Clone, Eq)]
|
||||||
|
|
|
@ -35,4 +35,7 @@ fn test_aabb() {
|
||||||
assert!(!aabb.contains(&Point3::new(10, 30, 5)));
|
assert!(!aabb.contains(&Point3::new(10, 30, 5)));
|
||||||
assert!(aabb.contains(&Point3::new(-20, -10, -5)));
|
assert!(aabb.contains(&Point3::new(-20, -10, -5)));
|
||||||
assert!(!aabb.contains(&Point3::new(-21, -11, -6)));
|
assert!(!aabb.contains(&Point3::new(-21, -11, -6)));
|
||||||
|
|
||||||
|
assert_eq!(aabb.translate(&Vec3::new(1, 2, 3)),
|
||||||
|
Aabb3::new(&Point3::new(-19, 32, 8), &Point3::new(11, -8, -2)));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue