@@ -9,16 +9,9 @@ import {
9
9
processTransform3d ,
10
10
rotateX ,
11
11
translate ,
12
+ toMatrix3 ,
12
13
} from "../../../skia/types" ;
13
14
14
- /**
15
- * @worklet
16
- */
17
- export const toCKMatrix3 = ( m : number [ ] ) => {
18
- "worklet" ;
19
- return [ m [ 0 ] , m [ 1 ] , m [ 3 ] , m [ 4 ] , m [ 5 ] , m [ 7 ] , m [ 12 ] , m [ 13 ] , m [ 15 ] ] ;
20
- } ;
21
-
22
15
const ckPerspective = ( d : number ) => [
23
16
1 ,
24
17
0 ,
@@ -43,7 +36,7 @@ const concat = (a: number[], b: number[]) => CanvasKit.M44.multiply(a, b);
43
36
describe ( "Matrix4" , ( ) => {
44
37
it ( "should be a row major matix" , ( ) => {
45
38
const m4 = CanvasKit . M44 . identity ( ) ;
46
- expect ( processTransform3d ( [ ] ) ) . toEqual ( toCKMatrix3 ( m4 ) ) ;
39
+ expect ( processTransform3d ( [ ] ) ) . toEqual ( m4 ) ;
47
40
} ) ;
48
41
it ( "should match identity matrix" , ( ) => {
49
42
const m4 = CanvasKit . M44 . identity ( ) ;
@@ -54,7 +47,7 @@ describe("Matrix4", () => {
54
47
{ translateX : - 256 / 2 } ,
55
48
{ translateY : - 256 / 2 } ,
56
49
] )
57
- ) . toEqual ( toCKMatrix3 ( m4 ) ) ;
50
+ ) . toEqual ( m4 ) ;
58
51
} ) ;
59
52
it ( "Identity should match identity matrix" , ( ) => {
60
53
const m4 = CanvasKit . M44 . identity ( ) ;
@@ -65,7 +58,7 @@ describe("Matrix4", () => {
65
58
{ translateX : - 256 / 2 } ,
66
59
{ translateY : - 256 / 2 } ,
67
60
] )
68
- ) . toEqual ( toCKMatrix3 ( m4 ) ) ;
61
+ ) . toEqual ( m4 ) ;
69
62
} ) ;
70
63
it ( "should match perspective matrix" , ( ) => {
71
64
let m4 = CanvasKit . M44 . identity ( ) ;
@@ -80,15 +73,15 @@ describe("Matrix4", () => {
80
73
{ translateX : - 256 / 2 } ,
81
74
{ translateY : - 256 / 2 } ,
82
75
] )
83
- ) . toEqual ( toCKMatrix3 ( m4 ) ) ;
76
+ ) . toEqual ( m4 ) ;
84
77
} ) ;
85
78
it ( "should match rotation matrix (1)" , ( ) => {
86
79
let m4 = CanvasKit . M44 . identity ( ) ;
87
80
m4 = concat ( m4 , CanvasKit . M44 . rotated ( [ 1 , 0 , 0 ] , 1 ) ) ;
88
- expect ( processTransform3d ( [ { rotateX : 1 } ] ) ) . toEqual ( toCKMatrix3 ( m4 ) ) ;
81
+ expect ( processTransform3d ( [ { rotateX : 1 } ] ) ) . toEqual ( m4 ) ;
89
82
m4 = CanvasKit . M44 . identity ( ) ;
90
83
m4 = concat ( m4 , CanvasKit . M44 . rotated ( [ 0 , 1 , 0 ] , Math . PI ) ) ;
91
- expect ( processTransform3d ( [ { rotateY : Math . PI } ] ) ) . toEqual ( toCKMatrix3 ( m4 ) ) ;
84
+ expect ( processTransform3d ( [ { rotateY : Math . PI } ] ) ) . toEqual ( m4 ) ;
92
85
} ) ;
93
86
it ( "should match rotation matrix (2)" , ( ) => {
94
87
let m4 = CanvasKit . M44 . identity ( ) ;
@@ -103,7 +96,7 @@ describe("Matrix4", () => {
103
96
{ translateX : - 256 / 2 } ,
104
97
{ translateY : - 256 / 2 } ,
105
98
] )
106
- ) . toEqual ( toCKMatrix3 ( m4 ) ) ;
99
+ ) . toEqual ( m4 ) ;
107
100
} ) ;
108
101
it ( "Should do a perspective transformation (1)" , async ( ) => {
109
102
const { width, height } = surface ;
@@ -221,12 +214,14 @@ describe("Matrix4", () => {
221
214
) ;
222
215
// eslint-disable-next-line @typescript-eslint/no-explicit-any, jest/valid-expect
223
216
( expect ( result ) as any ) . toBeApproximatelyEqual (
224
- processTransform3d ( [
225
- { translate : [ width / 2 , height / 2 ] } ,
226
- { perspective : 300 } ,
227
- { rotateX : 1 } ,
228
- { translate : [ - width / 2 , - height / 2 ] } ,
229
- ] ) ,
217
+ toMatrix3 (
218
+ processTransform3d ( [
219
+ { translate : [ width / 2 , height / 2 ] } ,
220
+ { perspective : 300 } ,
221
+ { rotateX : 1 } ,
222
+ { translate : [ - width / 2 , - height / 2 ] } ,
223
+ ] )
224
+ ) ,
230
225
0.1
231
226
) ;
232
227
} ) ;
0 commit comments