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

View file

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

View file

@ -51,22 +51,22 @@ Line::addPoint (const Point3D &point)
Rectangle
Line::getBounds () const
{
Point3D min;
Point3D max;
SGGeod min;
SGGeod max;
int nPoints = _points.size();
for (int i = 0; i < nPoints; i++) {
if (i == 0) {
min = max = _points[i];
min = max = _points[i].toSGGeod();
} 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());
if (_points[i].x() < min.getLongitudeDeg())
min.setLongitudeDeg(_points[i].x());
if (_points[i].x() > max.getLongitudeDeg())
max.setLongitudeDeg(_points[i].x());
if (_points[i].y() < min.getLatitudeDeg())
min.setLatitudeDeg(_points[i].y());
if (_points[i].y() > max.getLatitudeDeg())
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),
_max(max)
{
@ -29,13 +29,13 @@ Rectangle::~Rectangle ()
}
void
Rectangle::setMin (const Point3D &p)
Rectangle::setMin (const SGGeod &p)
{
_min = p;
}
void
Rectangle::setMax (const Point3D &p)
Rectangle::setMax (const SGGeod &p)
{
_max = p;
}
@ -44,35 +44,35 @@ void
Rectangle::sanify ()
{
double tmp;
if (_min.x() > _max.x()) {
tmp = _min.x();
_min.setx(_max.x());
_max.setx(tmp);
if (_min.getLongitudeDeg() > _max.getLongitudeDeg()) {
tmp = _min.getLongitudeDeg();
_min.setLongitudeDeg(_max.getLongitudeDeg());
_max.setLongitudeDeg(tmp);
}
if (_min.y() > _max.y()) {
tmp = _min.y();
_min.sety(_max.y());
_max.sety(tmp);
if (_min.getLatitudeDeg() > _max.getLatitudeDeg()) {
tmp = _min.getLatitudeDeg();
_min.setLatitudeDeg(_max.getLatitudeDeg());
_max.setLatitudeDeg(tmp);
}
}
bool
Rectangle::isInside (const Point3D &p) const
Rectangle::isInside (const SGGeod &p) const
{
return ((p.x() >= _min.x() && p.x() <= _max.x()) &&
(p.y() >= _min.y() && p.y() <= _max.y()));
return ((p.getLongitudeDeg() >= _min.getLongitudeDeg() && p.getLongitudeDeg() <= _max.getLongitudeDeg()) &&
(p.getLatitudeDeg() >= _min.getLatitudeDeg() && p.getLatitudeDeg() <= _max.getLatitudeDeg()));
}
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()));
const SGGeod &min = r.getMin();
const SGGeod &max = r.getMax();
return ((max.getLongitudeDeg() >= _min.getLongitudeDeg()) && (min.getLongitudeDeg() <= _max.getLongitudeDeg()) &&
(max.getLatitudeDeg() >= _min.getLatitudeDeg()) && (min.getLatitudeDeg() <= _max.getLatitudeDeg()));
}
const TGPolygon
/*const TGPolygon
Rectangle::toPoly () const
{
TGPolygon poly;
@ -81,7 +81,7 @@ Rectangle::toPoly () const
poly.add_node(0, _max);
poly.add_node(0, Point3D(_min.x(), _max.y(), 0));
return poly;
}
}*/
};

View file

@ -12,7 +12,6 @@
#endif
#include <simgear/compiler.h>
#include <Geometry/point3d.hxx>
#include <Polygon/polygon.hxx>
@ -45,7 +44,7 @@ public:
/**
* Convenience constructor.
*/
Rectangle (const Point3D &min, const Point3D &max);
Rectangle (const SGGeod& min, const SGGeod& max);
/**
* Destructor.
@ -57,42 +56,42 @@ public:
*
* @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.
*
* @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.
*
* @return The top-left vertex.
*/
virtual Point3D &getMin () { return _min; }
virtual SGGeod &getMin () { return _min; }
/**
* Get the maximum (bottom right) corner of the rectangle.
*
* @return The bottom-right vertex.
*/
virtual Point3D &getMax () { return _max; }
virtual SGGeod &getMax () { return _max; }
/**
* Set the minimum (top-left) corner of the rectangle.
*
* @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.
*
* @param p The bottom-right vertex.
*/
virtual void setMax (const Point3D &p);
virtual void setMax (const SGGeod& p);
/**
* Make the rectangle sane.
@ -110,7 +109,7 @@ public:
* @return true if the point is inside or on the boundary of the
* 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.
@ -126,11 +125,11 @@ public:
*
* @return A four-vertex polygon representing this rectangle.
*/
virtual const TGPolygon toPoly () const;
// virtual const TGPolygon toPoly () const;
private:
Point3D _min;
Point3D _max;
SGGeod _min;
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 y = atoi(s.substr(5).c_str()) * y_factor;
bounds.setMin(Point3D(x, y, 0));
bounds.setMax(Point3D(x + delta, y + delta, 0));
bounds.setMin(SGGeod::fromDeg(x, y));
bounds.setMax(SGGeod::fromDeg(x + delta, y + delta));
return bounds;
}