7
7
package com.almasb.fxgl.physics.box2d.common
8
8
9
9
import com.almasb.fxgl.core.math.Vec2
10
- import org.hamcrest.CoreMatchers
11
10
import org.hamcrest.CoreMatchers.*
12
- import org.hamcrest.MatcherAssert
13
11
import org.hamcrest.MatcherAssert.*
12
+ import org.junit.jupiter.api.Assertions.assertEquals
14
13
import org.junit.jupiter.api.Test
15
14
16
15
/* *
17
- *
18
16
* @author Almas Baimagambetov (almaslvl@gmail.com)
19
17
*/
20
18
class Mat22Test {
21
19
20
+ @Test
21
+ fun `Set to zero` () {
22
+ val mat = Mat22 ()
23
+
24
+ mat.ex.set(2f , 3f )
25
+ mat.ey.set(4f , 7f )
26
+
27
+ mat.setZero()
28
+
29
+ assertThat(mat.ex, `is `(Vec2 ()))
30
+ assertThat(mat.ey, `is `(Vec2 ()))
31
+ }
32
+
33
+ @Test
34
+ fun `Invert` () {
35
+ val A = Mat22 ()
36
+ A .ex.set(1f , 2f )
37
+ A .ey.set(3f , 4f )
38
+
39
+ val B = Mat22 ()
40
+ A .invertToOut(B )
41
+
42
+ val eps = 1e- 6f
43
+ assertEquals(- 2.0f , B .ex.x, eps)
44
+ assertEquals(1.5f , B .ey.x, eps)
45
+ assertEquals(1.0f , B .ex.y, eps)
46
+ assertEquals(- 0.5f , B .ey.y, eps)
47
+ }
48
+
49
+ @Test
50
+ fun `Solve Ax = b` () {
51
+ val A = Mat22 ()
52
+ A .ex.set(2.0f , 3.0f )
53
+ A .ey.set(4.0f , 7.0f )
54
+
55
+ val b = Vec2 (10.0f , 17.0f )
56
+ val out = Vec2 ()
57
+
58
+ // A x = b
59
+ // [ 2 4 ] x [ 1 ] = [ 10 ]
60
+ // [ 3 7 ] [ 2 ] [ 17 ]
61
+
62
+ A .solveToOut(b, out )
63
+
64
+ assertEquals(1.0f , out .x, 0.0001f )
65
+ assertEquals(2.0f , out .y, 0.0001f )
66
+ }
67
+
22
68
@Test
23
69
fun `Matrix mul vector` () {
24
70
val mat = Mat22 ()
@@ -28,7 +74,7 @@ class Mat22Test {
28
74
29
75
val v = Vec2 (1f , 2f )
30
76
31
- // [ 2 4 ] x [ 1 ] = [ 10 ]
77
+ // [ 2 4 ] x [ 1 ] = [ 10 ]
32
78
// [ 3 7 ] [ 2 ] [ 17 ]
33
79
34
80
val out = Vec2 ()
0 commit comments