Browse Source

Added fmax and fmin operators to vector

Josh Yelon 20 years ago
parent
commit
947294fe99

+ 22 - 0
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

+ 3 - 0
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;

+ 24 - 0
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

+ 3 - 0
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,

+ 26 - 0
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

+ 3 - 0
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;