| Flutter Impeller |

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

A 4x4 matrix using column-major storage. More...

`#include <matrix.h>`

## Public Member Functions
constexpr | Matrix ()
constexpr | Matrix (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)
| Matrix (const MatrixDecomposition &decomposition)
constexpr Matrix | Basis () const
constexpr Matrix | Translate (const Vector3 &t) const
constexpr Matrix | Scale (const Vector3 &s) const
constexpr Matrix | Multiply (const Matrix &o) const
constexpr Matrix | Transpose () const
Matrix | Invert () const
Scalar | GetDeterminant () const
Scalar | GetMaxBasisLength () const
Scalar | GetMaxBasisLengthXY () const
constexpr Vector3 | GetBasisX () const
constexpr Vector3 | GetBasisY () const
constexpr Vector3 | GetBasisZ () const
constexpr Vector3 | GetScale () const
constexpr Scalar | GetDirectionScale (Vector3 direction) const
constexpr bool | IsAffine () const
constexpr bool | HasPerspective () const
constexpr bool | IsAligned (Scalar tolerance=0) const
constexpr bool | IsIdentity () const
constexpr bool | IsTranslationScaleOnly () const
| Returns true if the matrix has a scale-only basis and is non-projective. Note that an identity matrix meets this criteria. More...
std::optional< MatrixDecomposition > | Decompose () const
constexpr bool | operator== (const Matrix &m) const
constexpr bool | operator!= (const Matrix &m) const
Matrix | operator+ (const Vector3 &t) const
Matrix | operator- (const Vector3 &t) const
Matrix | operator* (const Matrix &m) const
Matrix | operator+ (const Matrix &m) const
constexpr Vector4 | operator* (const Vector4 &v) const
constexpr Vector3 | operator* (const Vector3 &v) const
constexpr Point | operator* (const Point &v) const
constexpr Vector4 | TransformDirection (const Vector4 &v) const
constexpr Vector3 | TransformDirection (const Vector3 &v) const
constexpr Vector2 | TransformDirection (const Vector2 &v) const

## Static Public Member Functions
static constexpr Matrix | MakeColumn (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)
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)
static constexpr Matrix | MakeTranslation (const Vector3 &t)
static constexpr Matrix | MakeScale (const Vector3 &s)
static constexpr Matrix | MakeScale (const Vector2 &s)
static constexpr Matrix | MakeSkew (Scalar sx, Scalar sy)
static Matrix | MakeRotation (Quaternion q)
static Matrix | MakeRotation (Scalar radians, const Vector4 &r)
static Matrix | MakeRotationX (Radians r)
static Matrix | MakeRotationY (Radians r)
static Matrix | MakeRotationZ (Radians r)
template<class T >
static constexpr Matrix | MakeOrthographic (TSize< T > size)
static constexpr Matrix | MakePerspective (Radians fov_y, Scalar aspect_ratio, Scalar z_near, Scalar z_far)
template<class T >
static constexpr Matrix | MakePerspective (Radians fov_y, TSize< T > size, Scalar z_near, Scalar z_far)
static constexpr Matrix | MakeLookAt (Vector3 position, Vector3 target, Vector3 up)

## Public Attributes
union {
Scalar m [16]
Scalar e [4][4]
Vector4 vec [4]
}; |

## Detailed Description

A 4x4 matrix using column-major storage.

            Utility methods that need to make assumptions about normalized
            device coordinates must use the following convention:
              * Left-handed coordinate system. Positive rotation is
                clockwise about axis of rotation.
              * Lower left corner is -1.0f, -1.0.
              * Upper right corner is  1.0f,  1.0.
              * Visible z-space is from 0.0 to 1.0.
                * This is NOT the same as OpenGL! Be careful.
              * NDC origin is at (0.0f, 0.0f, 0.5f).

Definition at line 36 of file matrix.h.

## Constructor & Destructor Documentation

## ◆ Matrix() [1/3]

constexpr impeller::Matrix::Matrix | ( |  | ) |
| inline constexpr

Constructs a default identity matrix.

Definition at line 46 of file matrix.h.

48 : vec{ Vector4(1.0f, 0.0f, 0.0f, 0.0f),
49 Vector4(0.0f, 1.0f, 0.0f, 0.0f),
50 Vector4(0.0f, 0.0f, 1.0f, 0.0f),
51 Vector4(0.0f, 0.0f, 0.0f, 1.0f)} {}

Referenced by Basis(), MakeColumn(), MakeRotation(), MakeRotationX(), MakeRotationY(), MakeRotationZ(), MakeRow(), MakeScale(), MakeSkew(), MakeTranslation(), Multiply(), operator+(), Scale(), and Translate().

## ◆ Matrix() [2/3]

constexpr impeller::Matrix::Matrix | ( | 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
| ) |  |
| inline constexpr

Definition at line 55 of file matrix.h.

59 : vec{Vector4(m0, m1, m2, m3),
60 Vector4(m4, m5, m6, m7),
61 Vector4(m8, m9, m10, m11),
62 Vector4(m12, m13, m14, m15)} {}

## ◆ Matrix() [3/3]

impeller::Matrix::Matrix | ( | const MatrixDecomposition & | decomposition | ) |
| explicit

Definition at line 12 of file matrix.cc.

12 : Matrix() {
13 /*
14 * Apply perspective.
15 */
16 for (int i = 0; i < 4; i++) {
17 e[i][3] = d.perspective.e[i];
18 }
19
20 /*
21 * Apply translation.
22 */
23 for (int i = 0; i < 3; i++) {
24 for (int j = 0; j < 3; j++) {
25 e[3][i] += d.translation.e[j] * e[j][i];
26 }
27 }
28
29 /*
30 * Apply rotation.
31 */
32
33 Matrix rotation;
34
35 const auto x = -d.rotation.x;
36 const auto y = -d.rotation.y;
37 const auto z = -d.rotation.z;
38 const auto w = d.rotation.w;
39
40 /*
41 * Construct a composite rotation matrix from the quaternion values.
42 */
43
44 rotation.e[0][0] = 1.0 - 2.0 * (y * y + z * z);
45 rotation.e[0][1] = 2.0 * (x * y - z * w);
46 rotation.e[0][2] = 2.0 * (x * z + y * w);
47 rotation.e[1][0] = 2.0 * (x * y + z * w);
48 rotation.e[1][1] = 1.0 - 2.0 * (x * x + z * z);
49 rotation.e[1][2] = 2.0 * (y * z - x * w);
50 rotation.e[2][0] = 2.0 * (x * z - y * w);
51 rotation.e[2][1] = 2.0 * (y * z + x * w);
52 rotation.e[2][2] = 1.0 - 2.0 * (x * x + y * y);
53
54 *this = *this * rotation;
55
56 /*
57 * Apply shear.
58 */
59 Matrix shear;
60
61 if (d.shear.e[2] != 0) {
62 shear.e[2][1] = d.shear.e[2];
63 *this = *this * shear;
64 }
65
66 if (d.shear.e[1] != 0) {
67 shear.e[2][1] = 0.0;
68 shear.e[2][0] = d.shear.e[1];
69 *this = *this * shear;
70 }
71
72 if (d.shear.e[0] != 0) {
73 shear.e[2][0] = 0.0;
74 shear.e[1][0] = d.shear.e[0];
75 *this = *this * shear;
76 }
77
78 /*
79 * Apply scale.
80 */
81 for (int i = 0; i < 3; i++) {
82 for (int j = 0; j < 3; j++) {
83 e[i][j] *= d.scale.e[i];
84 }
85 }
86 }

