1
0
Fork 0

Added a getBounds() method to get the bounding rectangle for the line.

This commit is contained in:
david 2002-07-23 01:31:58 +00:00
parent f30ffc0d1f
commit 1f2d16fe6c
2 changed files with 34 additions and 0 deletions

View file

@ -43,4 +43,31 @@ Line::addPoint (const Point3D &point)
_points.push_back(point);
}
const Rectangle
Line::getBounds () const
{
Point3D min;
Point3D max;
int nPoints = _points.size();
for (int i = 0; i < nPoints; i++) {
if (i == 0) {
min = max = _points[i];
} else {
if (_points[i].x() < min.x())
min.setx(_points[i].x());
if (_points[i].x() > max.x())
max.setx(_points[i].x());
if (_points[i].y() < min.y())
min.sety(_points[i].y());
if (_points[i].y() > max.y())
max.sety(_points[i].y());
}
return Rectangle(min, max);
}
Rectangle bounds;
return bounds;
}
// end of line.cxx

View file

@ -76,6 +76,13 @@ public:
*/
virtual void addPoint (const Point3D &point);
/**
* Get the bounding rectangle for the line.
*
* @return The bounding rectangle.
*/
virtual const Rectangle getBounds () const;
private:
vector<Point3D> _points;
};