-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
trs_test.go
81 lines (64 loc) · 2.35 KB
/
trs_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package trs_test
import (
"math"
"testing"
"github.com/EliCDavis/polyform/math/quaternion"
"github.com/EliCDavis/polyform/math/trs"
"github.com/EliCDavis/vector/vector3"
"github.com/stretchr/testify/assert"
)
func TestTransformArray(t *testing.T) {
// ARRANGE ================================================================
transform := trs.New(
vector3.New(1., 2., 3.),
quaternion.FromTheta(math.Pi, vector3.Forward[float64]()),
vector3.New(4., 5., 6.),
)
points := []vector3.Float64{
vector3.Zero[float64](),
vector3.One[float64](),
}
// ACT ====================================================================
out := transform.TransformArray(points)
// ASSERT =================================================================
assert.Len(t, out, len(points))
assert.Equal(t, vector3.New(1., 2., 3.), out[0])
assert.InDelta(t, -3., out[1].X(), 0.0000001)
assert.InDelta(t, -3., out[1].Y(), 0.0000001)
assert.InDelta(t, 9., out[1].Z(), 0.0000001)
}
func TestTransformInPlace(t *testing.T) {
// ARRANGE ================================================================
transform := trs.New(
vector3.New(1., 2., 3.),
quaternion.FromTheta(math.Pi, vector3.Forward[float64]()),
vector3.New(4., 5., 6.),
)
points := []vector3.Float64{
vector3.Zero[float64](),
vector3.One[float64](),
}
// ACT ====================================================================
transform.TransformInPlace(points)
// ASSERT =================================================================
assert.Equal(t, vector3.New(1., 2., 3.), points[0])
assert.InDelta(t, -3., points[1].X(), 0.0000001)
assert.InDelta(t, -3., points[1].Y(), 0.0000001)
assert.InDelta(t, 9., points[1].Z(), 0.0000001)
}
func TestTranslate(t *testing.T) {
// ARRANGE ================================================================
transform := trs.New(
vector3.New(1., 2., 3.),
quaternion.FromTheta(math.Pi, vector3.Forward[float64]()),
vector3.New(4., 5., 6.),
)
point := vector3.One[float64]()
// ACT ====================================================================
translated := transform.Translate(point)
newPosition := translated.Position()
// ASSERT =================================================================
assert.InDelta(t, 2., newPosition.X(), 0.0000001)
assert.InDelta(t, 3., newPosition.Y(), 0.0000001)
assert.InDelta(t, 4., newPosition.Z(), 0.0000001)
}