From 947294fe99c8b271663886ffc07b042532b4b506 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Tue, 7 Feb 2006 20:18:07 +0000 Subject: [PATCH] Added fmax and fmin operators to vector --- panda/src/linmath/lvecBase2_src.I | 22 ++++++++++++++++++++++ panda/src/linmath/lvecBase2_src.h | 3 +++ panda/src/linmath/lvecBase3_src.I | 24 ++++++++++++++++++++++++ panda/src/linmath/lvecBase3_src.h | 3 +++ panda/src/linmath/lvecBase4_src.I | 26 ++++++++++++++++++++++++++ panda/src/linmath/lvecBase4_src.h | 3 +++ 6 files changed, 81 insertions(+) diff --git a/panda/src/linmath/lvecBase2_src.I b/panda/src/linmath/lvecBase2_src.I index bef5e96f5b..343e57d9b0 100644 --- a/panda/src/linmath/lvecBase2_src.I +++ b/panda/src/linmath/lvecBase2_src.I @@ -558,6 +558,28 @@ operator /= (FLOATTYPE scalar) { _v.v._1 *= recip_scalar; } +//////////////////////////////////////////////////////////////////// +// Function: LVecBase2::fmax +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase2):: +fmax(const FLOATNAME(LVecBase2) &other) { + return FLOATNAME(LVecBase2)(_v.v._0 > other._v.v._0 ? _v.v._0 : other._v.v._0, + _v.v._1 > other._v.v._1 ? _v.v._1 : other._v.v._1); +} + +//////////////////////////////////////////////////////////////////// +// Function: LVecBase2::fmin +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase2):: +fmin(const FLOATNAME(LVecBase2) &other) { + return FLOATNAME(LVecBase2)(_v.v._0 < other._v.v._0 ? _v.v._0 : other._v.v._0, + _v.v._1 < other._v.v._1 ? _v.v._1 : other._v.v._1); +} + //////////////////////////////////////////////////////////////////// // Function: LVecBase2::almost_equal // Access: Public diff --git a/panda/src/linmath/lvecBase2_src.h b/panda/src/linmath/lvecBase2_src.h index fe039deaa4..a83368738a 100644 --- a/panda/src/linmath/lvecBase2_src.h +++ b/panda/src/linmath/lvecBase2_src.h @@ -107,6 +107,9 @@ PUBLISHED: INLINE_LINMATH void operator *= (FLOATTYPE scalar); INLINE_LINMATH void operator /= (FLOATTYPE scalar); + INLINE_LINMATH FLOATNAME(LVecBase2) fmax(const FLOATNAME(LVecBase2) &other); + INLINE_LINMATH FLOATNAME(LVecBase2) fmin(const FLOATNAME(LVecBase2) &other); + INLINE_LINMATH bool almost_equal(const FLOATNAME(LVecBase2) &other, FLOATTYPE threshold) const; INLINE_LINMATH bool almost_equal(const FLOATNAME(LVecBase2) &other) const; diff --git a/panda/src/linmath/lvecBase3_src.I b/panda/src/linmath/lvecBase3_src.I index 9cb523ca00..35e3886630 100644 --- a/panda/src/linmath/lvecBase3_src.I +++ b/panda/src/linmath/lvecBase3_src.I @@ -718,6 +718,30 @@ operator /= (FLOATTYPE scalar) { _v.v._2 *= recip_scalar; } +//////////////////////////////////////////////////////////////////// +// Function: LVecBase3::fmax +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: +fmax(const FLOATNAME(LVecBase3) &other) { + return FLOATNAME(LVecBase3)(_v.v._0 > other._v.v._0 ? _v.v._0 : other._v.v._0, + _v.v._1 > other._v.v._1 ? _v.v._1 : other._v.v._1, + _v.v._2 > other._v.v._2 ? _v.v._2 : other._v.v._2); +} + +//////////////////////////////////////////////////////////////////// +// Function: LVecBase3::fmin +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3):: +fmin(const FLOATNAME(LVecBase3) &other) { + return FLOATNAME(LVecBase3)(_v.v._0 < other._v.v._0 ? _v.v._0 : other._v.v._0, + _v.v._1 < other._v.v._1 ? _v.v._1 : other._v.v._1, + _v.v._2 < other._v.v._2 ? _v.v._2 : other._v.v._2); +} + //////////////////////////////////////////////////////////////////// // Function: LVecBase3::cross product (with assigment) // Access: Published diff --git a/panda/src/linmath/lvecBase3_src.h b/panda/src/linmath/lvecBase3_src.h index 5a85ceaee8..eb418d3f91 100644 --- a/panda/src/linmath/lvecBase3_src.h +++ b/panda/src/linmath/lvecBase3_src.h @@ -115,6 +115,9 @@ PUBLISHED: INLINE_LINMATH void operator *= (FLOATTYPE scalar); INLINE_LINMATH void operator /= (FLOATTYPE scalar); + INLINE_LINMATH FLOATNAME(LVecBase3) fmax(const FLOATNAME(LVecBase3) &other); + INLINE_LINMATH FLOATNAME(LVecBase3) fmin(const FLOATNAME(LVecBase3) &other); + INLINE_LINMATH void cross_into(const FLOATNAME(LVecBase3) &other); INLINE_LINMATH bool almost_equal(const FLOATNAME(LVecBase3) &other, diff --git a/panda/src/linmath/lvecBase4_src.I b/panda/src/linmath/lvecBase4_src.I index f7b431d691..ed163b508c 100644 --- a/panda/src/linmath/lvecBase4_src.I +++ b/panda/src/linmath/lvecBase4_src.I @@ -676,6 +676,32 @@ operator /= (FLOATTYPE scalar) { _v.v._3 *= recip_scalar; } +//////////////////////////////////////////////////////////////////// +// Function: LVecBase4::fmax +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVecBase4):: +fmax(const FLOATNAME(LVecBase4) &other) { + return FLOATNAME(LVecBase4)(_v.v._0 > other._v.v._0 ? _v.v._0 : other._v.v._0, + _v.v._1 > other._v.v._1 ? _v.v._1 : other._v.v._1, + _v.v._2 > other._v.v._2 ? _v.v._2 : other._v.v._2, + _v.v._3 > other._v.v._3 ? _v.v._3 : other._v.v._3); +} + +//////////////////////////////////////////////////////////////////// +// Function: LVecBase4::fmin +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVecBase4):: +fmin(const FLOATNAME(LVecBase4) &other) { + return FLOATNAME(LVecBase4)(_v.v._0 < other._v.v._0 ? _v.v._0 : other._v.v._0, + _v.v._1 < other._v.v._1 ? _v.v._1 : other._v.v._1, + _v.v._2 < other._v.v._2 ? _v.v._2 : other._v.v._2, + _v.v._3 < other._v.v._3 ? _v.v._3 : other._v.v._3); +} + //////////////////////////////////////////////////////////////////// // Function: LVecBase4::almost_equal // Access: Public diff --git a/panda/src/linmath/lvecBase4_src.h b/panda/src/linmath/lvecBase4_src.h index 06299d27bd..818c38bb2d 100644 --- a/panda/src/linmath/lvecBase4_src.h +++ b/panda/src/linmath/lvecBase4_src.h @@ -112,6 +112,9 @@ PUBLISHED: INLINE_LINMATH void operator *= (FLOATTYPE scalar); INLINE_LINMATH void operator /= (FLOATTYPE scalar); + INLINE_LINMATH FLOATNAME(LVecBase4) fmax(const FLOATNAME(LVecBase4) &other); + INLINE_LINMATH FLOATNAME(LVecBase4) fmin(const FLOATNAME(LVecBase4) &other); + INLINE_LINMATH bool almost_equal(const FLOATNAME(LVecBase4) &other, FLOATTYPE threshold) const; INLINE_LINMATH bool almost_equal(const FLOATNAME(LVecBase4) &other) const;