MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ ping_pong()

template<typename T >
T MayaFlux::Kinesis::ping_pong ( x,
lo,
hi 
)
inlinenoexcept

Ping-pong (triangle wave): fold x back and forth in [lo, hi].

At x = lo the value is lo. It increases to hi then folds back toward lo. Period is 2 * (hi - lo). Use for oscillating parameters, bounce animations, or any signal that should reverse at the boundary instead of wrapping.

Example: ping_pong(1.3F, 0.F, 1.F) -> 0.7F

Definition at line 153 of file Scalar.hpp.

154{
155 const T range = hi - lo;
156 if (range <= T { 0 })
157 return lo;
158 const T shifted = x - lo;
159 const T period = T { 2 } * range;
160 const T t = shifted - period * std::floor(shifted / period);
161 return lo + (t < range ? t : period - t);
162}