#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/predicate.hpp>
+#include <osg/Math> // for osg::isNaN
+
#include <simgear/timing/timestamp.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/structure/exception.hxx>
return result;
}
+static void validateSGGeod(const SGGeod& geod)
+{
+ if (osg::isNaN(geod.getLatitudeDeg()) ||
+ osg::isNaN(geod.getLongitudeDeg()))
+ {
+ throw sg_range_exception("position is invalid, NaNs");
+ }
+}
+
///////////////////////////////////////////////////////////////////////////////
bool
FGPositionedRef
FGPositioned::findClosestWithIdent(const std::string& aIdent, const SGGeod& aPos, Filter* aFilter)
{
+ validateSGGeod(aPos);
+
FGPositioned::List r(findAll(global_identIndex, aIdent, aFilter, true));
if (r.empty()) {
return FGPositionedRef();
FGPositioned::List
FGPositioned::findWithinRange(const SGGeod& aPos, double aRangeNm, Filter* aFilter)
{
+ validateSGGeod(aPos);
+
List result;
Octree::findAllWithinRange(SGVec3d::fromGeod(aPos),
aRangeNm * SG_NM_TO_METER, aFilter, result);
FGPositionedRef
FGPositioned::findClosest(const SGGeod& aPos, double aCutoffNm, Filter* aFilter)
{
- List l(findClosestN(aPos, 1, aCutoffNm, aFilter));
- if (l.empty()) {
- return NULL;
- }
-
- assert(l.size() == 1);
- return l.front();
+ validateSGGeod(aPos);
+
+ List l(findClosestN(aPos, 1, aCutoffNm, aFilter));
+ if (l.empty()) {
+ return NULL;
+ }
+
+ assert(l.size() == 1);
+ return l.front();
}
FGPositioned::List
FGPositioned::findClosestN(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter)
{
+ validateSGGeod(aPos);
+
List result;
Octree::findNearestN(SGVec3d::fromGeod(aPos), aN, aCutoffNm * SG_NM_TO_METER, aFilter, result);
return result;
void
FGPositioned::sortByRange(List& aResult, const SGGeod& aPos)
{
+ validateSGGeod(aPos);
+
SGVec3d cartPos(SGVec3d::fromGeod(aPos));
// computer ordering values
Octree::FindNearestResults r;