From 1f2d16fe6ca110ac82e4bc718ccd825e3d7dbb4f Mon Sep 17 00:00:00 2001
From: david <david>
Date: Tue, 23 Jul 2002 01:31:58 +0000
Subject: [PATCH] Added a getBounds() method to get the bounding rectangle for
 the line.

---
 src/Lib/Geometry/line.cxx | 27 +++++++++++++++++++++++++++
 src/Lib/Geometry/line.hxx |  7 +++++++
 2 files changed, 34 insertions(+)

diff --git a/src/Lib/Geometry/line.cxx b/src/Lib/Geometry/line.cxx
index 8aa45dab..aed88017 100644
--- a/src/Lib/Geometry/line.cxx
+++ b/src/Lib/Geometry/line.cxx
@@ -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
diff --git a/src/Lib/Geometry/line.hxx b/src/Lib/Geometry/line.hxx
index 84094cb2..24e778ac 100644
--- a/src/Lib/Geometry/line.hxx
+++ b/src/Lib/Geometry/line.hxx
@@ -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;
 };