References impeller::Shear::e, impeller::Vector3::e, e, impeller::Vector4::e, impeller::MatrixDecomposition::perspective, impeller::MatrixDecomposition::rotation, impeller::MatrixDecomposition::scale, impeller::MatrixDecomposition::shear, impeller::MatrixDecomposition::translation, impeller::Quaternion::w, impeller::Quaternion::x, impeller::Quaternion::y, and impeller::Quaternion::z.

## Member Function Documentation

## ◆ Basis()

constexpr Matrix impeller::Matrix::Basis | ( |  | ) | const
| inline constexpr

Definition at line 222 of file matrix.h.

222 {
223 // clang-format off
224 return Matrix(
225 m[0], m[1], m[2], 0.0f,
226 m[4], m[5], m[6], 0.0f,
227 m[8], m[9], m[10], 0.0f,
228 0.0f, 0.0f, 0.0f, 1.0
229 );
230 // clang-format on
231 }

References m, and Matrix().

Referenced by GetDirectionScale(), impeller::DirectionalMorphologyFilterContents::GetFilterCoverage(), impeller::DirectionalGaussianBlurFilterContents::GetFilterCoverage(), impeller::MatrixFilterContents::IsTranslationOnly(), and impeller::testing::TEST().

## ◆ Decompose()

std::optional< MatrixDecomposition > impeller::Matrix::Decompose | ( |  | ) | const

Definition at line 217 of file matrix.cc.

217 {
218 /*
219 * Normalize the matrix.
220 */
221 Matrix self = *this;
222
223 if (self.e[3][3] == 0) {
224 return std::nullopt;
225 }
226
227 for (int i = 0; i < 4; i++) {
228 for (int j = 0; j < 4; j++) {
229 self.e[i][j] /= self.e[3][3];
230 }
231 }
232
233 /*
234 * `perspectiveMatrix` is used to solve for perspective, but it also provides
235 * an easy way to test for singularity of the upper 3x3 component.
236 */
237 Matrix perpectiveMatrix = self;
238 for (int i = 0; i < 3; i++) {
239 perpectiveMatrix.e[i][3] = 0;
240 }
241
242 perpectiveMatrix.e[3][3] = 1;
243
244 if (perpectiveMatrix.GetDeterminant() == 0.0) {
245 return std::nullopt;
246 }
247
248 MatrixDecomposition result;
249
250 /*
251 * ==========================================================================
252 * First, isolate perspective.
253 * ==========================================================================
254 */
255 if (self.e[0][3] != 0.0 || self.e[1][3] != 0.0 || self.e[2][3] != 0.0) {
256 /*
257 * prhs is the right hand side of the equation.
258 */
259 const Vector4 rightHandSide(self.e[0][3], //
260 self.e[1][3], //
261 self.e[2][3], //
262 self.e[3][3]);
263
264 /*
265 * Solve the equation by inverting `perspectiveMatrix` and multiplying
266 * prhs by the inverse.
267 */
268
269 result.perspective = perpectiveMatrix.Invert().Transpose() * rightHandSide;
270
271 /*
272 * Clear the perspective partition.
273 */
274 self.e[0][3] = self.e[1][3] = self.e[2][3] = 0;
275 self.e[3][3] = 1;
276 }
277
278 /*
279 * ==========================================================================
280 * Next, the translation.
281 * ==========================================================================
282 */
283 result.translation = {self.e[3][0], self.e[3][1], self.e[3][2]};
284 self.e[3][0] = self.e[3][1] = self.e[3][2] = 0.0;
285
286 /*
287 * ==========================================================================
288 * Next, the scale and shear.
289 * ==========================================================================
290 */
291 Vector3 row[3];
292 for (int i = 0; i < 3; i++) {
293 row[i].x = self.e[i][0];
294 row[i].y = self.e[i][1];
295 row[i].z = self.e[i][2];
296 }
297
298 /*
299 * Compute X scale factor and normalize first row.
300 */
301 result.scale.x = row[0].Length();
302 row[0] = row[0].Normalize();
303
304 /*
305 * Compute XY shear factor and make 2nd row orthogonal to 1st.
306 */
307 result.shear.xy = row[0].Dot(row[1]);
308 row[1] = Vector3::Combine(row[1], 1.0, row[0], -result.shear.xy);
309
310 /*
311 * Compute Y scale and normalize 2nd row.
312 */
313 result.scale.y = row[1].Length();
314 row[1] = row[1].Normalize();
315 result.shear.xy /= result.scale.y;
316
317 /*
318 * Compute XZ and YZ shears, orthogonalize 3rd row.
319 */
320 result.shear.xz = row[0].Dot(row[2]);
321 row[2] = Vector3::Combine(row[2], 1.0, row[0], -result.shear.xz);
322 result.shear.yz = row[1].Dot(row[2]);
323 row[2] = Vector3::Combine(row[2], 1.0, row[1], -result.shear.yz);
324
325 /*
326 * Next, get Z scale and normalize 3rd row.
327 */
328 result.scale.z = row[2].Length();
329 row[2] = row[2].Normalize();
330
331 result.shear.xz /= result.scale.z;
332 result.shear.yz /= result.scale.z;
333
334 /*
335 * At this point, the matrix (in rows[]) is orthonormal.
336 * Check for a coordinate system flip. If the determinant
337 * is -1, then negate the matrix and the scaling factors.
338 */
339 if (row[0].Dot(row[1].Cross(row[2])) < 0) {
340 result.scale.x *= -1;
341 result.scale.y *= -1;
342 result.scale.z *= -1;
343
344 for (int i = 0; i < 3; i++) {
345 row[i].x *= -1;
346 row[i].y *= -1;
347 row[i].z *= -1;
348 }
349 }
350
351 /*
352 * ==========================================================================
353 * Finally, get the rotations out.
354 * ==========================================================================
355 */
356 result.rotation.x =
357 0.5 * sqrt(fmax(1.0 + row[0].x - row[1].y - row[2].z, 0.0));
358 result.rotation.y =
359 0.5 * sqrt(fmax(1.0 - row[0].x + row[1].y - row[2].z, 0.0));
360 result.rotation.z =
361 0.5 * sqrt(fmax(1.0 - row[0].x - row[1].y + row[2].z, 0.0));
362 result.rotation.w =
363 0.5 * sqrt(fmax(1.0 + row[0].x + row[1].y + row[2].z, 0.0));
364
365 if (row[2].y > row[1].z) {
366 result.rotation.x = -result.rotation.x;
367 }
368 if (row[0].z > row[2].x) {
369 result.rotation.y = -result.rotation.y;
370 }
371 if (row[1].x > row[0].y) {
372 result.rotation.z = -result.rotation.z;
373 }
374
375 return result;
376 }

