| 14 | namespace fl { |
| 15 | |
| 16 | vec2f TransformFloatImpl::transform(const vec2f &xy) const { |
| 17 | if (is_identity()) { |
| 18 | return xy; |
| 19 | } |
| 20 | float x = xy.x; |
| 21 | float y = xy.y; |
| 22 | if (scale_x != 1.0f) { |
| 23 | x *= scale_x; |
| 24 | } |
| 25 | if (scale_y != 1.0f) { |
| 26 | y *= scale_y; |
| 27 | } |
| 28 | // Assume that adding floats is fast when offset_x == 0.0f |
| 29 | x += offset_x; |
| 30 | y += offset_y; |
| 31 | |
| 32 | const bool has_rotation = (rotation != 0.0f); |
| 33 | |
| 34 | if (has_rotation) { |
| 35 | float radians = rotation * 2 * FL_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 | } |
| 42 | return vec2f(x, y); |
| 43 | } |
| 44 | |
| 45 | Transform16 Transform16::ToBounds(alpha16 max_value) { |
| 46 | Transform16 tx; |