From: frohlich Date: Tue, 21 Nov 2006 18:39:57 +0000 (+0000) Subject: Modified Files: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3059da5805f53c0cb940b26638ef9f0467d3277b;p=simgear.git Modified Files: SGVec2.hxx SGVec3.hxx SGVec4.hxx: Implement min/max for vectors --- diff --git a/simgear/math/SGVec2.hxx b/simgear/math/SGVec2.hxx index 2b539b84..6205e126 100644 --- a/simgear/math/SGVec2.hxx +++ b/simgear/math/SGVec2.hxx @@ -204,6 +204,40 @@ SGVec2 operator*(const SGVec2& v, S s) { return SGVec2(s*v(0), s*v(1)); } +/// component wise min +template +inline +SGVec2 +min(const SGVec2& v1, const SGVec2& v2) +{return SGVec2(SGMisc::min(v1(0), v2(0)), SGMisc::min(v1(1), v2(1)));} +template +inline +SGVec2 +min(const SGVec2& v, S s) +{ return SGVec2(SGMisc::min(s, v(0)), SGMisc::min(s, v(1))); } +template +inline +SGVec2 +min(S s, const SGVec2& v) +{ return SGVec2(SGMisc::min(s, v(0)), SGMisc::min(s, v(1))); } + +/// component wise max +template +inline +SGVec2 +max(const SGVec2& v1, const SGVec2& v2) +{return SGVec2(SGMisc::max(v1(0), v2(0)), SGMisc::max(v1(1), v2(1)));} +template +inline +SGVec2 +max(const SGVec2& v, S s) +{ return SGVec2(SGMisc::max(s, v(0)), SGMisc::max(s, v(1))); } +template +inline +SGVec2 +max(S s, const SGVec2& v) +{ return SGVec2(SGMisc::max(s, v(0)), SGMisc::max(s, v(1))); } + /// Scalar dot product template inline diff --git a/simgear/math/SGVec3.hxx b/simgear/math/SGVec3.hxx index ee75415c..df742744 100644 --- a/simgear/math/SGVec3.hxx +++ b/simgear/math/SGVec3.hxx @@ -259,6 +259,64 @@ SGVec3 operator*(const SGVec3& v, S s) { return SGVec3(s*v(0), s*v(1), s*v(2)); } +/// component wise min +template +inline +SGVec3 +min(const SGVec3& v1, const SGVec3& v2) +{ + return SGVec3(SGMisc::min(v1(0), v2(0)), + SGMisc::min(v1(1), v2(1)), + SGMisc::min(v1(2), v2(2))); +} +template +inline +SGVec3 +min(const SGVec3& v, S s) +{ + return SGVec3(SGMisc::min(s, v(0)), + SGMisc::min(s, v(1)), + SGMisc::min(s, v(2))); +} +template +inline +SGVec3 +min(S s, const SGVec3& v) +{ + return SGVec3(SGMisc::min(s, v(0)), + SGMisc::min(s, v(1)), + SGMisc::min(s, v(2))); +} + +/// component wise max +template +inline +SGVec3 +max(const SGVec3& v1, const SGVec3& v2) +{ + return SGVec3(SGMisc::max(v1(0), v2(0)), + SGMisc::max(v1(1), v2(1)), + SGMisc::max(v1(2), v2(2))); +} +template +inline +SGVec3 +max(const SGVec3& v, S s) +{ + return SGVec3(SGMisc::max(s, v(0)), + SGMisc::max(s, v(1)), + SGMisc::max(s, v(2))); +} +template +inline +SGVec3 +max(S s, const SGVec3& v) +{ + return SGVec3(SGMisc::max(s, v(0)), + SGMisc::max(s, v(1)), + SGMisc::max(s, v(2))); +} + /// Scalar dot product template inline diff --git a/simgear/math/SGVec4.hxx b/simgear/math/SGVec4.hxx index 50b138c9..b8223a7a 100644 --- a/simgear/math/SGVec4.hxx +++ b/simgear/math/SGVec4.hxx @@ -221,6 +221,70 @@ SGVec4 operator*(const SGVec4& v, S s) { return SGVec4(s*v(0), s*v(1), s*v(2), s*v(3)); } +/// component wise min +template +inline +SGVec4 +min(const SGVec4& v1, const SGVec4& v2) +{ + return SGVec4(SGMisc::min(v1(0), v2(0)), + SGMisc::min(v1(1), v2(1)), + SGMisc::min(v1(2), v2(2)), + SGMisc::min(v1(3), v2(3))); +} +template +inline +SGVec4 +min(const SGVec4& v, S s) +{ + return SGVec4(SGMisc::min(s, v(0)), + SGMisc::min(s, v(1)), + SGMisc::min(s, v(2)), + SGMisc::min(s, v(3))); +} +template +inline +SGVec4 +min(S s, const SGVec4& v) +{ + return SGVec4(SGMisc::min(s, v(0)), + SGMisc::min(s, v(1)), + SGMisc::min(s, v(2)), + SGMisc::min(s, v(3))); +} + +/// component wise max +template +inline +SGVec4 +max(const SGVec4& v1, const SGVec4& v2) +{ + return SGVec4(SGMisc::max(v1(0), v2(0)), + SGMisc::max(v1(1), v2(1)), + SGMisc::max(v1(2), v2(2)), + SGMisc::max(v1(3), v2(3))); +} +template +inline +SGVec4 +max(const SGVec4& v, S s) +{ + return SGVec4(SGMisc::max(s, v(0)), + SGMisc::max(s, v(1)), + SGMisc::max(s, v(2)), + SGMisc::max(s, v(3))); +} +template +inline +SGVec4 +max(S s, const SGVec4& v) +{ + return SGVec4(SGMisc::max(s, v(0)), + SGMisc::max(s, v(1)), + SGMisc::max(s, v(2)), + SGMisc::max(s, v(3))); +} + /// Scalar dot product template inline