14 {
15
16vec2f TransformFloatImpl::transform(
const vec2f &
xy)
const {
17 if (is_identity()) {
19 }
24 }
27 }
28
31
32 const bool has_rotation = (rotation != 0.0f);
33
34 if (has_rotation) {
38 float x_rotated =
x * cos_theta -
y * sin_theta;
39 float y_rotated =
x * sin_theta +
y * cos_theta;
40 return vec2f(x_rotated, y_rotated);
41 }
43}
44
45Transform16 Transform16::ToBounds(alpha16 max_value) {
46 Transform16 tx;
47
48
49 alpha16 scale16 = 0;
50 if (max_value) {
51
52 u32 numer = static_cast<u32>(max_value) << 16;
53
54 u32 scale32 = numer / 0xFFFF;
55 scale16 = static_cast<alpha16>(scale32);
56 }
57 tx.scale_x = scale16;
58 tx.scale_y = scale16;
59 tx.offset_x = 0;
60 tx.offset_y = 0;
61 tx.rotation = 0;
62 return tx;
63}
64
65Transform16 Transform16::ToBounds(
const vec2<alpha16> &
min,
66 const vec2<alpha16> &
max, alpha16 rotation) {
67 Transform16 tx;
68
69
70 alpha16 scale16 = 0;
72
73 u32 numer =
static_cast<u32
>(
max.x -
min.x) << 16;
74
75 u32 scale32 = numer / 0xFFFF;
76 scale16 = static_cast<alpha16>(scale32);
77 }
78 tx.scale_x = scale16;
80
81 u32 numer =
static_cast<u32
>(
max.y -
min.y) << 16;
82
83 u32 scale32 = numer / 0xFFFF;
84 scale16 = static_cast<alpha16>(scale32);
85 }
86 tx.scale_y = scale16;
89 tx.rotation = rotation;
90 return tx;
91}
92
93vec2<alpha16> Transform16::transform(
const vec2<alpha16> &
xy)
const {
94 vec2<alpha16> out =
xy;
95
96
97 if (rotation != 0) {
98 constexpr i32 MID = 0x7FFF;
99
100
101 i32
x = i32(out.x) - MID;
102 i32
y = i32(out.y) - MID;
103
104
105 i32 c = cos16(rotation);
106 i32 s = sin16(rotation);
107
108
109 i32 xr = (
x * c -
y * s) >> 15;
110 i32 yr = (
x * s +
y * c) >> 15;
111
112
113 out.x = alpha16(xr + MID);
114 out.y = alpha16(yr + MID);
115 }
116
117
121 }
125 }
126
127
128 if (offset_x)
129 out.x = alpha16(out.x + offset_x);
130 if (offset_y)
131 out.y = alpha16(out.y + offset_y);
132
133 return out;
134}
135
137
138void TransformFloatImpl::set_scale(
float scale) {
141}
142
143bool TransformFloatImpl::is_identity() const {
145 offset_y == 0.0f && rotation == 0.0f);
146}
147
148Matrix3x3f TransformFloat::compile() const {
149 Matrix3x3f out;
152 out.m[0][2] = offset_x();
155 out.m[1][2] = offset_y();
156 out.m[2][2] = 1.0f;
157 return out;
158}
159
160}
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
Memory functions are available in fl:: namespace via fl/stl/cstring.h Using declarations cannot work ...
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
constexpr T radians(T deg) FL_NOEXCEPT
uint32_t scale_y[NUM_LAYERS]
uint32_t scale_x[NUM_LAYERS]
fl::UISlider scale("Scale", 4,.1, 4,.1)
unsigned int xy(unsigned int x, unsigned int y)
u16 map32_to_16(u32 x) FL_NOEXCEPT
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
float sinf(float value) FL_NOEXCEPT
float cosf(float value) FL_NOEXCEPT