Added a parseChunk function for parsing chunk strings like w080n40.
This commit is contained in:
parent
14488cda6a
commit
598500edb0
2 changed files with 47 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/math/sg_geodesy.hxx>
|
||||
#include <simgear/misc/exception.hxx>
|
||||
|
||||
#include <Polygon/polygon.hxx>
|
||||
|
||||
|
@ -144,4 +145,38 @@ makePolygon (const Line &line, int width, FGPolygon &polygon)
|
|||
}
|
||||
|
||||
|
||||
Rectangle
|
||||
parseChunk (const string &s)
|
||||
{
|
||||
Rectangle bounds;
|
||||
int x_factor;
|
||||
int y_factor;
|
||||
|
||||
if (s.size() != 7)
|
||||
throw sg_exception(string("Bad length for chunk specifier: ") + s);
|
||||
|
||||
if (s[0] == 'w')
|
||||
x_factor = -1;
|
||||
else if (s[0] == 'e')
|
||||
x_factor = 1;
|
||||
else
|
||||
throw sg_exception(string("Chunk specifier must begin with 'e' or 'w': "
|
||||
+ s));
|
||||
|
||||
if (s[4] == 's')
|
||||
y_factor = -1;
|
||||
else if (s[4] == 'n')
|
||||
y_factor = 1;
|
||||
else
|
||||
throw sg_exception("Second part of chunk specifier must begin with 's' or 'n': " + s);
|
||||
|
||||
|
||||
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 + 10, y + 10, 0));
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
// end of util.cxx
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
#include <simgear/compiler.h>
|
||||
#include <simgear/math/point3d.hxx>
|
||||
|
||||
#include <string>
|
||||
SG_USING_STD(string);
|
||||
|
||||
#include <Polygon/polygon.hxx>
|
||||
|
||||
#include "line.hxx"
|
||||
|
@ -84,4 +87,13 @@ void makePolygon (const Point3D &p, int width, FGPolygon &polygon);
|
|||
void makePolygon (const Line &line, int width, FGPolygon &polygon);
|
||||
|
||||
|
||||
/**
|
||||
* Parse a chunk string (like "w080n40") into a rectangle.
|
||||
*
|
||||
* @param s The string.
|
||||
* @return A rectangle containing the bounds.
|
||||
*/
|
||||
Rectangle parseChunk (const string &s);
|
||||
|
||||
|
||||
#endif // __UTIL_HXX
|
||||
|
|
Loading…
Add table
Reference in a new issue