References impeller::Vector3::Combine(), impeller::Vector3::Dot(), impeller::Vector3::e, e, impeller::Vector4::e, GetDeterminant(), Invert(), impeller::Vector3::Length(), impeller::Vector3::Normalize(), impeller::MatrixDecomposition::perspective, impeller::MatrixDecomposition::rotation, impeller::MatrixDecomposition::scale, impeller::MatrixDecomposition::shear, impeller::MatrixDecomposition::translation, Transpose(), impeller::Quaternion::w, impeller::Quaternion::x, impeller::Vector3::x, impeller::Shear::xy, impeller::Shear::xz, impeller::Quaternion::y, impeller::Vector3::y, impeller::Shear::yz, impeller::Quaternion::z, and impeller::Vector3::z.

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

## ◆ GetBasisX()

constexpr Vector3 impeller::Matrix::GetBasisX | ( |  | ) | const
| inline constexpr

Definition at line 295 of file matrix.h.

295 { return Vector3(m[0], m[1], m[2]); }

References m.

Referenced by GetScale().

## ◆ GetBasisY()

constexpr Vector3 impeller::Matrix::GetBasisY | ( |  | ) | const
| inline constexpr

Definition at line 297 of file matrix.h.

297 { return Vector3(m[4], m[5], m[6]); }

References m.

Referenced by GetScale().

## ◆ GetBasisZ()

constexpr Vector3 impeller::Matrix::GetBasisZ | ( |  | ) | const
| inline constexpr

Definition at line 299 of file matrix.h.

299 { return Vector3(m[8], m[9], m[10]); }

References m.

Referenced by GetScale().

## ◆ GetDeterminant()

Scalar impeller::Matrix::GetDeterminant | ( |  | ) | const

Definition at line 162 of file matrix.cc.

162 {
163 auto a00 = e[0][0];
164 auto a01 = e[0][1];
165 auto a02 = e[0][2];
166 auto a03 = e[0][3];
167 auto a10 = e[1][0];
168 auto a11 = e[1][1];
169 auto a12 = e[1][2];
170 auto a13 = e[1][3];
171 auto a20 = e[2][0];
172 auto a21 = e[2][1];
173 auto a22 = e[2][2];
174 auto a23 = e[2][3];
175 auto a30 = e[3][0];
176 auto a31 = e[3][1];
177 auto a32 = e[3][2];
178 auto a33 = e[3][3];
179
180 auto b00 = a00 * a11 - a01 * a10;
181 auto b01 = a00 * a12 - a02 * a10;
182 auto b02 = a00 * a13 - a03 * a10;
183 auto b03 = a01 * a12 - a02 * a11;
184 auto b04 = a01 * a13 - a03 * a11;
185 auto b05 = a02 * a13 - a03 * a12;
186 auto b06 = a20 * a31 - a21 * a30;
187 auto b07 = a20 * a32 - a22 * a30;
188 auto b08 = a20 * a33 - a23 * a30;
189 auto b09 = a21 * a32 - a22 * a31;
190 auto b10 = a21 * a33 - a23 * a31;
191 auto b11 = a22 * a33 - a23 * a32;
192
193 return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
194 }

References e.

Referenced by Decompose().

## ◆ GetDirectionScale()

constexpr Scalar impeller::Matrix::GetDirectionScale | ( | Vector3 | direction | ) | const
| inline constexpr

Definition at line 306 of file matrix.h.

306 {
307 return 1.0f / (this->Basis().Invert() * direction.Normalize()).Length() *
308 direction.Length();
309 }

References Basis(), Invert(), impeller::Vector3::Length(), and impeller::Vector3::Normalize().

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

## ◆ GetMaxBasisLength()

Scalar impeller::Matrix::GetMaxBasisLength | ( |  | ) | const

Definition at line 196 of file matrix.cc.

196 {
197 Scalar max = 0;
198 for (int i = 0; i < 3; i++) {
199 max = std::max(max,
200 e[i][0] * e[i][0] + e[i][1] * e[i][1] + e[i][2] * e[i][2]);
201 }
202 return std::sqrt(max);
203 }

References e.

## ◆ GetMaxBasisLengthXY()

Scalar impeller::Matrix::GetMaxBasisLengthXY | ( |  | ) | const

Definition at line 205 of file matrix.cc.

205 {
206 Scalar max = 0;
207 for (int i = 0; i < 3; i++) {
208 max = std::max(max, e[i][0] * e[i][0] + e[i][1] * e[i][1]);
209 }
210 return std::sqrt(max);
211 }

References e.

Referenced by impeller::Entity::DeriveTextScale().

## ◆ GetScale()

constexpr Vector3 impeller::Matrix::GetScale | ( |  | ) | const
| inline constexpr

Definition at line 301 of file matrix.h.

301 {
302 return Vector3(GetBasisX().Length(), GetBasisY().Length(),
303 GetBasisZ().Length());
304 }

References GetBasisX(), GetBasisY(), and GetBasisZ().

Referenced by impeller::DlDispatcher::drawShadow(), impeller::SceneContents::Render(), and impeller::testing::TEST_P().

## ◆ HasPerspective()

constexpr bool impeller::Matrix::HasPerspective | ( |  | ) | const
| inline constexpr

Definition at line 316 of file matrix.h.

316 {
317 return m[3] != 0 || m[7] != 0 || m[11] != 0 || m[15] != 1;
318 }

References m.

Referenced by impeller::DlDispatcher::drawDisplayList().

## ◆ Invert()

Matrix impeller::Matrix::Invert | ( |  | ) | const

Definition at line 97 of file matrix.cc.

