1
0
Fork 0

Added a makeBounds function to get a bounding rectangle for a polygon.

This commit is contained in:
david 2002-08-03 14:00:26 +00:00
parent 8b990aa02a
commit 79d653b597
2 changed files with 35 additions and 0 deletions

View file

@ -145,6 +145,32 @@ makePolygon (const Line &line, int width, FGPolygon &polygon)
}
Rectangle
makeBounds (const FGPolygon &polygon)
{
double min_x, min_y, max_x, max_y;
for (int i = 0; i < polygon.contours(); i++) {
for (int j = 0; j < polygon.contour_size(i); j++) {
Point3D p = polygon.get_pt(i, j);
if (i == 0 && j == 0) {
min_x = max_x = p.x();
min_y = max_y = p.y();
} else {
if (min_x > p.x())
min_x = p.x();
if (max_x < p.x())
max_x = p.x();
if (min_y > p.y())
min_y = p.y();
if (max_y < p.y())
max_y = p.y();
}
}
}
return Rectangle(Point3D(min_x, min_y, 0), Point3D(max_x, max_y, 0));
}
Rectangle
parseChunk (const string &s)
{

View file

@ -87,6 +87,15 @@ void makePolygon (const Point3D &p, int width, FGPolygon &polygon);
void makePolygon (const Line &line, int width, FGPolygon &polygon);
/**
* Make a 2D bounding rectangle for a polygon.
*
* @param polygon The polygon to make the rectangle for.
* @return The bounding rectangle.
*/
Rectangle makeBounds (const FGPolygon &polygon);
/**
* Parse a chunk string (like "w080n40") into a rectangle.
*