00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "physxLinearInterpolationValues.h"
00016
00017
00018
00019
00020
00021
00022 void PhysxLinearInterpolationValues::
00023 clear() {
00024
00025 _map.clear();
00026 }
00027
00028
00029
00030
00031
00032
00033 void PhysxLinearInterpolationValues::
00034 insert(float index, float value) {
00035
00036 if (_map.empty()) {
00037 _min = _max = index;
00038 }
00039 else {
00040 _min = min(_min, index);
00041 _max = max(_max, index);
00042 }
00043 _map[index] = value;
00044 }
00045
00046
00047
00048
00049
00050
00051 bool PhysxLinearInterpolationValues::
00052 is_valid(float number) const {
00053
00054 return (number >= _min) && (number <= _max);
00055 }
00056
00057
00058
00059
00060
00061
00062 unsigned int PhysxLinearInterpolationValues::
00063 get_size() const {
00064
00065 return _map.size();
00066 }
00067
00068
00069
00070
00071
00072
00073 float PhysxLinearInterpolationValues::
00074 get_value(float number) const {
00075
00076 MapType::const_iterator lower = _map.begin();
00077 if (number < _min) {
00078 return lower->second;
00079 }
00080
00081 MapType::const_iterator upper = _map.end();
00082 upper--;
00083 if (number > _max) {
00084 return upper->second;
00085 }
00086
00087 upper = _map.lower_bound(number);
00088 if (upper == lower) {
00089 return upper->second;
00090 }
00091
00092 lower = upper;
00093 lower--;
00094
00095 float w1 = number - lower->first;
00096 float w2 = upper->first - number;
00097
00098 return ((w2 * lower->second) + (w1 * upper->second)) / (w1 + w2);
00099 }
00100
00101
00102
00103
00104
00105
00106 float PhysxLinearInterpolationValues::
00107 get_value_at_index(int index) const {
00108
00109 MapType::const_iterator it = _map.begin();
00110
00111 for (int i=0; i<index; i++) {
00112 ++it;
00113 }
00114
00115 return it->second;
00116 }
00117
00118
00119
00120
00121
00122
00123 void PhysxLinearInterpolationValues::
00124 output(ostream &out) const {
00125
00126 MapType::const_iterator it = _map.begin();
00127
00128 for (; it != _map.end(); ++it) {
00129 cout << it->first << " -> " << it->second << "\n";
00130 }
00131 }
00132