cosmetix
[k8-jellyphysics.git] / src / jelly / AABB.cpp
blob5e797a48e053a439b3049c9dea30bebd9c98dd3d
1 #include "AABB.h"
3 namespace JellyPhysics {
6 AABB::AABB (const Vector2 &minPt, const Vector2 &maxPt) {
7 Min = minPt;
8 Max = maxPt;
9 Validity = Valid;
13 void AABB::clear () {
14 Min = Max = Vector2::Zero;
15 Validity = Invalid;
19 void AABB::expandToInclude (const Vector2 &pt) {
20 if (Validity == Valid) {
21 if (pt.X < Min.X) Min.X = pt.X; else if (pt.X > Max.X) Max.X = pt.X;
22 if (pt.Y < Min.Y) Min.Y = pt.Y; else if (pt.Y > Max.Y) Max.Y = pt.Y;
23 } else {
24 Min = Max = pt;
25 Validity = Valid;
30 void AABB::expandToInclude (const AABB &aabb) {
31 expandToInclude(aabb.Min);
32 expandToInclude(aabb.Max);
36 bool AABB::contains (const Vector2 &pt) const {
37 if (Validity == Invalid) return false;
38 return (pt.X >= Min.X && pt.X <= Max.X && pt.Y >= Min.Y && pt.Y <= Max.Y);
42 bool AABB::intersects (const AABB &box)const {
43 bool overlapX = (Min.X <= box.Max.X && Max.X >= box.Min.X);
44 bool overlapY = (Min.Y <= box.Max.Y && Max.Y >= box.Min.Y);
45 return (overlapX && overlapY);