# include <simgear_config.h>
#endif
+#include <simgear/misc/test_macros.hxx>
+
#include <cstdlib>
#include <iostream>
#include "SGMath.hxx"
+#include "SGRect.hxx"
#include "sg_random.h"
template<typename T>
return true;
}
+template<typename T>
+void doRectTest()
+{
+ SGRect<T> rect(10, 15, 20, 25);
+
+ COMPARE(rect.x(), 10)
+ COMPARE(rect.y(), 15)
+ COMPARE(rect.width(), 20)
+ COMPARE(rect.height(), 25)
+
+ COMPARE(rect.pos(), SGVec2<T>(10, 15))
+ COMPARE(rect.size(), SGVec2<T>(20, 25))
+
+ COMPARE(rect.l(), 10)
+ COMPARE(rect.t(), 15)
+ COMPARE(rect.r(), 30)
+ COMPARE(rect.b(), 40)
+
+ VERIFY(rect == rect)
+ VERIFY(rect == SGRect<T>(10, 15, 20, 25))
+ VERIFY(rect != SGRect<T>(11, 15, 20, 25))
+
+ VERIFY(rect.contains(10, 15))
+ VERIFY(!rect.contains(9, 15))
+ VERIFY(rect.contains(9, 15, 1))
+}
+
bool
GeodesyTest(void)
{
if (!MatrixTest<double>())
return EXIT_FAILURE;
+ // Do rect tests
+ doRectTest<int>();
+ doRectTest<double>();
+
// Check geodetic/geocentric/cartesian conversions
if (!GeodesyTest())
return EXIT_FAILURE;
T y() const { return _min.y(); }
T width() const { return _max.x() - _min.x(); }
T height() const { return _max.y() - _min.y(); }
+ SGVec2<T> const& pos() const { return _min; }
+ SGVec2<T> size() const { return SGVec2<T>(width(), height()); }
void setX(T x) { T w = width(); _min.x() = x; _max.x() = x + w; }
void setY(T y) { T h = height(); _min.y() = y; _max.y() = y + h; }
void setWidth(T w) { _max.x() = _min.x() + w; }
void setHeight(T h) { _max.y() = _min.y() + h; }
+ void setPos(const SGVec2<T>& p) { setX(p.x()); setY(p.y()); }
+ void setSize(const SGVec2<T>& s) { setWidth(s.x()); setHeight(s.y()); }
T l() const { return _min.x(); }
T r() const { return _max.x(); }
return *this;
}
+ bool operator==(const SGRect<T>& rhs) const
+ {
+ return _min == rhs._min
+ && _max == rhs._max;
+ }
+
+ bool operator!=(const SGRect<T>& rhs) const
+ {
+ return !(*this == rhs);
+ }
+
bool contains(T x, T y) const
{
return _min.x() <= x && x <= _max.x()
operator<<(std::basic_ostream<char_type, traits_type>& s, const SGRect<T>& rect)
{ return s << "min = " << rect.getMin() << ", max = " << rect.getMax(); }
+typedef SGRect<int> SGRecti;
+typedef SGRect<float> SGRectf;
+typedef SGRect<double> SGRectd;
+
#endif /* SG_RECT_HXX_ */
#include "nasal_traits.hxx"
+#include <simgear/math/SGMath.hxx>
+#include <simgear/math/SGRect.hxx>
#include <simgear/nasal/nasal.h>
#include <boost/function/function_fwd.hpp>
return to_nasal_helper(c, nasal_vec);
}
+ //----------------------------------------------------------------------------
+ template<class T>
+ naRef to_nasal_helper(naContext c, const SGRect<T>& rect)
+ {
+ std::vector<float> vec(4);
+ vec[0] = rect.l();
+ vec[1] = rect.t();
+ vec[2] = rect.r();
+ vec[3] = rect.b();
+
+ return to_nasal_helper(c, vec);
+ }
+
//----------------------------------------------------------------------------
template<class Value>
naRef to_nasal_helper(naContext c, const std::map<std::string, Value>& map)