26 int n = (int) (val / period);
29 return n ? val - n * period : val;
37 template <
class T,
int P>
41 T
val(
bool positive=
true)
const 44 if ( !positive && res > ((T)P)/2 )
71 { val_ = nv;
return this; }
73 { val_ += nv;
return this; }
75 { val_ -= nv;
return this; }
77 { val_ *= nv;
return this; }
79 { val_ /= nv;
return this; }
81 { val_ = nv.
val();
return this; }
83 { val_ += nv.
val();
return this; }
85 { val_ -= nv.
val();
return this; }
87 { val_ *= nv.
val();
return this; }
89 { val_ /= nv.
val();
return this; }
91 bool operator<(const PeriodicValue<T,P>& b)
const 94 if ( tmp.
val(
true)>
P/2 )
return true;
100 if ( tmp.
val(
true)<=
P/2 )
return true;
104 {
return *this < PeriodicValue<T,P>(b); }
124 template <
class T,
class RT>
126 RT& ret,
RT period,
bool extrapolate=
false )
128 const float halfperiod = period / 2;
130 float dist = pos - intpos;
131 if(
mIsZero(dist,1e-10) && intpos >= 0 && intpos < sz )
132 { ret = idxabl[intpos];
return; }
134 int prevpos = dist > 0 ? intpos : intpos - 1;
135 if ( !extrapolate && (prevpos > sz-2 || prevpos < 0) )
137 else if ( prevpos < 1 )
139 const float val0 = idxabl[0];
141 while ( val1 - val0 > halfperiod ) val1 -= period;
142 while ( val1 - val0 < -halfperiod ) val1 += period;
147 else if ( prevpos > sz-3 )
149 const RT val0 = idxabl[sz-2];
150 RT val1 = idxabl[sz-1];
151 while ( val1 - val0 > halfperiod ) val1 -= period;
152 while ( val1 - val0 < -halfperiod ) val1 += period;
158 const RT val0 = idxabl[prevpos-1];
160 RT val1 = idxabl[prevpos];
161 while ( val1 - val0 > halfperiod ) val1 -= period;
162 while ( val1 - val0 < -halfperiod ) val1 += period;
164 RT val2 = idxabl[prevpos+1];
165 while ( val2 - val1 > halfperiod ) val2 -= period;
166 while ( val2 - val1 < -halfperiod ) val2 += period;
168 RT val3 = idxabl[prevpos+2];
169 while ( val3 - val2 > halfperiod ) val3 -= period;
170 while ( val3 - val2 < -halfperiod ) val3 += period;
173 pos - prevpos ), period );
180 float period,
bool extrapolate=
false )
182 float ret =
mUdf(
float);
194 template <
class T,
class RT>
199 float dist = pos - intpos;
200 if(
mIsZero(dist,1e-10) && intpos >= 0 && intpos < sz )
201 { ret = idxabl[intpos];
return; }
203 int prevpos = dist > 0 ? intpos : intpos - 1;
204 const float relpos = pos - prevpos;
207 int prevpos2 = prevpos - 1;
210 int nextpos = prevpos + 1;
213 int nextpos2 = prevpos + 2;
216 const RT prevval2 = idxabl[prevpos2];
217 const RT prevval = idxabl[prevpos];
218 const RT nextval = idxabl[nextpos];
219 const RT nextval2 = idxabl[nextpos2];
PeriodicValue(T nv)
Definition: periodicvalue.h:109
#define mIsZero(x, eps)
Definition: commondefs.h:55
const PeriodicValue< T, P > & operator-=(const PeriodicValue< T, P > &nv)
Definition: periodicvalue.h:84
void interpolateXPeriodicReg(const T &idxabl, int sz, float pos, RT &ret)
Definition: periodicvalue.h:195
const PeriodicValue< T, P > & operator/=(T nv)
Definition: periodicvalue.h:78
T polyReg1D(T vm1, T v0, T v1, T v2, float x)
Definition: interpol1d.h:128
const PeriodicValue< T, P > & operator-=(T nv)
Definition: periodicvalue.h:74
PeriodicValue handles periodic data through mathematical operations.
Definition: periodicvalue.h:38
PeriodicValue< T, P > operator+(const PeriodicValue< T, P > &nv) const
Definition: periodicvalue.h:61
const PeriodicValue< T, P > & operator=(const PeriodicValue< T, P > &nv) const
Definition: periodicvalue.h:80
PeriodicValue< T, P > operator*(const PeriodicValue< T, P > &nv) const
Definition: periodicvalue.h:65
PeriodicValue< T, P > operator-(const PeriodicValue< T, P > &nv) const
Definition: periodicvalue.h:63
#define mNINT32(x)
Definition: commondefs.h:48
T val_
Definition: periodicvalue.h:112
PeriodicValue< T, P > operator/(const PeriodicValue< T, P > &nv) const
Definition: periodicvalue.h:67
PeriodicValue< T, P > operator+(T nv) const
Definition: periodicvalue.h:53
PeriodicValue< T, P > operator/(T nv) const
Definition: periodicvalue.h:59
Definition: seistype.h:59
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:270
T val(bool positive=true) const
Definition: periodicvalue.h:41
bool operator<(T b) const
Definition: periodicvalue.h:103
void interpolateYPeriodicReg(const T &idxabl, int sz, float pos, RT &ret, RT period, bool extrapolate=false)
Definition: periodicvalue.h:125
T linearReg1D(T v0, T v1, float x)
Definition: interpol1d.h:44
const PeriodicValue< T, P > & operator=(T nv) const
Definition: periodicvalue.h:70
const PeriodicValue< T, P > & operator/=(const PeriodicValue< T, P > &nv)
Definition: periodicvalue.h:88
bool operator>(T b) const
Definition: periodicvalue.h:105
Position-sorted indexable objects.
Definition: idxable.h:28
PeriodicValue< T, P > operator*(T nv) const
Definition: periodicvalue.h:57
T dePeriodize(T val, T period)
Definition: periodicvalue.h:24
const PeriodicValue< T, P > & operator*=(T nv)
Definition: periodicvalue.h:76
const PeriodicValue< T, P > & operator+=(T nv)
Definition: periodicvalue.h:72
bool operator>(const PeriodicValue< T, P > &b) const
Definition: periodicvalue.h:97
PeriodicValue< T, P > operator-(T nv) const
Definition: periodicvalue.h:55
const PeriodicValue< T, P > & operator*=(const PeriodicValue< T, P > &nv)
Definition: periodicvalue.h:86
#define mClass(module)
Definition: commondefs.h:161
const PeriodicValue< T, P > & operator+=(const PeriodicValue< T, P > &nv)
Definition: periodicvalue.h:82