From 95fa56d97749567cc8a2eeb7391a702ca43cc184 Mon Sep 17 00:00:00 2001 From: ketmar Date: Sat, 18 Jan 2014 19:59:52 +0200 Subject: [PATCH] cosmetix --- src/jelly/AABB.cpp | 105 +++++++++++++++++++++++++---------------------------- src/jelly/AABB.h | 69 ++++++++++++++++++----------------- 2 files changed, 85 insertions(+), 89 deletions(-) rewrite src/jelly/AABB.cpp (95%) rewrite src/jelly/AABB.h (85%) diff --git a/src/jelly/AABB.cpp b/src/jelly/AABB.cpp dissimilarity index 95% index 5196908..5e797a4 100644 --- a/src/jelly/AABB.cpp +++ b/src/jelly/AABB.cpp @@ -1,56 +1,49 @@ -#include "AABB.h" - -namespace JellyPhysics -{ - - AABB::AABB( const Vector2& minPt, const Vector2& maxPt ) - { - Min = minPt; - Max = maxPt; - Validity = Valid; - } - - void AABB::clear() - { - Min = Max = Vector2::Zero; - Validity = Invalid; - } - - void AABB::expandToInclude( const Vector2& pt ) - { - if (Validity == Valid) - { - if (pt.X < Min.X) { Min.X = pt.X; } - else if (pt.X > Max.X) { Max.X = pt.X; } - - if (pt.Y < Min.Y) { Min.Y = pt.Y; } - else if (pt.Y > Max.Y) { Max.Y = pt.Y; } - } - else - { - Min = Max = pt; - Validity = Valid; - } - } - - void AABB::expandToInclude( const AABB& aabb ) - { - expandToInclude( aabb.Min ); - expandToInclude( aabb.Max ); - } - - bool AABB::contains( const Vector2& pt ) const - { - if (Validity == Invalid) { return false; } - - return ((pt.X >= Min.X) && (pt.X <= Max.X) && (pt.Y >= Min.Y) && (pt.Y <= Max.Y)); - } - - bool AABB::intersects( const AABB& box ) const - { - bool overlapX = ((Min.X <= box.Max.X) && (Max.X >= box.Min.X)); - bool overlapY = ((Min.Y <= box.Max.Y) && (Max.Y >= box.Min.Y)); - - return (overlapX && overlapY); - } -} +#include "AABB.h" + +namespace JellyPhysics { + + +AABB::AABB (const Vector2 &minPt, const Vector2 &maxPt) { + Min = minPt; + Max = maxPt; + Validity = Valid; +} + + +void AABB::clear () { + Min = Max = Vector2::Zero; + Validity = Invalid; +} + + +void AABB::expandToInclude (const Vector2 &pt) { + if (Validity == Valid) { + if (pt.X < Min.X) Min.X = pt.X; else if (pt.X > Max.X) Max.X = pt.X; + if (pt.Y < Min.Y) Min.Y = pt.Y; else if (pt.Y > Max.Y) Max.Y = pt.Y; + } else { + Min = Max = pt; + Validity = Valid; + } +} + + +void AABB::expandToInclude (const AABB &aabb) { + expandToInclude(aabb.Min); + expandToInclude(aabb.Max); +} + + +bool AABB::contains (const Vector2 &pt) const { + if (Validity == Invalid) return false; + return (pt.X >= Min.X && pt.X <= Max.X && pt.Y >= Min.Y && pt.Y <= Max.Y); +} + + +bool AABB::intersects (const AABB &box)const { + bool overlapX = (Min.X <= box.Max.X && Max.X >= box.Min.X); + bool overlapY = (Min.Y <= box.Max.Y && Max.Y >= box.Min.Y); + return (overlapX && overlapY); +} + + +} diff --git a/src/jelly/AABB.h b/src/jelly/AABB.h dissimilarity index 85% index 67ae269..5cf3899 100644 --- a/src/jelly/AABB.h +++ b/src/jelly/AABB.h @@ -1,33 +1,36 @@ -#ifndef _AABB_H -#define _AABB_H - -#include "Vector2.h" - -namespace JellyPhysics { - - class AABB - { - public: - enum PointValidity { Invalid, Valid }; - - Vector2 Min; - Vector2 Max; - PointValidity Validity; - - AABB() : Min(Vector2::Zero), Max(Vector2::Zero), Validity(Invalid) { } - AABB( const Vector2& minPt, const Vector2& maxPt ); - - void clear(); - - void expandToInclude( const Vector2& pt ); - void expandToInclude( const AABB& aabb ); - - bool contains( const Vector2& pt ) const; - bool intersects( const AABB& box ) const; - - Vector2 getSize() const { return Max - Min; } - - }; -} - -#endif // _AABB_H +#ifndef _AABB_H +#define _AABB_H + +#include "Vector2.h" + + +namespace JellyPhysics { + +class AABB { +public: + enum PointValidity { Invalid, Valid }; + +public: + AABB () : Min(Vector2::Zero), Max(Vector2::Zero), Validity(Invalid) {} + AABB (const Vector2 &minPt, const Vector2 &maxPt); + + void clear (); + + void expandToInclude (const Vector2 &pt); + void expandToInclude (const AABB &aabb); + + bool contains (const Vector2 &pt) const; + bool intersects (const AABB &box) const; + + Vector2 getSize () const { return Max-Min; } + +public: + Vector2 Min; + Vector2 Max; + PointValidity Validity; +}; + +} + + +#endif -- 2.11.4.GIT