6 if (den.raw_value() == 0)
9 return ae::q20_12_t{0};
11 return ae::q20_12_t::from_raw_value(divf32(num.raw_value(), den.raw_value()));
16 if (v.raw_value() < 0)
19 return ae::q20_12_t{0};
21 uint32_t raw = sqrtf32(
static_cast<uint32_t
>(v.raw_value()));
22 return ae::q20_12_t::from_raw_value(
static_cast<int32_t
>(raw));
27 if (den.raw_value() == 0)
30 return ae::q20_12_t{0};
32 return ae::q20_12_t::from_raw_value(mod32(num.raw_value(), den.raw_value()));
37 return static_cast<ae::angle16_t
>((
static_cast<int32_t
>(radians.raw_value()) * 5215) / 4096);
42 return static_cast<ae::angle16_t
>((
static_cast<int64_t
>(degrees.raw_value()) * DEGREES_IN_CIRCLE / 360) >> 12);
47 int32_t raw_rad = (
static_cast<int32_t
>(angle) * 51472) >> 16;
48 return ae::q20_12_t::from_raw_value(raw_rad);
53 return ae::q4_12_t::from_raw_value(sinLerp(
radiansToAngle(radians)));
58 return ae::q4_12_t::from_raw_value(sinLerp(angle));
63 return ae::q4_12_t::from_raw_value(cosLerp(
radiansToAngle(radians)));
68 return ae::q4_12_t::from_raw_value(cosLerp(angle));
73 return ae::q20_12_t::from_raw_value(tanLerp(
radiansToAngle(radians)));
78 return asinLerp(ratio.raw_value());
83 return acosLerp(ratio.raw_value());
87 ae::q20_12_t x1, ae::q20_12_t y1, ae::q20_12_t z1, ae::q20_12_t x2, ae::q20_12_t y2, ae::q20_12_t z2)
90 s32 vec1[3] = {x1.raw_value(), y1.raw_value(), z1.raw_value()};
91 s32 vec2[3] = {x2.raw_value(), y2.raw_value(), z2.raw_value()};
92 return ae::q20_12_t::from_raw_value(dotf32(vec1, vec2));
97 return dot(x, y, z, x, y, z);
102 return ae::q20_12_t::from_raw_value(sqrtf32(
lengthSq(x, y, z).raw_value()));
107 s32 vec[3] = {x.raw_value(), y.raw_value(), z.raw_value()};
111 x = ae::q20_12_t::from_raw_value(vec[0]);
112 y = ae::q20_12_t::from_raw_value(vec[1]);
113 z = ae::q20_12_t::from_raw_value(vec[2]);
118 uint32_t r =
static_cast<uint32_t
>(rand()) % 4096;
119 return ae::q20_12_t::from_raw_value(
static_cast<int32_t
>(r));
124 if (y.raw_value() == 0 && x.raw_value() == 0)
126 return ae::q20_12_t{0};
128 return ae::q20_12_t::from_raw_value(atan2_f32(y.raw_value(), x.raw_value()));
133 return atan2(y, ae::q20_12_t{1});
138 u32 wholeSeconds =
static_cast<u32
>(seconds);
139 ae::q20_12_t fractionalSeconds = seconds - ae::q20_12_t{wholeSeconds};
140 u32 fractionalSamples =
static_cast<u32
>(fractionalSeconds * sampleRate);
141 return (wholeSeconds * sampleRate) + fractionalSamples;
159 return a + (b - a) * t;
164 const ae::q20_12_t delta = ae::q20_12_t{b - a} * t;
165 return a +
static_cast<int>(delta);
170 t =
clamp(t, ae::q20_12_t{0}, ae::q20_12_t{1});
177 return t * (ae::q20_12_t{2} - t);
180 if (t < ae::q20_12_t::from_raw_value(2048))
182 return ae::q20_12_t{2} * t * t;
185 return ae::q20_12_t{-1} + (ae::q20_12_t{4} - ae::q20_12_t{2} * t) * t;
191 const ae::q20_12_t f = t - ae::q20_12_t{1};
192 return f * f * f + ae::q20_12_t{1};
197 const ae::q20_12_t s = ae::q20_12_t::from_raw_value(6970);
198 return t * t * ((s + ae::q20_12_t{1}) * t - s);
202 const ae::q20_12_t s = ae::q20_12_t::from_raw_value(6970);
203 const ae::q20_12_t f = t - ae::q20_12_t{1};
204 return f * f * ((s + ae::q20_12_t{1}) * f + s) + ae::q20_12_t{1};
ae::q20_12_t clamp(ae::q20_12_t v, ae::q20_12_t lo, ae::q20_12_t hi)
Clamps a Q20.12 value to [lo, hi].
ae::q20_12_t lengthSq(ae::q20_12_t x, ae::q20_12_t y, ae::q20_12_t z)
Computes the squared length of a Q20.12 3D vector.
ae::q4_12_t cos(ae::angle16_t angle)
Cosine of a cyclic angle.
ae::q4_12_t sin(ae::angle16_t angle)
Sine of a cyclic angle.
ae::q20_12_t sqrt(ae::q20_12_t v)
Computes the square root of a Q20.12 value.
ae::q20_12_t ease(EaseMode mode, ae::q20_12_t t)
Applies an easing curve to a normalized time value.
ae::q20_12_t angleToRadians(ae::angle16_t angle)
Converts a cyclic angle to radians (Q20.12).
ae::angle16_t asin(ae::q4_12_t ratio)
Computes the arcsine of a ratio.
ae::angle16_t degreesToCyclicAngle(ae::q20_12_t degrees)
Converts an angle in degrees (Q20.12) to a cyclic angle.
ae::angle16_t acos(ae::q4_12_t ratio)
Computes the arccosine of a ratio.
ae::angle16_t radiansToAngle(ae::q20_12_t radians)
Converts an angle in radians (Q20.12).
void normalize(ae::q20_12_t &x, ae::q20_12_t &y, ae::q20_12_t &z)
Normalizes a Q20.12 3D vector in place.
ae::q20_12_t atan2(ae::q20_12_t y, ae::q20_12_t x)
Computes the angle (in radians) between the positive x-axis and (x, y).
ae::q20_12_t length(ae::q20_12_t x, ae::q20_12_t y, ae::q20_12_t z)
Computes the length of a Q20.12 3D vector.
ae::q20_12_t div(ae::q20_12_t num, ae::q20_12_t den)
Divides two Q20.12 values.
ae::q20_12_t tan(ae::q20_12_t radians)
Tangent, accepting radians (Q20.12).
ae::q20_12_t lerp(ae::q20_12_t a, ae::q20_12_t b, ae::q20_12_t t)
Linearly interpolates two Q20.12 values.
ae::q20_12_t atan(ae::q20_12_t y)
Computes the arctangent of a single ratio.
ae::q20_12_t randFrac()
Returns a uniformly distributed random fraction from 0 to 1.
u32 secondsToSamples(ae::q20_12_t seconds, u32 sampleRate)
Converts a Q20.12 seconds value to a sample count, avoiding overflow when seconds * sampleRate exceed...
EaseMode
Easing curves for fixed-point interpolation (t in [0, 1]).
ae::q20_12_t mod(ae::q20_12_t num, ae::q20_12_t den)
Computes the modulo of two Q20.12 values.
ae::q20_12_t dot(ae::q20_12_t x1, ae::q20_12_t y1, ae::q20_12_t z1, ae::q20_12_t x2, ae::q20_12_t y2, ae::q20_12_t z2)
Computes the dot product of two Q20.12 3D vectors.
void logMessage(LogSeverity severity, std::string_view message, std::source_location location)
Logs a diagnostic message and halts only for fatal messages.
Util to handle error logging.