MCPcopy Create free account
hub / github.com/FastLED/FastLED / lerp

Function lerp

src/fl/math/fixed_point/s16x16.h:155–429  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153
154#if defined(__riscv) && (__riscv_xlen == 32)
155 static FASTLED_FORCE_INLINE s16x16 lerp(s16x16 a, s16x16 b, s16x16 t) {
156#else
157 static constexpr FASTLED_FORCE_INLINE s16x16 lerp(s16x16 a, s16x16 b, s16x16 t) FL_NOEXCEPT {
158#endif
159 return a + (b - a) * t;
160 }
161
162 static constexpr FASTLED_FORCE_INLINE s16x16 clamp(s16x16 x, s16x16 lo, s16x16 hi) FL_NOEXCEPT {
163 return x < lo ? lo : (x > hi ? hi : x);
164 }
165
166 static constexpr FASTLED_FORCE_INLINE s16x16 step(s16x16 edge, s16x16 x) FL_NOEXCEPT {
167 return x < edge ? s16x16() : s16x16(1.0f);
168 }
169
170 static FASTLED_FORCE_INLINE s16x16 smoothstep(s16x16 edge0, s16x16 edge1, s16x16 x) FL_NOEXCEPT {
171 constexpr s16x16 zero(0.0f);
172 constexpr s16x16 one(1.0f);
173 constexpr s16x16 two(2.0f);
174 constexpr s16x16 three(3.0f);
175 s16x16 t = clamp((x - edge0) / (edge1 - edge0), zero, one);
176 return t * t * (three - two * t);
177 }
178
179 // ---- Inverse Trigonometry (pure fixed-point) ----------------------------
180
181 static FASTLED_FORCE_INLINE s16x16 atan(s16x16 x) FL_NOEXCEPT {
182 constexpr s16x16 one(1.0f);
183 constexpr s16x16 pi_over_2(1.5707963f);
184 bool neg = x.mValue < 0;
185 s16x16 ax = abs(x);
186 s16x16 result;
187 if (ax <= one) {
188 result = atan_unit(ax);
189 } else {
190 result = pi_over_2 - atan_unit(one / ax);
191 }
192 return neg ? -result : result;
193 }
194
195 static FASTLED_FORCE_INLINE s16x16 atan2(s16x16 y, s16x16 x) FL_NOEXCEPT {
196 constexpr s16x16 pi(3.1415926f);
197 constexpr s16x16 pi_over_2(1.5707963f);
198 if (x.mValue == 0 && y.mValue == 0) return s16x16();
199 if (x.mValue == 0) return y.mValue > 0 ? pi_over_2 : -pi_over_2;
200 if (y.mValue == 0) return x.mValue > 0 ? s16x16() : pi;
201 s16x16 ax = abs(x);
202 s16x16 ay = abs(y);
203 s16x16 a;
204 if (ax >= ay) {
205 a = atan_unit(ay / ax);
206 } else {
207 a = pi_over_2 - atan_unit(ax / ay);
208 }
209 if (x.mValue < 0) a = pi - a;
210 if (y.mValue < 0) a = -a;
211 return a;
212 }

Callers

nothing calls this directly

Calls 15

clampFunction · 0.85
sqrtFunction · 0.85
exp2_fpFunction · 0.85
log2_fpFunction · 0.85
floorFunction · 0.85
ceilFunction · 0.85
atanFunction · 0.85
asinFunction · 0.85
acosFunction · 0.85
highest_bitFunction · 0.85
s16x16Function · 0.70
_highest_bit_stepFunction · 0.70

Tested by

no test coverage detected