Browse Source

add quantize()

David Rose 21 years ago
parent
commit
21483c7e2b
2 changed files with 17 additions and 0 deletions
  1. 13 0
      panda/src/egg/eggAnimData.cxx
  2. 4 0
      panda/src/egg/eggAnimData.h

+ 13 - 0
panda/src/egg/eggAnimData.cxx

@@ -19,3 +19,16 @@
 #include "eggAnimData.h"
 
 TypeHandle EggAnimData::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: EggAnimData::quantize
+//       Access: Public
+//  Description: Rounds each element of the table to the nearest
+//               multiple of quantum.
+////////////////////////////////////////////////////////////////////
+void EggAnimData::
+quantize(double quantum) {
+  for (size_t i = 0; i < _data.size(); i++) {
+    _data[i] = floor(_data[i] / quantum + 0.5) * quantum;
+  }
+}

+ 4 - 0
panda/src/egg/eggAnimData.h

@@ -26,6 +26,8 @@
 #include "pointerToArray.h"
 #include "pta_double.h"
 
+#include <math.h>
+
 ////////////////////////////////////////////////////////////////////
 //       Class : EggAnimData
 // Description : A base class for EggSAnimData and EggXfmAnimData,
@@ -50,6 +52,8 @@ PUBLISHED:
   INLINE PTA_double get_data() const;
   INLINE void set_data(const PTA_double &data);
 
+  void quantize(double quantum);
+
 protected:
   PTA_double _data;