-
Notifications
You must be signed in to change notification settings - Fork 0
/
transformations_test.go
72 lines (64 loc) · 1.69 KB
/
transformations_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
package jbtracer
import "fmt"
func matrixTranslation(m1name string, x, y, z float64) error {
matrices[m1name] = Translation(x, y, z)
return nil
}
func matrixScaling(m1name string, x, y, z float64) error {
matrices[m1name] = Scaling(x, y, z)
return nil
}
func matrixRotation(m1name, axis string, radians float64) error {
var axisInt int
switch axis {
case "x":
axisInt = Axis_X
case "y":
axisInt = Axis_Y
case "z":
axisInt = Axis_Z
}
matrices[m1name] = Rotation(axisInt, radians)
return nil
}
func matrixShearing(m1name string, xY, xZ, yX, yZ, zX, zY float64) error {
matrices[m1name] = Shearing(xY, xZ, yX, yZ, zX, zY)
return nil
}
func tupleMatrixAssign(t1name, m1name, t2name string) error {
if m1, ok = matrices[m1name]; !ok {
return fmt.Errorf("Unknown symbol %s", m1name)
}
if t2, ok = tuples[t2name]; !ok {
return fmt.Errorf("Unknown symbol %s", t2name)
}
tuples[t1name] = m1.MultiplyTuple(t2)
return nil
}
func tupleEqual(t1name, t2name string) error {
if t1, ok = tuples[t1name]; !ok {
return fmt.Errorf("Unknown symbol %s", t1name)
}
if t2, ok = tuples[t2name]; !ok {
return fmt.Errorf("Unknown symbol %s", t2name)
}
expected := t1
got := t2
if !got.Equal(expected) {
return fmt.Errorf("Expected %s = %v; got %v", t2name, expected, got)
}
return nil
}
func matrixViewTransform(m1name, t1name, t2name, t3name string) error {
if t1, ok = tuples[t1name]; !ok {
return fmt.Errorf("Unknown symbol (tuple) %s", t1name)
}
if t2, ok = tuples[t2name]; !ok {
return fmt.Errorf("Unknown symbol (tuple) %s", t2name)
}
if t3, ok = tuples[t3name]; !ok {
return fmt.Errorf("Unknown symbol (tuple) %s", t3name)
}
matrices[m1name] = ViewTransform(t1, t2, t3)
return nil
}