7 /** This class represents a rectangle.
8 * (Implementation Note) We're using upper left and lower right point instead of
9 * upper left and width/height here, because that makes the collision dectection
10 * a little bit efficienter.
18 Rect(const Vector& np1, const Vector& np2)
23 Rect(float x1, float y1, float x2, float y2)
24 : p1(x1, y1), p2(x2, y2)
26 assert(p1.x <= p2.x && p1.y <= p2.y);
29 float get_width() const
30 { return p2.x - p1.x; }
32 float get_height() const
33 { return p2.y - p1.y; }
35 Vector get_middle() const
36 { return Vector((p1.x+p2.x)/2, (p1.y+p2.y)/2); }
38 void set_pos(const Vector& v)
43 void set_height(float height)
47 void set_width(float width)
51 void set_size(float width, float height)
57 void move(const Vector& v)
63 bool inside(const Vector& v) const
65 return v.x >= p1.x && v.y >= p1.y && v.x < p2.x && v.y < p2.y;
67 bool inside(const Rect& other) const
69 if(p1.x >= other.p2.x || other.p1.x >= p2.x)
71 if(p1.y >= other.p2.y || other.p1.y >= p2.y)
77 // leave these 2 public to safe the headaches of set/get functions for such