Added a convenience constructor, non-const accessors, and an
isOverlapping method to test for overlap with another rectangle.
This commit is contained in:
parent
1f2d16fe6c
commit
4d37243a5b
2 changed files with 43 additions and 0 deletions
|
@ -16,6 +16,12 @@ Rectangle::Rectangle (const Rectangle &r)
|
|||
{
|
||||
}
|
||||
|
||||
Rectangle::Rectangle (const Point3D &min, const Point3D &max)
|
||||
: _min(min),
|
||||
_max(max)
|
||||
{
|
||||
}
|
||||
|
||||
Rectangle::~Rectangle ()
|
||||
{
|
||||
}
|
||||
|
@ -55,4 +61,13 @@ Rectangle::isInside (const Point3D &p) const
|
|||
(p.y() >= _min.y() && p.y() <= _max.y()));
|
||||
}
|
||||
|
||||
bool
|
||||
Rectangle::isOverlapping (const Rectangle &r) const
|
||||
{
|
||||
const Point3D &min = r.getMin();
|
||||
const Point3D &max = r.getMax();
|
||||
return ((max.x() >= _min.x()) && (min.x() <= _max.x()) &&
|
||||
(max.y() >= _min.y()) && (min.y() <= _max.y()));
|
||||
}
|
||||
|
||||
// end of rectangle.cxx
|
||||
|
|
|
@ -39,6 +39,11 @@ public:
|
|||
*/
|
||||
Rectangle (const Rectangle &r);
|
||||
|
||||
/**
|
||||
* Convenience constructor.
|
||||
*/
|
||||
Rectangle (const Point3D &min, const Point3D &max);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
|
@ -58,6 +63,20 @@ public:
|
|||
*/
|
||||
virtual const Point3D &getMax () const { return _max; }
|
||||
|
||||
/**
|
||||
* Get the minimum (top left) corner of the rectangle.
|
||||
*
|
||||
* @return The top-left vertex.
|
||||
*/
|
||||
virtual Point3D &getMin () { return _min; }
|
||||
|
||||
/**
|
||||
* Get the maximum (bottom right) corner of the rectangle.
|
||||
*
|
||||
* @return The bottom-right vertex.
|
||||
*/
|
||||
virtual Point3D &getMax () { return _max; }
|
||||
|
||||
/**
|
||||
* Set the minimum (top-left) corner of the rectangle.
|
||||
*
|
||||
|
@ -90,6 +109,15 @@ public:
|
|||
*/
|
||||
virtual bool isInside (const Point3D &p) const;
|
||||
|
||||
/**
|
||||
* Test whether this rectangle overlaps with another one.
|
||||
*
|
||||
* @param r The rectangle to test.
|
||||
* @return true if the rectangle is touching or overlapping, false
|
||||
* otherwise.
|
||||
*/
|
||||
virtual bool isOverlapping (const Rectangle &r) const;
|
||||
|
||||
private:
|
||||
Point3D _min;
|
||||
Point3D _max;
|
||||
|
|
Loading…
Add table
Reference in a new issue