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) {
35 float radians = rotation * 2 *
PI;
36 float cos_theta = cosf(radians);
37 float sin_theta = sinf(radians);
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
50 if (max_value) {
51
52 u32 numer = static_cast<u32>(max_value) << 16;
53
54 u32 scale32 = numer / 0xFFFF;
56 }
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
71 if (max.x > min.x) {
72
73 u32 numer = static_cast<u32>(max.x - min.x) << 16;
74
75 u32 scale32 = numer / 0xFFFF;
77 }
79 if (max.y > min.y) {
80
81 u32 numer = static_cast<u32>(max.y - min.y) << 16;
82
83 u32 scale32 = numer / 0xFFFF;
85 }
87 tx.offset_x = min.x;
88 tx.offset_y = min.y;
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
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;
150 out.m[0][0] =
scale_x() * cosf(rotation() * 2.0f *
PI);
151 out.m[0][1] = -
scale_y() * sinf(rotation() * 2.0f *
PI);
152 out.m[0][2] = offset_x();
153 out.m[1][0] =
scale_x() * sinf(rotation() * 2.0f *
PI);
154 out.m[1][1] =
scale_y() * cosf(rotation() * 2.0f *
PI);
155 out.m[1][2] = offset_y();
156 out.m[2][2] = 1.0f;
157 return out;
158}
159
160}
uint32_t scale_y[NUM_LAYERS]
uint32_t scale_x[NUM_LAYERS]
unsigned int xy(unsigned int x, unsigned int y)
LIB8STATIC uint16_t scale16(uint16_t i, fract16 scale)
Scale a 16-bit unsigned value by an 16-bit value, which is treated as the numerator of a fraction who...
LIB8STATIC int16_t cos16(uint16_t theta)
Fast 16-bit approximation of cos(x).
#define sin16
Platform-independent alias of the fast sin implementation.
LIB8STATIC_ALWAYS_INLINE uint16_t map32_to_16(uint32_t x)