Overload Rect::contains and add compound assignment operators to PropertyObject

This commit is contained in:
Thomas Geymayer 2012-12-13 00:30:01 +01:00
parent f5150d32af
commit 8417fea3bf
3 changed files with 48 additions and 0 deletions

View File

@ -74,6 +74,12 @@ namespace simgear
&& _y1 <= y && y <= _y2; && _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: private:
T _x1, _x2, _y1, _y2; T _x1, _x2, _y1, _y2;
}; };

View File

@ -122,6 +122,27 @@ public:
return aValue; return aValue;
} }
#define SG_DEF_ASSIGN_OP(op)\
T operator op##=(const T rhs)\
{\
SGPropertyNode* n = getOrThrow();\
n->setValue<T>(n->getValue<T>() 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 SGPropertyNode* node() const
{ {
return PropertyObjectBase::node(false); return PropertyObjectBase::node(false);

View File

@ -110,6 +110,27 @@ void testAssignment()
a3 = 44; a3 = 44;
assert(a1 == 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() void testSTLContainer()