4 * Created on: Apr 20, 2012
15 bool AABB::Overlaps(const Shape &other, Vector &normal) const {
16 // This call reveals the real type of this shape by overloading and the
17 // other one via polymorphism.
18 if (other.Overlaps(*this, normal)) {
19 // Since the other shape's Overlaps() returns its own surface normal,
20 // it has to be inverted here.
28 bool AABB::Overlaps(const AABB &other, Vector &normal) const {
29 if (Bottom() <= other.Top()) return false;
30 if (other.Bottom() <= Top()) return false;
31 if (Right() <= other.Left()) return false;
32 if (other.Right() <= Left()) return false;
34 if (HorizontalOverlap(other)) {
35 if (Top() < other.Top()) {
36 normal = Vector(0, -1);
38 normal = Vector(0, 1);
41 if (Left() < other.Left()) {
42 normal = Vector(-1, 0);
44 normal = Vector(1, 0);
51 bool AABB::Overlaps(const Circle &other, Vector &normal) const {
52 if (other.Overlaps(*this, normal)) {
60 bool AABB::Overlaps(const FakeLens &other, Vector &normal) const {
61 if (other.Overlaps(*this, normal)) {
69 std::ostream &AABB::Write(std::ostream &out) const {
70 return out << "AABB(" << Width() << 'x' << Height() << '+' << X() << '+' << Y() << ')';
73 } /* namespace geometry */