MCPcopy Create free account
hub / github.com/JetBrains/skija / Matrix33

Class Matrix33

shared/java/Matrix33.java:16–242  ·  view source on GitHub ↗

Matrix holds a 3x3 matrix for transforming coordinates. This allows mapping Point and vectors with translation, scaling, skewing, rotation, and perspective. Matrix includes a hidden variable that classifies the type of matrix to improve performance. Matrix is not thread safe unless getTyp

Source from the content-addressed store, hash-verified

14 * @see <a href="https://fiddle.skia.org/c/@Matrix_063">https://fiddle.skia.org/c/@Matrix_063</a>
15 */
16@Data
17public class Matrix33 {
18 /**
19 * <p>Matrix33 elements are in row-major order.</p>
20 *
21 * <pre><code>
22 * | scaleX skewX transX |
23 * | skewY scaleY transY |
24 * | persp0 persp1 persp2 |
25 * </code></pre>
26 */
27 @ApiStatus.Internal
28 public final float[] _mat;
29
30 public Matrix33(float... mat) {
31 assert mat.length == 9 : "Expected 9 elements, got " + mat == null ? null : mat.length;
32 _mat = mat;
33 }
34
35 /**
36 * An identity Matrix33:
37 *
38 * <pre><code>
39 * | 1 0 0 |
40 * | 0 1 0 |
41 * | 0 0 1 |
42 * </code></pre>
43 */
44 @NotNull
45 public static final Matrix33 IDENTITY = makeTranslate(0, 0);
46
47 /**
48 * <p>Creates a Matrix33 to translate by (dx, dy). Returned matrix is:</p>
49 *
50 * <pre><code>
51 * | 1 0 dx |
52 * | 0 1 dy |
53 * | 0 0 1 |
54 * </code></pre>
55 *
56 * @param dx horizontal translation
57 * @param dy vertical translation
58 * @return Matrix33 with translation
59 */
60 @NotNull @Contract("_, _ -> new")
61 public static Matrix33 makeTranslate(float dx, float dy) {
62 return new Matrix33(new float[] {1, 0, dx, 0, 1, dy, 0, 0, 1});
63 }
64
65 /**
66 * <p>Creates a Matrix33 to scale by s. Returned matrix is:</p>
67 *
68 * <pre><code>
69 * | s 0 0 |
70 * | 0 s 0 |
71 * | 0 0 1 |
72 * </code></pre>
73 *

Callers

nothing calls this directly

Calls 1

makeTranslateMethod · 0.95

Tested by

no test coverage detected