| Flutter Impeller |

Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
impeller::RSTransform Struct Reference

`#include <rstransform.h>`

## Public Member Functions
constexpr | RSTransform ()
constexpr | RSTransform (Scalar scaled_cos, Scalar scaled_sin, Scalar translate_x, Scalar translate_y)
bool | IsAxisAligned () const
Matrix | GetMatrix () const
void | GetQuad (Scalar width, Scalar height, Quad &quad) const
Quad | GetQuad (Scalar width, Scalar height) const
Quad | GetQuad (Size size) const
std::optional< Rect > | GetBounds (Scalar width, Scalar height) const
std::optional< Rect > | GetBounds (Size size) const

## Static Public Member Functions
static RSTransform | Make (Point origin, Scalar scale, Radians radians)

## Public Attributes
Scalar | scaled_cos
Scalar | scaled_sin
Scalar | translate_x
Scalar | translate_y

## Detailed Description

A utility struct that stores a simple transform composed of a translation, a rotation, and a uniform scale.

This transform is used by drawAtlas to transform the sprites. This structure mirrors the Flutter RSTransform class.

Definition at line 20 of file rstransform.h.

## Constructor & Destructor Documentation

## ◆ RSTransform() [1/2]

constexpr impeller::RSTransform::RSTransform | ( |  | ) |
| inline constexpr

Definition at line 21 of file rstransform.h.

22 : scaled_cos(1.0f),
23 scaled_sin(0.0f),
24 translate_x(0.0f),
25 translate_y(0.0f) {}
impeller::RSTransform::translate_y
Scalar translate_y
Definition: rstransform.h:46
impeller::RSTransform::translate_x
Scalar translate_x
Definition: rstransform.h:45
impeller::RSTransform::scaled_sin
Scalar scaled_sin
Definition: rstransform.h:44
impeller::RSTransform::scaled_cos
Scalar scaled_cos
Definition: rstransform.h:43

## ◆ RSTransform() [2/2]

constexpr impeller::RSTransform::RSTransform | ( | Scalar | scaled_cos,
|  | Scalar | scaled_sin,
|  | Scalar | translate_x,
|  | Scalar | translate_y
| ) |  |
| inline constexpr

Definition at line 27 of file rstransform.h.

31 : scaled_cos(scaled_cos),
32 scaled_sin(scaled_sin),
33 translate_x(translate_x),
34 translate_y(translate_y) {}

## Member Function Documentation

## ◆ GetBounds() [1/2]

std::optional< Rect > impeller::RSTransform::GetBounds | ( | Scalar | width,
|  | Scalar | height
| ) |  | const

Returns the bounds of the 4 corner points of the transformed quad for a sub-image of the indicated size.

Definition at line 49 of file rstransform.cc.

49 {
50 return Rect::MakePointBounds(GetQuad(width, height));
51 }
impeller::RSTransform::GetQuad
void GetQuad(Scalar width, Scalar height, Quad &quad) const
Definition: rstransform.cc:24
impeller::TRect< Scalar >::MakePointBounds
constexpr static std::optional< TRect > MakePointBounds(const U &value)
Definition: rect.h:165

References GetQuad(), and impeller::TRect< Scalar >::MakePointBounds().

Referenced by impeller::DlAtlasGeometry::ComputeBoundingBox().

## ◆ GetBounds() [2/2]

std::optional< Rect > impeller::RSTransform::GetBounds | ( | Size | size | ) | const

Definition at line 53 of file rstransform.cc.

53 {
54 return Rect::MakePointBounds(GetQuad(size));
55 }

References GetQuad(), and impeller::TRect< Scalar >::MakePointBounds().

## ◆ GetMatrix()

Matrix impeller::RSTransform::GetMatrix | ( |  | ) | const

Definition at line 15 of file rstransform.cc.

15 {
16 // clang-format off
17 return Matrix::MakeRow(scaled_cos, -scaled_sin, 0.0f, translate_x,
18 scaled_sin, scaled_cos, 0.0f, translate_y,
19 0.0f, 0.0f, 1.0f, 0.0f,
20 0.0f, 0.0f, 0.0f, 1.0f);
21 // clang-format on
22 }
impeller::Matrix::MakeRow
static constexpr Matrix MakeRow(Scalar m0, Scalar m1, Scalar m2, Scalar m3, Scalar m4, Scalar m5, Scalar m6, Scalar m7, Scalar m8, Scalar m9, Scalar m10, Scalar m11, Scalar m12, Scalar m13, Scalar m14, Scalar m15)
Definition: matrix.h:83

