1 #ifndef JVGS_MATH_BOUNDINGBOX_H 2 #define JVGS_MATH_BOUNDINGBOX_H 3 4 #include "Vector2D.h" 5 #include <vector> 6 7 namespace jvgs 8 { 9 namespace math 10 { 11 class BoundingBox 12 { 13 private: 14 Vector2D topLeft, bottomRight; 15 16 public: 17 /** Constructor. 18 * @param topLeft Top left of the bounding box. 19 * @param bottomRight Bottom right of the bounding box. 20 */ 21 BoundingBox(const Vector2D &topLeft = Vector2D(), 22 const Vector2D &bottomRight = Vector2D()); 23 24 /** Constructor. Create the smallest bounding box fitting 25 * around a number of points. 26 * @param points Vectors to fit around. 27 */ 28 BoundingBox(std::vector<Vector2D> *points); 29 30 /** Constructor. Join two bounding boxes so we get a bounding 31 * box containing both bounding boxes. 32 * @param b1 First bounding box. 33 * @param b2 Second bounding box. 34 */ 35 BoundingBox(const BoundingBox &b1, const BoundingBox &b2); 36 37 /** Destructor. 38 */ 39 virtual ~BoundingBox(); 40 41 /** Get the top left point. 42 * @return The top left point. 43 */ 44 virtual const Vector2D &getTopLeft() const; 45 46 /** Get the bottom right point. 47 * @return The bottom right point. 48 */ 49 virtual const Vector2D &getBottomRight() const; 50 51 /** Checks if a given point lies inside this bounding box. 52 * @param point Point to check. 53 * @return If this point lies inside this bounding box. 54 */ 55 virtual bool hasPoint(const Vector2D &point) const; 56 57 /** Check for intersection with another bounding box. 58 * @param other BoundingBox to check intersection with. 59 * @return If there is any intersection of the two boxes. 60 */ 61 virtual bool intersectsWith(BoundingBox *other, 62 const Vector2D &vel1, const Vector2D &vel2) const; 63 64 /** Check for intersection with another bounding box. 65 * @param other BoundingBox to check intersection with. 66 * @param vel1 Velocity of this bounding box. 67 * @param vel2 Velocity of the other bounding box. 68 * @return If there is an intersection of the boxes. 69 */ 70 virtual bool intersectsWith(BoundingBox *other) const; 71 72 /** Check if this bounding box lays completely in another 73 * bounding box. 74 * @param other BoundingBox to lay in. 75 * @return If this BoundingBox lays completely in the other. 76 */ 77 virtual bool completelyIn(BoundingBox *other) const; 78 }; 79 } 80 } 81 82 #endif 83