File tree Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import {
10
10
rotateX ,
11
11
translate ,
12
12
toMatrix3 ,
13
+ Matrix4 ,
14
+ mapPoint3d ,
13
15
} from "../../../skia/types" ;
14
16
15
17
const ckPerspective = ( d : number ) => [
@@ -225,4 +227,17 @@ describe("Matrix4", () => {
225
227
0.1
226
228
) ;
227
229
} ) ;
230
+ it ( "should correctly transform a point with an identity matrix" , ( ) => {
231
+ const identityMatrix = Matrix4 ( ) ;
232
+ const point = [ 100 , - 100 , 200 ] as const ; // Define some test point
233
+ const result = mapPoint3d ( identityMatrix , point ) ;
234
+ expect ( result ) . toEqual ( point ) ;
235
+ } ) ;
236
+ it ( "should correctly transform a point with a translation matrix" , ( ) => {
237
+ const translationMatrix = translate ( 100 , 100 , 100 ) ;
238
+ const point = [ 100 , - 100 , 200 ] as const ; // Define some test point
239
+ const expectedResult = [ 200 , 0 , 300 ] as const ;
240
+ const result = mapPoint3d ( translationMatrix , point ) ;
241
+ expect ( result ) . toEqual ( expectedResult ) ;
242
+ } ) ;
228
243
} ) ;
Original file line number Diff line number Diff line change @@ -150,14 +150,16 @@ const rotatedUnitSinCos = (
150
150
] ;
151
151
} ;
152
152
153
- const matrixVecMul4 = ( m : Matrix4 , v : Vec4 ) => {
153
+ /**
154
+ * @worklet
155
+ */
156
+ export const matrixVecMul4 = ( m : Matrix4 , v : Vec4 ) : Vec4 => {
154
157
"worklet" ;
155
- const [ vx , vy , vz , vw ] = v ;
156
158
return [
157
- vx * m [ 0 ] + vy * m [ 4 ] + vz * m [ 8 ] + vw * m [ 12 ] ,
158
- vx * m [ 1 ] + vy * m [ 5 ] + vz * m [ 9 ] + vw * m [ 13 ] ,
159
- vx * m [ 2 ] + vy * m [ 6 ] + vz * m [ 10 ] + vw * m [ 14 ] ,
160
- vx * m [ 3 ] + vy * m [ 7 ] + vz * m [ 11 ] + vw * m [ 15 ] ,
159
+ m [ 0 ] * v [ 0 ] + m [ 1 ] * v [ 1 ] + m [ 2 ] * v [ 2 ] + m [ 3 ] * v [ 3 ] ,
160
+ m [ 4 ] * v [ 0 ] + m [ 5 ] * v [ 1 ] + m [ 6 ] * v [ 2 ] + m [ 7 ] * v [ 3 ] ,
161
+ m [ 8 ] * v [ 0 ] + m [ 9 ] * v [ 1 ] + m [ 10 ] * v [ 2 ] + m [ 11 ] * v [ 3 ] ,
162
+ m [ 12 ] * v [ 0 ] + m [ 13 ] * v [ 1 ] + m [ 14 ] * v [ 2 ] + m [ 15 ] * v [ 3 ] ,
161
163
] ;
162
164
} ;
163
165
You can’t perform that action at this time.
0 commit comments