97 {
98 Matrix tmp{
99 m[5] * m[10] * m[15] - m[5] * m[11] * m[14] - m[9] * m[6] * m[15] +
100 m[9] * m[7] * m[14] + m[13] * m[6] * m[11] - m[13] * m[7] * m[10],
101
102 -m[1] * m[10] * m[15] + m[1] * m[11] * m[14] + m[9] * m[2] * m[15] -
103 m[9] * m[3] * m[14] - m[13] * m[2] * m[11] + m[13] * m[3] * m[10],
104
105 m[1] * m[6] * m[15] - m[1] * m[7] * m[14] - m[5] * m[2] * m[15] +
106 m[5] * m[3] * m[14] + m[13] * m[2] * m[7] - m[13] * m[3] * m[6],
107
108 -m[1] * m[6] * m[11] + m[1] * m[7] * m[10] + m[5] * m[2] * m[11] -
109 m[5] * m[3] * m[10] - m[9] * m[2] * m[7] + m[9] * m[3] * m[6],
110
111 -m[4] * m[10] * m[15] + m[4] * m[11] * m[14] + m[8] * m[6] * m[15] -
112 m[8] * m[7] * m[14] - m[12] * m[6] * m[11] + m[12] * m[7] * m[10],
113
114 m[0] * m[10] * m[15] - m[0] * m[11] * m[14] - m[8] * m[2] * m[15] +
115 m[8] * m[3] * m[14] + m[12] * m[2] * m[11] - m[12] * m[3] * m[10],
116
117 -m[0] * m[6] * m[15] + m[0] * m[7] * m[14] + m[4] * m[2] * m[15] -
118 m[4] * m[3] * m[14] - m[12] * m[2] * m[7] + m[12] * m[3] * m[6],
119
120 m[0] * m[6] * m[11] - m[0] * m[7] * m[10] - m[4] * m[2] * m[11] +
121 m[4] * m[3] * m[10] + m[8] * m[2] * m[7] - m[8] * m[3] * m[6],
122
123 m[4] * m[9] * m[15] - m[4] * m[11] * m[13] - m[8] * m[5] * m[15] +
124 m[8] * m[7] * m[13] + m[12] * m[5] * m[11] - m[12] * m[7] * m[9],
125
126 -m[0] * m[9] * m[15] + m[0] * m[11] * m[13] + m[8] * m[1] * m[15] -
127 m[8] * m[3] * m[13] - m[12] * m[1] * m[11] + m[12] * m[3] * m[9],
128
129 m[0] * m[5] * m[15] - m[0] * m[7] * m[13] - m[4] * m[1] * m[15] +
130 m[4] * m[3] * m[13] + m[12] * m[1] * m[7] - m[12] * m[3] * m[5],
131
132 -m[0] * m[5] * m[11] + m[0] * m[7] * m[9] + m[4] * m[1] * m[11] -
133 m[4] * m[3] * m[9] - m[8] * m[1] * m[7] + m[8] * m[3] * m[5],
134
135 -m[4] * m[9] * m[14] + m[4] * m[10] * m[13] + m[8] * m[5] * m[14] -
136 m[8] * m[6] * m[13] - m[12] * m[5] * m[10] + m[12] * m[6] * m[9],
137
138 m[0] * m[9] * m[14] - m[0] * m[10] * m[13] - m[8] * m[1] * m[14] +
139 m[8] * m[2] * m[13] + m[12] * m[1] * m[10] - m[12] * m[2] * m[9],
140
141 -m[0] * m[5] * m[14] + m[0] * m[6] * m[13] + m[4] * m[1] * m[14] -
142 m[4] * m[2] * m[13] - m[12] * m[1] * m[6] + m[12] * m[2] * m[5],
143
144 m[0] * m[5] * m[10] - m[0] * m[6] * m[9] - m[4] * m[1] * m[10] +
145 m[4] * m[2] * m[9] + m[8] * m[1] * m[6] - m[8] * m[2] * m[5]};
146
147 Scalar det =
148 m[0] * tmp.m[0] + m[1] * tmp.m[4] + m[2] * tmp.m[8] + m[3] * tmp.m[12];
149
150 if (det == 0) {
151 return {};
152 }
153
154 det = 1.0 / det;
155
156 return {tmp.m[0] * det, tmp.m[1] * det, tmp.m[2] * det, tmp.m[3] * det,
157 tmp.m[4] * det, tmp.m[5] * det, tmp.m[6] * det, tmp.m[7] * det,
158 tmp.m[8] * det, tmp.m[9] * det, tmp.m[10] * det, tmp.m[11] * det,
159 tmp.m[12] * det, tmp.m[13] * det, tmp.m[14] * det, tmp.m[15] * det};
160 }

References m.

