From 8417fea3bf6e53bfe96a311e054360c31304736a Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Thu, 13 Dec 2012 00:30:01 +0100 Subject: [PATCH] Overload Rect::contains and add compound assignment operators to PropertyObject --- simgear/math/Rect.hxx | 6 ++++++ simgear/props/propertyObject.hxx | 21 +++++++++++++++++++++ simgear/props/propertyObject_test.cxx | 21 +++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/simgear/math/Rect.hxx b/simgear/math/Rect.hxx index d5f252f4..d45d4a0f 100644 --- a/simgear/math/Rect.hxx +++ b/simgear/math/Rect.hxx @@ -74,6 +74,12 @@ namespace simgear && _y1 <= y && y <= _y2; } + bool contains(T x, T y, T margin) const + { + return (_x1 - margin) <= x && x <= (_x2 + margin) + && (_y1 - margin) <= y && y <= (_y2 + margin); + } + private: T _x1, _x2, _y1, _y2; }; diff --git a/simgear/props/propertyObject.hxx b/simgear/props/propertyObject.hxx index 33c30a45..6a5e1ae7 100644 --- a/simgear/props/propertyObject.hxx +++ b/simgear/props/propertyObject.hxx @@ -122,6 +122,27 @@ public: return aValue; } +#define SG_DEF_ASSIGN_OP(op)\ + T operator op##=(const T rhs)\ + {\ + SGPropertyNode* n = getOrThrow();\ + n->setValue(n->getValue() op rhs);\ + return *this;\ + } + + SG_DEF_ASSIGN_OP(+) + SG_DEF_ASSIGN_OP(-) + SG_DEF_ASSIGN_OP(*) + SG_DEF_ASSIGN_OP(/) + SG_DEF_ASSIGN_OP(%) + SG_DEF_ASSIGN_OP(>>) + SG_DEF_ASSIGN_OP(<<) + SG_DEF_ASSIGN_OP(&) + SG_DEF_ASSIGN_OP(^) + SG_DEF_ASSIGN_OP(|) + +#undef SG_DEF_ASSIGN_OP + SGPropertyNode* node() const { return PropertyObjectBase::node(false); diff --git a/simgear/props/propertyObject_test.cxx b/simgear/props/propertyObject_test.cxx index 7021395a..9c354f46 100644 --- a/simgear/props/propertyObject_test.cxx +++ b/simgear/props/propertyObject_test.cxx @@ -110,6 +110,27 @@ void testAssignment() a3 = 44; assert(a1 == 44); + // Compound assignment ops + a1 *= 2; + assert(a1 == 88); + a1 /= 2; + assert(a1 == 44); + a1 += 2; + assert(a1 == 46); + a1 -= 16; + assert(a1 == 30); + a1 %= 28; + assert(a1 == 2); + a1 >>= 1; + assert(a1 == 1); + a1 <<= 2; + assert(a1 == 4); + a1 &= 1; + assert(a1 == 0); + a1 ^= 2; + assert(a1 == 2); + a1 |= 1; + assert(a1 == 3); } void testSTLContainer() -- 2.39.5