3 namespace JellyPhysics
{
6 AABB::AABB (const Vector2
&minPt
, const Vector2
&maxPt
) {
14 Min
= Max
= Vector2::Zero
;
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
;
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
);