Referenced by Decompose(), GetDirectionScale(), impeller::MatrixFilterContents::GetFilterCoverage(), impeller::Snapshot::GetUVTransform(), impeller::scene::Skin::MakeFromFlatbuffer(), impeller::ColorSourceContents::SetEffectTransform(), impeller::scene::Node::SetGlobalTransform(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ IsAffine()

constexpr bool impeller::Matrix::IsAffine | ( |  | ) | const
| inline constexpr

Definition at line 311 of file matrix.h.

311 {
312 return (m[2] == 0 && m[3] == 0 && m[6] == 0 && m[7] == 0 && m[8] == 0 &&
313 m[9] == 0 && m[10] == 1 && m[11] == 0 && m[14] == 0 && m[15] == 1);
314 }

References m.

## ◆ IsAligned()

constexpr bool impeller::Matrix::IsAligned | ( | Scalar | tolerance = `0` | ) | const
| inline constexpr

Definition at line 320 of file matrix.h.

320 {
321 int v[] = {!ScalarNearlyZero(m[0], tolerance), //
322 !ScalarNearlyZero(m[1], tolerance), //
323 !ScalarNearlyZero(m[2], tolerance), //
324 !ScalarNearlyZero(m[4], tolerance), //
325 !ScalarNearlyZero(m[5], tolerance), //
326 !ScalarNearlyZero(m[6], tolerance), //
327 !ScalarNearlyZero(m[8], tolerance), //
328 !ScalarNearlyZero(m[9], tolerance), //
329 !ScalarNearlyZero(m[10], tolerance)};
330 // Check if all three basis vectors are aligned to an axis.
331 if (v[0] + v[1] + v[2] != 1 || //
332 v[3] + v[4] + v[5] != 1 || //
333 v[6] + v[7] + v[8] != 1) {
334 return false;
335 }
336 // Ensure that none of the basis vectors overlap.
337 if (v[0] + v[3] + v[6] != 1 || //
338 v[1] + v[4] + v[7] != 1 || //
339 v[2] + v[5] + v[8] != 1) {
340 return false;
341 }
342 return true;
343 }

References m, and impeller::ScalarNearlyZero().

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

## ◆ IsIdentity()

constexpr bool impeller::Matrix::IsIdentity | ( |  | ) | const
| inline constexpr

Definition at line 345 of file matrix.h.

345 {
346 return (
347 // clang-format off
348 m[0] == 1.0f && m[1] == 0.0f && m[2] == 0.0f && m[3] == 0.0f &&
349 m[4] == 0.0f && m[5] == 1.0f && m[6] == 0.0f && m[7] == 0.0f &&
350 m[8] == 0.0f && m[9] == 0.0f && m[10] == 1.0f && m[11] == 0.0f &&
351 m[12] == 0.0f && m[13] == 0.0f && m[14] == 0.0f && m[15] == 1.0f
352 // clang-format on
353 );
354 }

References m.

Referenced by impeller::MatrixFilterContents::IsTranslationOnly(), impeller::scene::importer::ProcessNode(), and impeller::testing::TEST_P().

## ◆ IsTranslationScaleOnly()

constexpr bool impeller::Matrix::IsTranslationScaleOnly | ( |  | ) | const
| inline constexpr

Returns true if the matrix has a scale-only basis and is non-projective. Note that an identity matrix meets this criteria.

Definition at line 358 of file matrix.h.

358 {
359 return (
360 // clang-format off
361 m[0] != 0.0 && m[1] == 0.0 && m[2] == 0.0 && m[3] == 0.0 &&
362 m[4] == 0.0 && m[5] != 0.0 && m[6] == 0.0 && m[7] == 0.0 &&
363 m[8] == 0.0 && m[9] == 0.0 && m[10] != 0.0 && m[11] == 0.0 &&
364 m[15] == 1.0
365 // clang-format on
366 );
367 }

References m.

Referenced by impeller::RectGeometry::CoversArea(), impeller::FillPathGeometry::CoversArea(), and impeller::TextContents::Render().

## ◆ MakeColumn()

static constexpr Matrix impeller::Matrix::MakeColumn | ( | 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
| ) |  |
| inline static constexpr

Definition at line 68 of file matrix.h.

72 {
73 return Matrix(m0, m1, m2, m3,
74 m4, m5, m6, m7,
75 m8, m9, m10, m11,
76 m12, m13, m14, m15);
77
78 }

References Matrix().

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

## ◆ MakeLookAt()

static constexpr Matrix impeller::Matrix::MakeLookAt | ( | Vector3 | position,
|  | Vector3 | target,
|  | Vector3 | up
| ) |  |
| inline static constexpr

Definition at line 483 of file matrix.h.

485 {
486 Vector3 forward = (target - position).Normalize();
487 Vector3 right = up.Cross(forward);
488 up = forward.Cross(right);
489
490 // clang-format off
491 return {
492 right.x, up.x, forward.x, 0.0f,
493 right.y, up.y, forward.y, 0.0f,
494 right.z, up.z, forward.z, 0.0f,
495 -right.Dot(position), -up.Dot(position), -forward.Dot(position), 1.0f
496 };
497 // clang-format on
498 }

References impeller::Vector3::Cross(), impeller::Vector3::Dot(), impeller::Vector3::x, impeller::Vector3::y, and impeller::Vector3::z.

Referenced by impeller::scene::Camera::GetTransform(), and impeller::testing::TEST().

## ◆ MakeOrthographic()

template<class T >

static constexpr Matrix impeller::Matrix::MakeOrthographic | ( | TSize< T > | size | ) |
| inline static constexpr

Definition at line 448 of file matrix.h.

448 {
449 // Per assumptions about NDC documented above.
450 const auto scale =
451 MakeScale({2.0f / static_cast<Scalar>(size.width),
452 -2.0f / static_cast<Scalar>(size.height), 0.0f});
453 const auto translate = MakeTranslation({-1.0f, 1.0f, 0.5f});
454 return translate * scale;
455 }

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

Referenced by impeller::AdvancedBlend(), impeller::ComputeUVGeometryForRect(), impeller::VerticesGeometry::GetPositionBuffer(), impeller::VerticesGeometry::GetPositionColorBuffer(), impeller::VerticesGeometry::GetPositionUVBuffer(), ImGui_ImplImpeller_RenderDrawData(), impeller::PipelineBlend(), impeller::ClipContents::Render(), impeller::SolidRRectBlurContents::Render(), impeller::TextContents::Render(), impeller::TextureContents::Render(), impeller::AtlasContents::Render(), impeller::ClipRestoreContents::Render(), impeller::AtlasTextureContents::Render(), impeller::AtlasColorContents::Render(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ MakePerspective() [1/2]

static constexpr Matrix impeller::Matrix::MakePerspective | ( | Radians | fov_y,
|  | Scalar | aspect_ratio,
|  | Scalar | z_near,
|  | Scalar | z_far
| ) |  |
| inline static constexpr

Definition at line 457 of file matrix.h.

460 {
461 Scalar height = std::tan(fov_y.radians * 0.5f);
462 Scalar width = height * aspect_ratio;
463
464 // clang-format off
465 return {
466 1.0f / width, 0.0f, 0.0f, 0.0f,
467 0.0f, 1.0f / height, 0.0f, 0.0f,
468 0.0f, 0.0f, z_far / (z_far - z_near), 1.0f,
469 0.0f, 0.0f, -(z_far * z_near) / (z_far - z_near), 0.0f,
470 };
471 // clang-format on
472 }

References impeller::Radians::radians.

Referenced by impeller::scene::Camera::GetTransform(), MakePerspective(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ MakePerspective() [2/2]

template<class T >

static constexpr Matrix impeller::Matrix::MakePerspective | ( | Radians | fov_y,
|  | TSize< T > | size,
|  | Scalar | z_near,
|  | Scalar | z_far
| ) |  |
| inline static constexpr

Definition at line 475 of file matrix.h.

478 {
479 return MakePerspective(fov_y, static_cast<Scalar>(size.width) / size.height,
480 z_near, z_far);
481 }

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

## ◆ MakeRotation() [1/2]

static Matrix impeller::Matrix::MakeRotation | ( | Quaternion | q | ) |
| inline static

Definition at line 125 of file matrix.h.

125 {
126 // clang-format off
127 return Matrix(
128 1.0f - 2.0f * q.y * q.y - 2.0f * q.z * q.z,
129 2.0f * q.x * q.y + 2.0f * q.z * q.w,
130 2.0f * q.x * q.z - 2.0f * q.y * q.w,
131 0.0f,
132
133 2.0f * q.x * q.y - 2.0f * q.z * q.w,
134 1.0f - 2.0f * q.x * q.x - 2.0f * q.z * q.z,
135 2.0f * q.y * q.z + 2.0f * q.x * q.w,
136 0.0f,
137
138 2.0f * q.x * q.z + 2.0f * q.y * q.w,
139 2.0f * q.y * q.z - 2.0f * q.x * q.w,
140 1.0f - 2.0f * q.x * q.x - 2.0f * q.y * q.y,
141 0.0f,
142
143 0.0f,
144 0.0f,
145 0.0f,
146 1.0f);
147 // clang-format on
148 }

References Matrix(), impeller::Quaternion::w, impeller::Quaternion::x, impeller::Quaternion::y, and impeller::Quaternion::z.

Referenced by impeller::scene::importer::ProcessNode(), impeller::testing::TEST(), and impeller::scene::testing::TEST_P().

## ◆ MakeRotation() [2/2]

static Matrix impeller::Matrix::MakeRotation | ( | Scalar | radians,
|  | const Vector4 & | r
| ) |  |
| inline static

Definition at line 150 of file matrix.h.

150 {
151 const Vector4 v = r.Normalize();
152
153 const Scalar cosine = cos(radians);
154 const Scalar cosp = 1.0f - cosine;
155 const Scalar sine = sin(radians);
156
157 // clang-format off
158 return Matrix(
159 cosine + cosp * v.x * v.x,
160 cosp * v.x * v.y + v.z * sine,
161 cosp * v.x * v.z - v.y * sine,
162 0.0f,
163
164 cosp * v.x * v.y - v.z * sine,
165 cosine + cosp * v.y * v.y,
166 cosp * v.y * v.z + v.x * sine,
167 0.0f,
168
169 cosp * v.x * v.z + v.y * sine,
170 cosp * v.y * v.z - v.x * sine,
171 cosine + cosp * v.z * v.z,
172 0.0f,
173
174 0.0f,
175 0.0f,
176 0.0f,
177 1.0f);
178 // clang-format on
179 }

References Matrix(), impeller::Vector4::Normalize(), impeller::Vector4::x, impeller::Vector4::y, and impeller::Vector4::z.

## ◆ MakeRotationX()

static Matrix impeller::Matrix::MakeRotationX | ( | Radians | r | ) |
| inline static

Definition at line 181 of file matrix.h.

181 {
182 const Scalar cosine = cos(r.radians);
183 const Scalar sine = sin(r.radians);
184 // clang-format off
185 return Matrix(
186 1.0f, 0.0f, 0.0f, 0.0f,
187 0.0f, cosine, sine, 0.0f,
188 0.0f, -sine, cosine, 0.0f,
189 0.0f, 0.0f, 0.0f, 1.0f
190 );
191 // clang-format on
192 }

References Matrix(), and impeller::Radians::radians.

Referenced by impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ MakeRotationY()

static Matrix impeller::Matrix::MakeRotationY | ( | Radians | r | ) |
| inline static

Definition at line 194 of file matrix.h.

194 {
195 const Scalar cosine = cos(r.radians);
196 const Scalar sine = sin(r.radians);
197
198 // clang-format off
199 return Matrix(
200 cosine, 0.0f, -sine, 0.0f,
201 0.0f, 1.0f, 0.0f, 0.0f,
202 sine, 0.0f, cosine, 0.0f,
203 0.0f, 0.0f, 0.0f, 1.0f
204 );
205 // clang-format on
206 }

References Matrix(), and impeller::Radians::radians.

Referenced by impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ MakeRotationZ()

static Matrix impeller::Matrix::MakeRotationZ | ( | Radians | r | ) |
| inline static

Definition at line 208 of file matrix.h.

208 {
209 const Scalar cosine = cos(r.radians);
210 const Scalar sine = sin(r.radians);
211
212 // clang-format off
213 return Matrix (
214 cosine, sine, 0.0f, 0.0f,
215 -sine, cosine, 0.0f, 0.0f,
216 0.0f, 0.0f, 1.0f, 0.0f,
217 0.0f, 0.0f, 0.0f, 1.0
218 );
219 // clang-format on
220 }

References Matrix(), and impeller::Radians::radians.

Referenced by impeller::Canvas::Rotate(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ MakeRow()

static constexpr Matrix impeller::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
| ) |  |
| inline static constexpr

Definition at line 82 of file matrix.h.

86 {
87 return Matrix(m0, m4, m8, m12,
88 m1, m5, m9, m13,
89 m2, m6, m10, m14,
90 m3, m7, m11, m15);
91 }

References Matrix().

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

## ◆ MakeScale() [1/2]

static constexpr Matrix impeller::Matrix::MakeScale | ( | const Vector2 & | s | ) |
| inline static constexpr

Definition at line 112 of file matrix.h.

112 {
113 return MakeScale(Vector3(s.x, s.y, 1.0f));
114 }

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

## ◆ MakeScale() [2/2]

static constexpr Matrix impeller::Matrix::MakeScale | ( | const Vector3 & | s | ) |
| inline static constexpr

Definition at line 103 of file matrix.h.

103 {
104 // clang-format off
105 return Matrix(s.x, 0.0f, 0.0f, 0.0f,
106 0.0f, s.y, 0.0f, 0.0f,
107 0.0f, 0.0f, s.z, 0.0f,
108 0.0f, 0.0f, 0.0f, 1.0f);
109 // clang-format on
110 }

References Matrix(), impeller::Vector3::x, impeller::Vector3::y, and impeller::Vector3::z.

Referenced by impeller::Snapshot::GetUVTransform(), MakeOrthographic(), MakeScale(), impeller::scene::importer::ParseGLTF(), impeller::scene::importer::ProcessNode(), impeller::SceneContents::Render(), impeller::TextureContents::RenderToSnapshot(), impeller::Canvas::Scale(), impeller::testing::TEST(), impeller::scene::testing::TEST_P(), and impeller::testing::TEST_P().

## ◆ MakeSkew()

static constexpr Matrix impeller::Matrix::MakeSkew | ( | Scalar | sx,
|  | Scalar | sy
| ) |  |
| inline static constexpr

Definition at line 116 of file matrix.h.

116 {
117 // clang-format off
118 return Matrix(1.0f, sy , 0.0f, 0.0f,
119 sx , 1.0f, 0.0f, 0.0f,
120 0.0f, 0.0f, 1.0f, 0.0f,
121 0.0f, 0.0f, 0.0f, 1.0f);
122 // clang-format on
123 }

References Matrix().

Referenced by impeller::Canvas::Skew(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ MakeTranslation()

static constexpr Matrix impeller::Matrix::MakeTranslation | ( | const Vector3 & | t | ) |
| inline static constexpr

Definition at line 94 of file matrix.h.

94 {
95 // clang-format off
96 return Matrix(1.0f, 0.0f, 0.0f, 0.0f,
97 0.0f, 1.0f, 0.0f, 0.0f,
98 0.0f, 0.0f, 1.0f, 0.0f,
99 t.x, t.y, t.z, 1.0f);
100 // clang-format on
101 }

References Matrix(), impeller::Vector3::x, impeller::Vector3::y, and impeller::Vector3::z.

Referenced by impeller::AdvancedBlend(), impeller::DlDispatcher::drawShadow(), impeller::Canvas::DrawTextFrame(), impeller::AtlasContents::GenerateSubAtlas(), MakeOrthographic(), impeller::PipelineBlend(), impeller::scene::importer::ProcessNode(), impeller::SolidRRectBlurContents::Render(), impeller::TextureContents::RenderToSnapshot(), impeller::Contents::RenderToSnapshot(), impeller::Picture::Snapshot(), impeller::testing::TEST(), impeller::scene::testing::TEST_P(), impeller::testing::TEST_P(), and impeller::Canvas::Translate().

## ◆ Multiply()

constexpr Matrix impeller::Matrix::Multiply | ( | const Matrix & | o | ) | const
| inline constexpr

Definition at line 254 of file matrix.h.

254 {
255 // clang-format off
256 return Matrix(
257 m[0] * o.m[0] + m[4] * o.m[1] + m[8] * o.m[2] + m[12] * o.m[3],
258 m[1] * o.m[0] + m[5] * o.m[1] + m[9] * o.m[2] + m[13] * o.m[3],
259 m[2] * o.m[0] + m[6] * o.m[1] + m[10] * o.m[2] + m[14] * o.m[3],
260 m[3] * o.m[0] + m[7] * o.m[1] + m[11] * o.m[2] + m[15] * o.m[3],
261 m[0] * o.m[4] + m[4] * o.m[5] + m[8] * o.m[6] + m[12] * o.m[7],
262 m[1] * o.m[4] + m[5] * o.m[5] + m[9] * o.m[6] + m[13] * o.m[7],
263 m[2] * o.m[4] + m[6] * o.m[5] + m[10] * o.m[6] + m[14] * o.m[7],
264 m[3] * o.m[4] + m[7] * o.m[5] + m[11] * o.m[6] + m[15] * o.m[7],
265 m[0] * o.m[8] + m[4] * o.m[9] + m[8] * o.m[10] + m[12] * o.m[11],
266 m[1] * o.m[8] + m[5] * o.m[9] + m[9] * o.m[10] + m[13] * o.m[11],
267 m[2] * o.m[8] + m[6] * o.m[9] + m[10] * o.m[10] + m[14] * o.m[11],
268 m[3] * o.m[8] + m[7] * o.m[9] + m[11] * o.m[10] + m[15] * o.m[11],
269 m[0] * o.m[12] + m[4] * o.m[13] + m[8] * o.m[14] + m[12] * o.m[15],
270 m[1] * o.m[12] + m[5] * o.m[13] + m[9] * o.m[14] + m[13] * o.m[15],
271 m[2] * o.m[12] + m[6] * o.m[13] + m[10] * o.m[14] + m[14] * o.m[15],
272 m[3] * o.m[12] + m[7] * o.m[13] + m[11] * o.m[14] + m[15] * o.m[15]);
273 // clang-format on
274 }

References m, and Matrix().

Referenced by operator*().

## ◆ operator!=()

constexpr bool impeller::Matrix::operator!= | ( | const Matrix & | m | ) | const
| inline constexpr

Definition at line 380 of file matrix.h.

380 {
381 // clang-format off
382 return vec[0] != m.vec[0]
383 || vec[1] != m.vec[1]
384 || vec[2] != m.vec[2]
385 || vec[3] != m.vec[3];
386 // clang-format on
387 }

References m, and vec.

## ◆ operator*() [1/4]

Matrix impeller::Matrix::operator* | ( | const Matrix & | m | ) | const
| inline

Definition at line 393 of file matrix.h.

393 { return Multiply(m); }

References m, and Multiply().

## ◆ operator*() [2/4]

constexpr Point impeller::Matrix::operator* | ( | const Point & | v | ) | const
| inline constexpr

Definition at line 418 of file matrix.h.

418 {
419 Scalar w = v.x * m[3] + v.y * m[7] + m[15];
420 Point result(v.x * m[0] + v.y * m[4] + m[12],
421 v.x * m[1] + v.y * m[5] + m[13]);
422
423 // This is Skia's behavior, but it may be reasonable to allow UB for the w=0
424 // case.
425 if (w) {
426 w = 1 / w;
427 }
428 return result * w;
429 }

References m, impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

## ◆ operator*() [3/4]

constexpr Vector3 impeller::Matrix::operator* | ( | const Vector3 & | v | ) | const
| inline constexpr

Definition at line 404 of file matrix.h.

404 {
405 Scalar w = v.x * m[3] + v.y * m[7] + v.z * m[11] + m[15];
406 Vector3 result(v.x * m[0] + v.y * m[4] + v.z * m[8] + m[12],
407 v.x * m[1] + v.y * m[5] + v.z * m[9] + m[13],
408 v.x * m[2] + v.y * m[6] + v.z * m[10] + m[14]);
409
410 // This is Skia's behavior, but it may be reasonable to allow UB for the w=0
411 // case.
412 if (w) {
413 w = 1 / w;
414 }
415 return result * w;
416 }

References m, impeller::Vector3::x, impeller::Vector3::y, and impeller::Vector3::z.

## ◆ operator*() [4/4]

constexpr Vector4 impeller::Matrix::operator* | ( | const Vector4 & | v | ) | const
| inline constexpr

Definition at line 397 of file matrix.h.

397 {
398 return Vector4(v.x * m[0] + v.y * m[4] + v.z * m[8] + v.w * m[12],
399 v.x * m[1] + v.y * m[5] + v.z * m[9] + v.w * m[13],
400 v.x * m[2] + v.y * m[6] + v.z * m[10] + v.w * m[14],
401 v.x * m[3] + v.y * m[7] + v.z * m[11] + v.w * m[15]);
402 }

References m, impeller::Vector4::w, impeller::Vector4::x, impeller::Vector4::y, and impeller::Vector4::z.

## ◆ operator+() [1/2]

Matrix impeller::Matrix::operator+ | ( | const Matrix & | m | ) | const

Definition at line 88 of file matrix.cc.

88 {
89 return Matrix(
90 m[0] + o.m[0], m[1] + o.m[1], m[2] + o.m[2], m[3] + o.m[3], //
91 m[4] + o.m[4], m[5] + o.m[5], m[6] + o.m[6], m[7] + o.m[7], //
92 m[8] + o.m[8], m[9] + o.m[9], m[10] + o.m[10], m[11] + o.m[11], //
93 m[12] + o.m[12], m[13] + o.m[13], m[14] + o.m[14], m[15] + o.m[15] //
94 );
95 }

References m, and Matrix().

## ◆ operator+() [2/2]

Matrix impeller::Matrix::operator+ | ( | const Vector3 & | t | ) | const
| inline

Definition at line 389 of file matrix.h.

389 { return Translate(t); }

References Translate().

## ◆ operator-()

Matrix impeller::Matrix::operator- | ( | const Vector3 & | t | ) | const
| inline

Definition at line 391 of file matrix.h.

391 { return Translate(-t); }

References Translate().

## ◆ operator==()

constexpr bool impeller::Matrix::operator== | ( | const Matrix & | m | ) | const
| inline constexpr

Definition at line 371 of file matrix.h.

371 {
372 // clang-format off
373 return vec[0] == m.vec[0]
374 && vec[1] == m.vec[1]
375 && vec[2] == m.vec[2]
376 && vec[3] == m.vec[3];
377 // clang-format on
378 }

References m, and vec.

## ◆ Scale()

constexpr Matrix impeller::Matrix::Scale | ( | const Vector3 & | s | ) | const
| inline constexpr

Definition at line 245 of file matrix.h.

245 {
246 // clang-format off
247 return Matrix(m[0] * s.x, m[1] * s.x, m[2] * s.x, m[3] * s.x,
248 m[4] * s.y, m[5] * s.y, m[6] * s.y, m[7] * s.y,
249 m[8] * s.z, m[9] * s.z, m[10] * s.z, m[11] * s.z,
250 m[12] , m[13] , m[14] , m[15] );
251 // clang-format on
252 }

References m, Matrix(), impeller::Vector3::x, impeller::Vector3::y, and impeller::Vector3::z.

## ◆ TransformDirection() [1/3]

constexpr Vector2 impeller::Matrix::TransformDirection | ( | const Vector2 & | v | ) | const
| inline constexpr

Definition at line 443 of file matrix.h.

443 {
444 return Vector2(v.x * m[0] + v.y * m[4], v.x * m[1] + v.y * m[5]);
445 }

References m, impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

## ◆ TransformDirection() [2/3]

constexpr Vector3 impeller::Matrix::TransformDirection | ( | const Vector3 & | v | ) | const
| inline constexpr

Definition at line 437 of file matrix.h.

437 {
438 return Vector3(v.x * m[0] + v.y * m[4] + v.z * m[8],
439 v.x * m[1] + v.y * m[5] + v.z * m[9],
440 v.x * m[2] + v.y * m[6] + v.z * m[10]);
441 }

References m, impeller::Vector3::x, impeller::Vector3::y, and impeller::Vector3::z.

## ◆ TransformDirection() [3/3]

constexpr Vector4 impeller::Matrix::TransformDirection | ( | const Vector4 & | v | ) | const
| inline constexpr

Definition at line 431 of file matrix.h.

431 {
432 return Vector4(v.x * m[0] + v.y * m[4] + v.z * m[8],
433 v.x * m[1] + v.y * m[5] + v.z * m[9],
434 v.x * m[2] + v.y * m[6] + v.z * m[10], v.w);
435 }

References m, impeller::Vector4::w, impeller::Vector4::x, impeller::Vector4::y, and impeller::Vector4::z.

Referenced by impeller::BorderMaskBlurFilterContents::GetFilterCoverage(), impeller::DirectionalMorphologyFilterContents::GetFilterCoverage(), and impeller::DirectionalGaussianBlurFilterContents::GetFilterCoverage().

## ◆ Translate()

constexpr Matrix impeller::Matrix::Translate | ( | const Vector3 & | t | ) | const
| inline constexpr

Definition at line 233 of file matrix.h.

233 {
234 // clang-format off
235 return Matrix(m[0], m[1], m[2], m[3],
236 m[4], m[5], m[6], m[7],
237 m[8], m[9], m[10], m[11],
238 m[0] * t.x + m[4] * t.y + m[8] * t.z + m[12],
239 m[1] * t.x + m[5] * t.y + m[9] * t.z + m[13],
240 m[2] * t.x + m[6] * t.y + m[10] * t.z + m[14],
241 m[15]);
242 // clang-format on
243 }

References m, Matrix(), impeller::Vector3::x, impeller::Vector3::y, and impeller::Vector3::z.

Referenced by ImGui_ImplImpeller_RenderDrawData(), operator+(), and operator-().

## ◆ Transpose()

constexpr Matrix impeller::Matrix::Transpose | ( |  | ) | const
| inline constexpr

Definition at line 276 of file matrix.h.

276 {
277 // clang-format off
278 return {
279 m[0], m[4], m[8], m[12],
280 m[1], m[5], m[9], m[13],
281 m[2], m[6], m[10], m[14],
282 m[3], m[7], m[11], m[15],
283 };
284 // clang-format on
285 }

References m.

Referenced by Decompose().

## Member Data Documentation

## ◆ @13

union { ... }

## ◆ e

Scalar impeller::Matrix::e[4][4]

Definition at line 39 of file matrix.h.

Referenced by Decompose(), GetDeterminant(), GetMaxBasisLength(), GetMaxBasisLengthXY(), Matrix(), and std::operator<<().

## ◆ m

Scalar impeller::Matrix::m[16]

Definition at line 38 of file matrix.h.

Referenced by Basis(), GetBasisX(), GetBasisY(), GetBasisZ(), HasPerspective(), Invert(), IsAffine(), IsAligned(), IsIdentity(), IsTranslationScaleOnly(), MatrixNear(), Multiply(), operator!=(), operator*(), operator+(), operator==(), Scale(), impeller::scene::importer::ToFBMatrix(), impeller::scene::importer::ToFBMatrixUniquePtr(), impeller::scene::importer::ToMatrix(), TransformDirection(), Translate(), and Transpose().

## ◆ vec

Vector4 impeller::Matrix::vec[4]

Definition at line 40 of file matrix.h.

Referenced by operator!=(), operator==(), and impeller::testing::TEST_P().

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

- impeller/geometry/matrix.h
- impeller/geometry/matrix.cc

impeller::Matrix::m
Scalar m[16]
Definition: matrix.h:38
impeller::Matrix::Matrix
constexpr Matrix()
Definition: matrix.h:46
impeller::Scalar
float Scalar
Definition: scalar.h:15
impeller::Vector3::Combine
static constexpr Vector3 Combine(const Vector3 &a, Scalar aScale, const Vector3 &b, Scalar bScale)
Definition: vector.h:189
impeller::Vector2
Point Vector2
Definition: point.h:310
impeller::Matrix::MakeTranslation
static constexpr Matrix MakeTranslation(const Vector3 &t)
Definition: matrix.h:94
impeller::Matrix::e
Scalar e[4][4]
Definition: matrix.h:39
impeller::Matrix::vec
Vector4 vec[4]
Definition: matrix.h:40
impeller::Matrix::MakePerspective
static constexpr Matrix MakePerspective(Radians fov_y, Scalar aspect_ratio, Scalar z_near, Scalar z_far)
Definition: matrix.h:457
impeller::Matrix::Basis
constexpr Matrix Basis() const
Definition: matrix.h:222
impeller::Point
TPoint< Scalar > Point
Definition: point.h:306
impeller::Matrix::Multiply
constexpr Matrix Multiply(const Matrix &o) const
Definition: matrix.h:254
impeller::Matrix::Translate
constexpr Matrix Translate(const Vector3 &t) const
Definition: matrix.h:233
impeller::ScalarNearlyZero
constexpr bool ScalarNearlyZero(Scalar x, Scalar tolerance=kEhCloseEnough)
Definition: scalar.h:22
impeller::Matrix::GetBasisZ
constexpr Vector3 GetBasisZ() const
Definition: matrix.h:299
impeller::Matrix::Invert
Matrix Invert() const
Definition: matrix.cc:97
impeller::Matrix::GetBasisY
constexpr Vector3 GetBasisY() const
Definition: matrix.h:297
impeller::Matrix::MakeScale
static constexpr Matrix MakeScale(const Vector3 &s)
Definition: matrix.h:103
impeller::Matrix::GetBasisX
constexpr Vector3 GetBasisX() const
Definition: matrix.h:295