FastLED 3.10.8
Loading...
Searching...
No Matches

◆ FL_DISABLE_WARNING()

FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING ( float- equal)

Definition at line 13 of file transform.cpp.hpp.

15 {
16
17vec2f TransformFloatImpl::transform(const vec2f &xy) const FL_NO_EXCEPT {
18 if (is_identity()) {
19 return xy;
20 }
21 float x = xy.x;
22 float y = xy.y;
23 if (scale_x != 1.0f) {
24 x *= scale_x;
25 }
26 if (scale_y != 1.0f) {
27 y *= scale_y;
28 }
29 // Assume that adding floats is fast when offset_x == 0.0f
30 x += offset_x;
31 y += offset_y;
32
33 const bool has_rotation = (rotation != 0.0f);
34
35 if (has_rotation) {
36 float radians = rotation * 2 * FL_PI;
37 float cos_theta = cosf(radians);
38 float sin_theta = sinf(radians);
39 float x_rotated = x * cos_theta - y * sin_theta;
40 float y_rotated = x * sin_theta + y * cos_theta;
41 return vec2f(x_rotated, y_rotated);
42 }
43 return vec2f(x, y);
44}
45
46Transform16 Transform16::ToBounds(alpha16 max_value) FL_NO_EXCEPT {
47 Transform16 tx;
48 // Compute a Q16 “scale” so that:
49 // (alpha16 * scale) >> 16 == max_value when alpha16==0xFFFF
50 alpha16 scale16 = 0;
51 if (max_value) {
52 // numerator = max_value * 2^16
53 u32 numer = static_cast<u32>(max_value) << 16;
54 // denom = 0xFFFF; use ceil so 0xFFFF→max_value exactly:
55 u32 scale32 = numer / 0xFFFF;
56 scale16 = static_cast<alpha16>(scale32);
57 }
58 tx.scale_x = scale16;
59 tx.scale_y = scale16;
60 tx.offset_x = 0;
61 tx.offset_y = 0;
62 tx.rotation = 0;
63 return tx;
64}
65
66Transform16 Transform16::ToBounds(const vec2<alpha16> &min,
67 const vec2<alpha16> &max, alpha16 rotation) FL_NO_EXCEPT {
68 Transform16 tx;
69 // Compute a Q16 “scale” so that:
70 // (alpha16 * scale) >> 16 == max_value when alpha16==0xFFFF
71 alpha16 scale16 = 0;
72 if (max.x > min.x) {
73 // numerator = max_value * 2^16
74 u32 numer = static_cast<u32>(max.x - min.x) << 16;
75 // denom = 0xFFFF; use ceil so 0xFFFF→max_value exactly:
76 u32 scale32 = numer / 0xFFFF;
77 scale16 = static_cast<alpha16>(scale32);
78 }
79 tx.scale_x = scale16;
80 if (max.y > min.y) {
81 // numerator = max_value * 2^16
82 u32 numer = static_cast<u32>(max.y - min.y) << 16;
83 // denom = 0xFFFF; use ceil so 0xFFFF→max_value exactly:
84 u32 scale32 = numer / 0xFFFF;
85 scale16 = static_cast<alpha16>(scale32);
86 }
87 tx.scale_y = scale16;
88 tx.offset_x = min.x;
89 tx.offset_y = min.y;
90 tx.rotation = rotation;
91 return tx;
92}
93
94vec2<alpha16> Transform16::transform(const vec2<alpha16> &xy) const FL_NO_EXCEPT {
95 vec2<alpha16> out = xy;
96
97 // 1) Rotate around the 16‑bit center first
98 if (rotation != 0) {
99 constexpr i32 MID = 0x7FFF; // center of 0…0xFFFF interval
100
101 // bring into signed centered coords
102 i32 x = i32(out.x) - MID;
103 i32 y = i32(out.y) - MID;
104
105 // Q15 cosine & sine
106 i32 c = cos16(rotation); // [-32768..+32767]
107 i32 s = sin16(rotation);
108
109 // rotate & truncate
110 i32 xr = (x * c - y * s) >> 15;
111 i32 yr = (x * s + y * c) >> 15;
112
113 // shift back into [0…0xFFFF]
114 out.x = alpha16(xr + MID);
115 out.y = alpha16(yr + MID);
116 }
117
118 // 2) Then scale in X/Y (Q16 → map32_to_16)
119 if (scale_x != 0xFFFF) {
120 u32 tx = u32(out.x) * scale_x;
121 out.x = map32_to_16(tx);
122 }
123 if (scale_y != 0xFFFF) {
124 u32 ty = u32(out.y) * scale_y;
125 out.y = map32_to_16(ty);
126 }
127
128 // 3) Finally translate
129 if (offset_x)
130 out.x = alpha16(out.x + offset_x);
131 if (offset_y)
132 out.y = alpha16(out.y + offset_y);
133
134 return out;
135}
136
137float TransformFloatImpl::scale() const FL_NO_EXCEPT { return fl::min(scale_x, scale_y); }
138
139void TransformFloatImpl::set_scale(float scale) FL_NO_EXCEPT {
140 scale_x = scale;
141 scale_y = scale;
142}
143
144bool TransformFloatImpl::is_identity() const FL_NO_EXCEPT {
145 return (scale_x == 1.0f && scale_y == 1.0f && offset_x == 0.0f &&
146 offset_y == 0.0f && rotation == 0.0f);
147}
148
149Matrix3x3f TransformFloat::compile() const FL_NO_EXCEPT {
150 Matrix3x3f out;
151 out.m[0][0] = scale_x() * cosf(rotation() * 2.0f * FL_PI);
152 out.m[0][1] = -scale_y() * sinf(rotation() * 2.0f * FL_PI);
153 out.m[0][2] = offset_x();
154 out.m[1][0] = scale_x() * sinf(rotation() * 2.0f * FL_PI);
155 out.m[1][1] = scale_y() * cosf(rotation() * 2.0f * FL_PI);
156 out.m[1][2] = offset_y();
157 out.m[2][2] = 1.0f;
158 return out;
159}
160
161} // namespace fl
int y
Definition simple.h:93
int x
Definition simple.h:92
uint32_t scale_y[NUM_LAYERS]
Definition Fire2023.h:95
uint32_t scale_x[NUM_LAYERS]
Definition Fire2023.h:94
fl::UISlider scale("Scale", 4,.1, 4,.1)
unsigned int xy(unsigned int x, unsigned int y)
constexpr common_type_t< T, U > max(T a, U b) FL_NO_EXCEPT
Definition math.h:75
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NO_EXCEPT
Memory functions are available in fl:: namespace via fl/stl/cstring.h Using declarations cannot work ...
Definition math.h:71
constexpr T radians(T deg) FL_NO_EXCEPT
Definition math.h:530
u16 map32_to_16(u32 x) FL_NO_EXCEPT
Definition intmap.h:72
#define FL_PI
Definition math.h:26
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NO_EXCEPT
Definition math.h:71
float sinf(float value) FL_NO_EXCEPT
Definition math.h:360
vec2< float > vec2f
Definition geometry.h:333
float cosf(float value) FL_NO_EXCEPT
Definition math.h:366
#define FL_NO_EXCEPT

References fl::TransformFloat::compile(), fl::cosf(), FL_NO_EXCEPT, FL_PI, fl::TransformFloatImpl::is_identity(), fl::map32_to_16(), max(), fl::min(), min(), radians(), fl::TransformFloatImpl::scale(), scale, scale_x, scale_y, fl::TransformFloatImpl::set_scale(), fl::sinf(), fl::Transform16::ToBounds(), fl::Transform16::transform(), fl::TransformFloatImpl::transform(), x, xy(), and y.

+ Here is the call graph for this function: