1
0
Fork 0

Convert Rectangle function to SGGeod

This commit is contained in:
Christian Schmitt 2012-10-09 20:25:00 +02:00
parent f3f6cd50f1
commit 4d3f1efd30
5 changed files with 53 additions and 54 deletions
src
Airports/GenAirports850
Lib/Geometry

View file

@ -213,18 +213,18 @@ int main(int argc, char **argv)
else if ( arg.find("--chunk=") == 0 ) else if ( arg.find("--chunk=") == 0 )
{ {
tg::Rectangle rectangle = tg::parseChunk(arg.substr(8).c_str(), 10.0); tg::Rectangle rectangle = tg::parseChunk(arg.substr(8).c_str(), 10.0);
min_lon = rectangle.getMin().x(); min_lon = rectangle.getMin().getLongitudeDeg();
min_lat = rectangle.getMin().y(); min_lat = rectangle.getMin().getLatitudeDeg();
max_lon = rectangle.getMax().x(); max_lon = rectangle.getMax().getLongitudeDeg();
max_lat = rectangle.getMax().y(); max_lat = rectangle.getMax().getLatitudeDeg();
} }
else if ( arg.find("--tile=") == 0 ) else if ( arg.find("--tile=") == 0 )
{ {
tg::Rectangle rectangle = tg::parseTile(arg.substr(7).c_str()); tg::Rectangle rectangle = tg::parseTile(arg.substr(7).c_str());
min_lon = rectangle.getMin().x(); min_lon = rectangle.getMin().getLongitudeDeg();
min_lat = rectangle.getMin().y(); min_lat = rectangle.getMin().getLatitudeDeg();
max_lon = rectangle.getMax().x(); max_lon = rectangle.getMax().getLongitudeDeg();
max_lat = rectangle.getMax().y(); max_lat = rectangle.getMax().getLatitudeDeg();
} }
else if ( arg.find("--airport=") == 0 ) else if ( arg.find("--airport=") == 0 )
{ {

View file

@ -51,22 +51,22 @@ Line::addPoint (const Point3D &point)
Rectangle Rectangle
Line::getBounds () const Line::getBounds () const
{ {
Point3D min; SGGeod min;
Point3D max; SGGeod max;
int nPoints = _points.size(); int nPoints = _points.size();
for (int i = 0; i < nPoints; i++) { for (int i = 0; i < nPoints; i++) {
if (i == 0) { if (i == 0) {
min = max = _points[i]; min = max = _points[i].toSGGeod();
} else { } else {
if (_points[i].x() < min.x()) if (_points[i].x() < min.getLongitudeDeg())
min.setx(_points[i].x()); min.setLongitudeDeg(_points[i].x());
if (_points[i].x() > max.x()) if (_points[i].x() > max.getLongitudeDeg())
max.setx(_points[i].x()); max.setLongitudeDeg(_points[i].x());
if (_points[i].y() < min.y()) if (_points[i].y() < min.getLatitudeDeg())
min.sety(_points[i].y()); min.setLatitudeDeg(_points[i].y());
if (_points[i].y() > max.y()) if (_points[i].y() > max.getLatitudeDeg())
max.sety(_points[i].y()); max.setLatitudeDeg(_points[i].y());
} }
} }

View file

@ -18,7 +18,7 @@ Rectangle::Rectangle (const Rectangle &r)
{ {
} }
Rectangle::Rectangle (const Point3D &min, const Point3D &max) Rectangle::Rectangle (const SGGeod &min, const SGGeod &max)
: _min(min), : _min(min),
_max(max) _max(max)
{ {
@ -29,13 +29,13 @@ Rectangle::~Rectangle ()
} }
void void
Rectangle::setMin (const Point3D &p) Rectangle::setMin (const SGGeod &p)
{ {
_min = p; _min = p;
} }
void void
Rectangle::setMax (const Point3D &p) Rectangle::setMax (const SGGeod &p)
{ {
_max = p; _max = p;
} }
@ -44,35 +44,35 @@ void
Rectangle::sanify () Rectangle::sanify ()
{ {
double tmp; double tmp;
if (_min.x() > _max.x()) { if (_min.getLongitudeDeg() > _max.getLongitudeDeg()) {
tmp = _min.x(); tmp = _min.getLongitudeDeg();
_min.setx(_max.x()); _min.setLongitudeDeg(_max.getLongitudeDeg());
_max.setx(tmp); _max.setLongitudeDeg(tmp);
} }
if (_min.y() > _max.y()) { if (_min.getLatitudeDeg() > _max.getLatitudeDeg()) {
tmp = _min.y(); tmp = _min.getLatitudeDeg();
_min.sety(_max.y()); _min.setLatitudeDeg(_max.getLatitudeDeg());
_max.sety(tmp); _max.setLatitudeDeg(tmp);
} }
} }
bool bool
Rectangle::isInside (const Point3D &p) const Rectangle::isInside (const SGGeod &p) const
{ {
return ((p.x() >= _min.x() && p.x() <= _max.x()) && return ((p.getLongitudeDeg() >= _min.getLongitudeDeg() && p.getLongitudeDeg() <= _max.getLongitudeDeg()) &&
(p.y() >= _min.y() && p.y() <= _max.y())); (p.getLatitudeDeg() >= _min.getLatitudeDeg() && p.getLatitudeDeg() <= _max.getLatitudeDeg()));
} }
bool bool
Rectangle::isOverlapping (const Rectangle &r) const Rectangle::isOverlapping (const Rectangle &r) const
{ {
const Point3D &min = r.getMin(); const SGGeod &min = r.getMin();
const Point3D &max = r.getMax(); const SGGeod &max = r.getMax();
return ((max.x() >= _min.x()) && (min.x() <= _max.x()) && return ((max.getLongitudeDeg() >= _min.getLongitudeDeg()) && (min.getLongitudeDeg() <= _max.getLongitudeDeg()) &&
(max.y() >= _min.y()) && (min.y() <= _max.y())); (max.getLatitudeDeg() >= _min.getLatitudeDeg()) && (min.getLatitudeDeg() <= _max.getLatitudeDeg()));
} }
const TGPolygon /*const TGPolygon
Rectangle::toPoly () const Rectangle::toPoly () const
{ {
TGPolygon poly; TGPolygon poly;
@ -81,7 +81,7 @@ Rectangle::toPoly () const
poly.add_node(0, _max); poly.add_node(0, _max);
poly.add_node(0, Point3D(_min.x(), _max.y(), 0)); poly.add_node(0, Point3D(_min.x(), _max.y(), 0));
return poly; return poly;
} }*/
}; };

View file

@ -12,7 +12,6 @@
#endif #endif
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <Geometry/point3d.hxx>
#include <Polygon/polygon.hxx> #include <Polygon/polygon.hxx>
@ -45,7 +44,7 @@ public:
/** /**
* Convenience constructor. * Convenience constructor.
*/ */
Rectangle (const Point3D &min, const Point3D &max); Rectangle (const SGGeod& min, const SGGeod& max);
/** /**
* Destructor. * Destructor.
@ -57,42 +56,42 @@ public:
* *
* @return The top-left vertex. * @return The top-left vertex.
*/ */
virtual const Point3D &getMin () const { return _min; } virtual const SGGeod &getMin () const { return _min; }
/** /**
* Get the maximum (bottom right) corner of the rectangle. * Get the maximum (bottom right) corner of the rectangle.
* *
* @return The bottom-right vertex. * @return The bottom-right vertex.
*/ */
virtual const Point3D &getMax () const { return _max; } virtual const SGGeod &getMax () const { return _max; }
/** /**
* Get the minimum (top left) corner of the rectangle. * Get the minimum (top left) corner of the rectangle.
* *
* @return The top-left vertex. * @return The top-left vertex.
*/ */
virtual Point3D &getMin () { return _min; } virtual SGGeod &getMin () { return _min; }
/** /**
* Get the maximum (bottom right) corner of the rectangle. * Get the maximum (bottom right) corner of the rectangle.
* *
* @return The bottom-right vertex. * @return The bottom-right vertex.
*/ */
virtual Point3D &getMax () { return _max; } virtual SGGeod &getMax () { return _max; }
/** /**
* Set the minimum (top-left) corner of the rectangle. * Set the minimum (top-left) corner of the rectangle.
* *
* @param p The top-left vertex. * @param p The top-left vertex.
*/ */
virtual void setMin (const Point3D &p); virtual void setMin (const SGGeod& p);
/** /**
* Set the maximum (bottom-right) corner of the rectangle. * Set the maximum (bottom-right) corner of the rectangle.
* *
* @param p The bottom-right vertex. * @param p The bottom-right vertex.
*/ */
virtual void setMax (const Point3D &p); virtual void setMax (const SGGeod& p);
/** /**
* Make the rectangle sane. * Make the rectangle sane.
@ -110,7 +109,7 @@ public:
* @return true if the point is inside or on the boundary of the * @return true if the point is inside or on the boundary of the
* rectangle, false if it is outside. * rectangle, false if it is outside.
*/ */
virtual bool isInside (const Point3D &p) const; virtual bool isInside (const SGGeod& p) const;
/** /**
* Test whether this rectangle overlaps with another one. * Test whether this rectangle overlaps with another one.
@ -126,11 +125,11 @@ public:
* *
* @return A four-vertex polygon representing this rectangle. * @return A four-vertex polygon representing this rectangle.
*/ */
virtual const TGPolygon toPoly () const; // virtual const TGPolygon toPoly () const;
private: private:
Point3D _min; SGGeod _min;
Point3D _max; SGGeod _max;
}; };
}; };

View file

@ -804,7 +804,7 @@ makeBounds (const TGPolygon &polygon)
} }
} }
} }
return Rectangle(Point3D(min_x, min_y, 0), Point3D(max_x, max_y, 0)); return Rectangle(SGGeod::fromDeg(min_x, min_y), SGGeod::fromDeg(max_x, max_y));
} }
@ -836,8 +836,8 @@ parseChunk (const string &s, double delta)
double x = atoi(s.substr(1,3).c_str()) * x_factor; double x = atoi(s.substr(1,3).c_str()) * x_factor;
double y = atoi(s.substr(5).c_str()) * y_factor; double y = atoi(s.substr(5).c_str()) * y_factor;
bounds.setMin(Point3D(x, y, 0)); bounds.setMin(SGGeod::fromDeg(x, y));
bounds.setMax(Point3D(x + delta, y + delta, 0)); bounds.setMax(SGGeod::fromDeg(x + delta, y + delta));
return bounds; return bounds;
} }