mirror of
https://github.com/bloeys/gglm.git
synced 2025-12-29 13:38:20 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2bdd7b2d02 | |||
| 61b2298cb1 | |||
| 62a2e4d7aa |
@ -6,8 +6,133 @@ import (
|
||||
"github.com/bloeys/gglm/gglm"
|
||||
)
|
||||
|
||||
func TestMat2GetSet(t *testing.T) {
|
||||
|
||||
m1 := gglm.Mat2{}
|
||||
|
||||
m1.Set(0, 1, -10)
|
||||
m1.Set(1, 0, 55)
|
||||
|
||||
if m1.Get(0, 1) != -10 {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.Get(0, 1), -10)
|
||||
}
|
||||
|
||||
if m1.Get(1, 0) != 55 {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.Get(1, 0), 55)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMat2Id(t *testing.T) {
|
||||
|
||||
correctAns := gglm.Mat2{
|
||||
Data: [4]float32{
|
||||
1, 0,
|
||||
0, 1,
|
||||
}}
|
||||
|
||||
m1 := gglm.NewMat2Id()
|
||||
if !m1.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.String(), correctAns.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubMat2(t *testing.T) {
|
||||
|
||||
correctAns := gglm.Mat2{
|
||||
Data: [4]float32{
|
||||
-4, -4,
|
||||
-4, -4,
|
||||
}}
|
||||
|
||||
m1 := &gglm.Mat2{
|
||||
Data: [4]float32{
|
||||
1, 2,
|
||||
3, 4,
|
||||
}}
|
||||
m2 := &gglm.Mat2{
|
||||
Data: [4]float32{
|
||||
5, 6,
|
||||
7, 8,
|
||||
}}
|
||||
|
||||
result := gglm.SubMat2(m1, m2)
|
||||
m1.Sub(m2)
|
||||
|
||||
if !result.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", result.String(), correctAns.String())
|
||||
}
|
||||
|
||||
if !m1.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.String(), correctAns.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddMat2(t *testing.T) {
|
||||
|
||||
correctAns := gglm.Mat2{
|
||||
Data: [4]float32{
|
||||
6, 8,
|
||||
10, 12,
|
||||
}}
|
||||
|
||||
m1 := &gglm.Mat2{
|
||||
Data: [4]float32{
|
||||
1, 2,
|
||||
3, 4,
|
||||
}}
|
||||
m2 := &gglm.Mat2{
|
||||
Data: [4]float32{
|
||||
5, 6,
|
||||
7, 8,
|
||||
}}
|
||||
|
||||
result := gglm.AddMat2(m1, m2)
|
||||
m1.Add(m2)
|
||||
|
||||
if !result.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", result.String(), correctAns.String())
|
||||
}
|
||||
|
||||
if !m1.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.String(), correctAns.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestMulMat2(t *testing.T) {
|
||||
|
||||
correctAns := gglm.Mat2{
|
||||
Data: [4]float32{
|
||||
19, 22,
|
||||
43, 50,
|
||||
}}
|
||||
|
||||
m1 := &gglm.Mat2{
|
||||
Data: [4]float32{
|
||||
1, 2,
|
||||
3, 4,
|
||||
}}
|
||||
m2 := &gglm.Mat2{
|
||||
Data: [4]float32{
|
||||
5, 6,
|
||||
7, 8,
|
||||
}}
|
||||
|
||||
result := gglm.MulMat2(m1, m2)
|
||||
m1.Mul(m2)
|
||||
|
||||
if !result.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", result.String(), correctAns.String())
|
||||
}
|
||||
|
||||
if !m1.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.String(), correctAns.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestMulMat2Vec2(t *testing.T) {
|
||||
|
||||
correctAns := gglm.Vec2{Data: [2]float32{5, 11}}
|
||||
|
||||
m := &gglm.Mat2{
|
||||
Data: [4]float32{
|
||||
1, 2,
|
||||
@ -16,7 +141,6 @@ func TestMulMat2Vec2(t *testing.T) {
|
||||
v := &gglm.Vec2{Data: [2]float32{1, 2}}
|
||||
|
||||
result := gglm.MulMat2Vec2(m, v)
|
||||
correctAns := gglm.Vec2{Data: [2]float32{5, 11}}
|
||||
|
||||
if !result.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", result.String(), correctAns.String())
|
||||
|
||||
@ -6,6 +6,144 @@ import (
|
||||
"github.com/bloeys/gglm/gglm"
|
||||
)
|
||||
|
||||
func TestMat3GetSet(t *testing.T) {
|
||||
|
||||
m1 := gglm.Mat3{}
|
||||
|
||||
m1.Set(0, 1, -10)
|
||||
m1.Set(1, 0, 55)
|
||||
m1.Set(2, 2, 99)
|
||||
|
||||
if m1.Get(0, 1) != -10 {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.Get(0, 1), -10)
|
||||
}
|
||||
|
||||
if m1.Get(1, 0) != 55 {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.Get(1, 0), 55)
|
||||
}
|
||||
|
||||
if m1.Get(2, 2) != 99 {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.Get(2, 2), 99)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMat3Id(t *testing.T) {
|
||||
|
||||
correctAns := gglm.Mat3{
|
||||
Data: [9]float32{
|
||||
1, 0, 0,
|
||||
0, 1, 0,
|
||||
0, 0, 1,
|
||||
}}
|
||||
|
||||
m1 := gglm.NewMat3Id()
|
||||
if !m1.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.String(), correctAns.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubMat3(t *testing.T) {
|
||||
|
||||
correctAns := gglm.Mat3{
|
||||
Data: [9]float32{
|
||||
-9, -9, -9,
|
||||
-9, -9, -9,
|
||||
-9, -9, -9,
|
||||
}}
|
||||
|
||||
m1 := &gglm.Mat3{
|
||||
Data: [9]float32{
|
||||
1, 2, 3,
|
||||
4, 5, 6,
|
||||
7, 8, 9,
|
||||
}}
|
||||
m2 := &gglm.Mat3{
|
||||
Data: [9]float32{
|
||||
10, 11, 12,
|
||||
13, 14, 15,
|
||||
16, 17, 18,
|
||||
}}
|
||||
|
||||
result := gglm.SubMat3(m1, m2)
|
||||
m1.Sub(m2)
|
||||
|
||||
if !result.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", result.String(), correctAns.String())
|
||||
}
|
||||
|
||||
if !m1.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.String(), correctAns.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddMat3(t *testing.T) {
|
||||
|
||||
correctAns := gglm.Mat3{
|
||||
Data: [9]float32{
|
||||
11, 13, 15,
|
||||
17, 19, 21,
|
||||
23, 25, 27,
|
||||
}}
|
||||
|
||||
m1 := &gglm.Mat3{
|
||||
Data: [9]float32{
|
||||
1, 2, 3,
|
||||
4, 5, 6,
|
||||
7, 8, 9,
|
||||
}}
|
||||
m2 := &gglm.Mat3{
|
||||
Data: [9]float32{
|
||||
10, 11, 12,
|
||||
13, 14, 15,
|
||||
16, 17, 18,
|
||||
}}
|
||||
|
||||
result := gglm.AddMat3(m1, m2)
|
||||
m1.Add(m2)
|
||||
|
||||
if !result.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", result.String(), correctAns.String())
|
||||
}
|
||||
|
||||
if !m1.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.String(), correctAns.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestMulMat3(t *testing.T) {
|
||||
|
||||
correctAns := gglm.Mat3{
|
||||
Data: [9]float32{
|
||||
84, 90, 96,
|
||||
201, 216, 231,
|
||||
318, 342, 366,
|
||||
}}
|
||||
|
||||
m1 := &gglm.Mat3{
|
||||
Data: [9]float32{
|
||||
1, 2, 3,
|
||||
4, 5, 6,
|
||||
7, 8, 9,
|
||||
}}
|
||||
m2 := &gglm.Mat3{
|
||||
Data: [9]float32{
|
||||
10, 11, 12,
|
||||
13, 14, 15,
|
||||
16, 17, 18,
|
||||
}}
|
||||
|
||||
result := gglm.MulMat3(m1, m2)
|
||||
m1.Mul(m2)
|
||||
|
||||
if !result.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", result.String(), correctAns.String())
|
||||
}
|
||||
|
||||
if !m1.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.String(), correctAns.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestMulMat3Vec3(t *testing.T) {
|
||||
|
||||
m := &gglm.Mat3{
|
||||
|
||||
@ -6,6 +6,159 @@ import (
|
||||
"github.com/bloeys/gglm/gglm"
|
||||
)
|
||||
|
||||
func TestMat4GetSet(t *testing.T) {
|
||||
|
||||
m1 := gglm.Mat4{}
|
||||
|
||||
m1.Set(0, 1, -10)
|
||||
m1.Set(1, 0, 55)
|
||||
m1.Set(2, 2, 99)
|
||||
m1.Set(3, 3, 513)
|
||||
|
||||
if m1.Get(0, 1) != -10 {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.Get(0, 1), -10)
|
||||
}
|
||||
|
||||
if m1.Get(1, 0) != 55 {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.Get(1, 0), 55)
|
||||
}
|
||||
|
||||
if m1.Get(2, 2) != 99 {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.Get(2, 2), 99)
|
||||
}
|
||||
|
||||
if m1.Get(3, 3) != 513 {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.Get(3, 3), 513)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMat4Id(t *testing.T) {
|
||||
|
||||
correctAns := gglm.Mat4{
|
||||
Data: [16]float32{
|
||||
1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1,
|
||||
}}
|
||||
|
||||
m1 := gglm.NewMat4Id()
|
||||
if !m1.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.String(), correctAns.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubMat4(t *testing.T) {
|
||||
|
||||
correctAns := gglm.Mat4{
|
||||
Data: [16]float32{
|
||||
-16, -16, -16, -16,
|
||||
-16, -16, -16, -16,
|
||||
-16, -16, -16, -16,
|
||||
-16, -16, -16, -16,
|
||||
}}
|
||||
|
||||
m1 := &gglm.Mat4{
|
||||
Data: [16]float32{
|
||||
1, 2, 3, 4,
|
||||
5, 6, 7, 8,
|
||||
9, 10, 11, 12,
|
||||
13, 14, 15, 16,
|
||||
}}
|
||||
m2 := &gglm.Mat4{
|
||||
Data: [16]float32{
|
||||
17, 18, 19, 20,
|
||||
21, 22, 23, 24,
|
||||
25, 26, 27, 28,
|
||||
29, 30, 31, 32,
|
||||
}}
|
||||
|
||||
result := gglm.SubMat4(m1, m2)
|
||||
m1.Sub(m2)
|
||||
|
||||
if !result.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", result.String(), correctAns.String())
|
||||
}
|
||||
|
||||
if !m1.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.String(), correctAns.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddMat4(t *testing.T) {
|
||||
|
||||
correctAns := gglm.Mat4{
|
||||
Data: [16]float32{
|
||||
18, 20, 22, 24,
|
||||
26, 28, 30, 32,
|
||||
34, 36, 38, 40,
|
||||
42, 44, 46, 48,
|
||||
}}
|
||||
|
||||
m1 := &gglm.Mat4{
|
||||
Data: [16]float32{
|
||||
1, 2, 3, 4,
|
||||
5, 6, 7, 8,
|
||||
9, 10, 11, 12,
|
||||
13, 14, 15, 16,
|
||||
}}
|
||||
m2 := &gglm.Mat4{
|
||||
Data: [16]float32{
|
||||
17, 18, 19, 20,
|
||||
21, 22, 23, 24,
|
||||
25, 26, 27, 28,
|
||||
29, 30, 31, 32,
|
||||
}}
|
||||
|
||||
result := gglm.AddMat4(m1, m2)
|
||||
m1.Add(m2)
|
||||
|
||||
if !result.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", result.String(), correctAns.String())
|
||||
}
|
||||
|
||||
if !m1.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.String(), correctAns.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestMulMat4(t *testing.T) {
|
||||
|
||||
correctAns := gglm.Mat4{
|
||||
Data: [16]float32{
|
||||
250, 260, 270, 280,
|
||||
618, 644, 670, 696,
|
||||
986, 1028, 1070, 1112,
|
||||
1354, 1412, 1470, 1528,
|
||||
}}
|
||||
|
||||
m1 := &gglm.Mat4{
|
||||
Data: [16]float32{
|
||||
1, 2, 3, 4,
|
||||
5, 6, 7, 8,
|
||||
9, 10, 11, 12,
|
||||
13, 14, 15, 16,
|
||||
}}
|
||||
m2 := &gglm.Mat4{
|
||||
Data: [16]float32{
|
||||
17, 18, 19, 20,
|
||||
21, 22, 23, 24,
|
||||
25, 26, 27, 28,
|
||||
29, 30, 31, 32,
|
||||
}}
|
||||
|
||||
result := gglm.MulMat4(m1, m2)
|
||||
m1.Mul(m2)
|
||||
|
||||
if !result.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", result.String(), correctAns.String())
|
||||
}
|
||||
|
||||
if !m1.Eq(&correctAns) {
|
||||
t.Errorf("Got: %v; Expected: %v", m1.String(), correctAns.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestMulMat4Vec4(t *testing.T) {
|
||||
|
||||
m := &gglm.Mat4{
|
||||
|
||||
Reference in New Issue
Block a user