#ifndef __SmoothValue_h__
#define __SmoothValue_h__
template<typename T>
class SmoothValue {
private:
T value;
public:
T lambda;
SmoothValue();
SmoothValue(T lambda);
SmoothValue(T lambda, T initialValue);
SmoothValue(const SmoothValue<T>& other)
: value(other.value), lambda(other.lambda){
}
void update(T newValue);
void reset(T newValue){
value = newValue;
}
T getValue(){
return value;
}
SmoothValue<T>& operator=(const T& other){
update(other);
return *this;
}
SmoothValue<T>& operator+=(const T& other){
update(value+other);
return *this;
}
SmoothValue<T>& operator-=(const T& other){
update(value-other);
return *this;
}
SmoothValue<T>& operator*=(const T& other){
update(value*other);
return *this;
}
SmoothValue<T>& operator/=(const T& other){
update(value/other);
return *this;
}
operator T(){
return getValue();
}
static T normal(float lambda, int blocksize);
};
typedef SmoothValue<float> SmoothFloat;
typedef SmoothValue<int> SmoothInt;
template<typename T>
class StiffValue {
private:
T value;
public:
T delta;
StiffValue()
: value(0.0), delta(0.02){}
StiffValue(T d)
: value(0.0), delta(d){}
StiffValue(T d, T initialValue)
: value(initialValue), delta(d){}
void update(T newValue){
if(abs(value-newValue) > delta)
value = newValue;
}
void reset(T newValue){
value = newValue;
}
T getValue(){
return value;
}
StiffValue<T>& operator=(const T& other){
update(other);
return *this;
}
StiffValue<T>& operator+=(const T& other){
update(value+other);
return *this;
}
StiffValue<T>& operator-=(const T& other){
update(value-other);
return *this;
}
StiffValue<T>& operator*=(const T& other){
update(value*other);
return *this;
}
StiffValue<T>& operator/=(const T& other){
update(value/other);
return *this;
}
operator T(){
return getValue();
}
static T normal(float delta);
};
typedef StiffValue<float> StiffFloat;
typedef StiffValue<int> StiffInt;
template<typename T>
class SmoothStiffValue {
private:
T lambda;
T delta;
T value;
public:
SmoothStiffValue(){}
SmoothStiffValue(T l, T d)
: lambda(d), delta(d){}
SmoothStiffValue(T l, T d, T initialValue)
: lambda(d), delta(d), value(initialValue) {}
void update(T newValue);
void reset(T newValue){
value = newValue;
}
T getValue(){
return value;
}
SmoothStiffValue<T>& operator=(const T& other){
update(other);
return *this;
}
SmoothStiffValue<T>& operator+=(const T& other){
update(value+other);
return *this;
}
SmoothStiffValue<T>& operator-=(const T& other){
update(value-other);
return *this;
}
SmoothStiffValue<T>& operator*=(const T& other){
update(value*other);
return *this;
}
SmoothStiffValue<T>& operator/=(const T& other){
update(value/other);
return *this;
}
operator T(){
return getValue();
}
};
typedef SmoothStiffValue<float> SmoothStiffFloat;
typedef SmoothStiffValue<int> SmoothStiffInt;
#endif