From: frohlich Date: Fri, 18 May 2007 04:46:11 +0000 (+0000) Subject: Modified Files: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f7c6a5bfa2140c1d5ef54f3212067cd286e525f1;p=simgear.git Modified Files: SGVec2.hxx SGVec3.hxx SGVec4.hxx point3d.hxx: Provide ordering relations for use with std::less in tree bases std:: containers. --- diff --git a/simgear/math/SGVec2.hxx b/simgear/math/SGVec2.hxx index 31538758..155b8a67 100644 --- a/simgear/math/SGVec2.hxx +++ b/simgear/math/SGVec2.hxx @@ -295,6 +295,39 @@ bool operator!=(const SGVec2& v1, const SGVec2& v2) { return ! (v1 == v2); } +/// Return true if smaller, good for putting that into a std::map +template +inline +bool +operator<(const SGVec2& v1, const SGVec2& v2) +{ + if (v1(0) < v2(0)) return true; + else if (v2(0) < v1(0)) return false; + else return (v1(1) < v2(1)); +} + +template +inline +bool +operator<=(const SGVec2& v1, const SGVec2& v2) +{ + if (v1(0) < v2(0)) return true; + else if (v2(0) < v1(0)) return false; + else return (v1(1) <= v2(1)); +} + +template +inline +bool +operator>(const SGVec2& v1, const SGVec2& v2) +{ return operator<(v2, v1); } + +template +inline +bool +operator>=(const SGVec2& v1, const SGVec2& v2) +{ return operator<=(v2, v1); } + /// Return true if equal to the relative tolerance tol template inline diff --git a/simgear/math/SGVec3.hxx b/simgear/math/SGVec3.hxx index 9e07584e..3d375c0b 100644 --- a/simgear/math/SGVec3.hxx +++ b/simgear/math/SGVec3.hxx @@ -412,6 +412,43 @@ bool operator!=(const SGVec3& v1, const SGVec3& v2) { return ! (v1 == v2); } +/// Return true if smaller, good for putting that into a std::map +template +inline +bool +operator<(const SGVec3& v1, const SGVec3& v2) +{ + if (v1(0) < v2(0)) return true; + else if (v2(0) < v1(0)) return false; + else if (v1(1) < v2(1)) return true; + else if (v2(1) < v1(1)) return false; + else return (v1(2) < v2(2)); +} + +template +inline +bool +operator<=(const SGVec3& v1, const SGVec3& v2) +{ + if (v1(0) < v2(0)) return true; + else if (v2(0) < v1(0)) return false; + else if (v1(1) < v2(1)) return true; + else if (v2(1) < v1(1)) return false; + else return (v1(2) <= v2(2)); +} + +template +inline +bool +operator>(const SGVec3& v1, const SGVec3& v2) +{ return operator<(v2, v1); } + +template +inline +bool +operator>=(const SGVec3& v1, const SGVec3& v2) +{ return operator<=(v2, v1); } + /// Return true if equal to the relative tolerance tol template inline diff --git a/simgear/math/SGVec4.hxx b/simgear/math/SGVec4.hxx index 7c714323..f854274d 100644 --- a/simgear/math/SGVec4.hxx +++ b/simgear/math/SGVec4.hxx @@ -344,6 +344,47 @@ bool operator!=(const SGVec4& v1, const SGVec4& v2) { return ! (v1 == v2); } +/// Return true if smaller, good for putting that into a std::map +template +inline +bool +operator<(const SGVec4& v1, const SGVec4& v2) +{ + if (v1(0) < v2(0)) return true; + else if (v2(0) < v1(0)) return false; + else if (v1(1) < v2(1)) return true; + else if (v2(1) < v1(1)) return false; + else if (v1(2) < v2(2)) return true; + else if (v2(2) < v1(2)) return false; + else return (v1(3) < v2(3)); +} + +template +inline +bool +operator<=(const SGVec4& v1, const SGVec4& v2) +{ + if (v1(0) < v2(0)) return true; + else if (v2(0) < v1(0)) return false; + else if (v1(1) < v2(1)) return true; + else if (v2(1) < v1(1)) return false; + else if (v1(2) < v2(2)) return true; + else if (v2(2) < v1(2)) return false; + else return (v1(3) <= v2(3)); +} + +template +inline +bool +operator>(const SGVec4& v1, const SGVec4& v2) +{ return operator<(v2, v1); } + +template +inline +bool +operator>=(const SGVec4& v1, const SGVec4& v2) +{ return operator<=(v2, v1); } + /// Return true if equal to the relative tolerance tol template inline diff --git a/simgear/math/point3d.hxx b/simgear/math/point3d.hxx index 3980e203..79ce8303 100644 --- a/simgear/math/point3d.hxx +++ b/simgear/math/point3d.hxx @@ -97,6 +97,8 @@ public: static Point3D fromSGGeod(const SGGeod& geod); static Point3D fromSGGeoc(const SGGeoc& geoc); static Point3D fromSGVec3(const SGVec3& cart); + static Point3D fromSGVec3(const SGVec3& cart); + static Point3D fromSGVec2(const SGVec2& cart); // Assignment operators @@ -134,6 +136,7 @@ public: SGVec3d toSGVec3d(void) const; SGVec3f toSGVec3f(void) const; + SGVec2f toSGVec2f(void) const; // friends friend Point3D operator - (const Point3D& p); // -p1 @@ -242,6 +245,24 @@ inline Point3D Point3D::fromSGVec3(const SGVec3& cart) return pt; } +inline Point3D Point3D::fromSGVec3(const SGVec3& cart) +{ + Point3D pt; + pt.setx(cart.x()); + pt.sety(cart.y()); + pt.setz(cart.z()); + return pt; +} + +inline Point3D Point3D::fromSGVec2(const SGVec2& cart) +{ + Point3D pt; + pt.setx(cart.x()); + pt.sety(cart.y()); + pt.setz(0); + return pt; +} + // ASSIGNMENT OPERATORS inline Point3D& Point3D::operator = (const Point3D& p) @@ -354,6 +375,11 @@ inline SGVec3f Point3D::toSGVec3f(void) const return SGVec3f(x(), y(), z()); } +inline SGVec2f Point3D::toSGVec2f(void) const +{ + return SGVec2f(x(), y()); +} + // FRIENDS inline Point3D operator - (const Point3D& a)