References impeller::Matrix::MakeRow(), scaled_cos, scaled_sin, translate_x, and translate_y.

## ◆ GetQuad() [1/3]

Quad impeller::RSTransform::GetQuad | ( | Scalar | width,
|  | Scalar | height
| ) |  | const

Definition at line 37 of file rstransform.cc.

37 {
38 Quad quad;
39 GetQuad(width, height, quad);
40 return quad;
41 }
impeller::Quad
std::array< Point, 4 > Quad
Definition: point.h:430

References GetQuad().

## ◆ GetQuad() [2/3]

void impeller::RSTransform::GetQuad | ( | Scalar | width,
|  | Scalar | height,
|  | Quad & | quad
| ) |  | const

Returns the 4 corner points of the transformed quad for a sub-image of the indicated size in the same order as Rect::GetPoints.

The order is UpperLeft, UpperRight, LowerLeft, LowerRight

Definition at line 24 of file rstransform.cc.

24 {
25 Point origin = {translate_x, translate_y};
26 Point dx = width * Point{scaled_cos, scaled_sin};
27 Point dy = height * Point{-scaled_sin, scaled_cos};
28 quad = {
29 // Ordered in the same Z pattern as Rect::GetPoints()
30 origin,
31 origin + dx,
32 origin + dy,
33 origin + dx + dy,
34 };
35 }
impeller::Point
TPoint< Scalar > Point
Definition: point.h:425

References scaled_cos, scaled_sin, translate_x, and translate_y.

Referenced by impeller::DlAtlasGeometry::CreateBlendVertexBuffer(), impeller::DlAtlasGeometry::CreateSimpleVertexBuffer(), GetBounds(), and GetQuad().

## ◆ GetQuad() [3/3]

Quad impeller::RSTransform::GetQuad | ( | Size | size | ) | const

Definition at line 43 of file rstransform.cc.

43 {
44 Quad quad;
45 GetQuad(size.width, size.height, quad);
46 return quad;
47 }

References GetQuad(), impeller::TSize< T >::height, and impeller::TSize< T >::width.

## ◆ IsAxisAligned()

bool impeller::RSTransform::IsAxisAligned | ( |  | ) | const

Returns true iff the resulting transformed quad will be aligned with the axes, even if rotated by a quadrant rotation.

Definition at line 11 of file rstransform.cc.

11 {
12 return scaled_cos == 0.0f || scaled_sin == 0.0f;
13 }

References scaled_cos, and scaled_sin.

## ◆ Make()

static RSTransform impeller::RSTransform::Make | ( | Point | origin,
|  | Scalar | scale,
|  | Radians | radians
| ) |  |
| inline static

Constructs an RSTransform from the indicated origin, uniform scale, and radians rotation.

Definition at line 38 of file rstransform.h.

38 {
39 auto scaled_cos_sin = Matrix::CosSin(radians) * scale;
40 return {scaled_cos_sin.x, scaled_cos_sin.y, origin.x, origin.y};
41 }
impeller::Matrix::CosSin
static Vector2 CosSin(Radians radians)
Definition: matrix.h:685
impeller::TPoint::x
Type x
Definition: point.h:31

References impeller::Matrix::CosSin(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by impeller::testing::TEST().

## Member Data Documentation

## ◆ scaled_cos

Scalar impeller::RSTransform::scaled_cos

Definition at line 43 of file rstransform.h.

Referenced by GetMatrix(), GetQuad(), IsAxisAligned(), and std::operator<<().

## ◆ scaled_sin

Scalar impeller::RSTransform::scaled_sin

Definition at line 44 of file rstransform.h.

Referenced by GetMatrix(), GetQuad(), IsAxisAligned(), and std::operator<<().

## ◆ translate_x

Scalar impeller::RSTransform::translate_x

Definition at line 45 of file rstransform.h.

Referenced by GetMatrix(), GetQuad(), and std::operator<<().

## ◆ translate_y

Scalar impeller::RSTransform::translate_y

Definition at line 46 of file rstransform.h.

Referenced by GetMatrix(), GetQuad(), and std::operator<<().

The documentation for this struct was generated from the following files:

- impeller/geometry/rstransform.h
- impeller/geometry/rstransform.cc