-
Notifications
You must be signed in to change notification settings - Fork 0
/
materials_test.go
177 lines (160 loc) · 4.66 KB
/
materials_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package jbtracer
import "fmt"
func material(m1name string) error {
materials[m1name] = NewMaterial()
return nil
}
func materialEqualColor(mat1name string, red, green, blue float64) error {
if mat1, ok = materials[mat1name]; !ok {
return fmt.Errorf("Unknown symbol (color) %s", mat1name)
}
expected := &Color{red, green, blue}
got := mat1.Color
if !got.Equal(expected) {
return fmt.Errorf("Expected %s.color=%v; got %v", mat1name, expected, got)
}
return nil
}
func materialEqualAmbient(mat1name string, scalar float64) error {
if mat1, ok = materials[mat1name]; !ok {
return fmt.Errorf("Unknown symbol (material) %s", mat1name)
}
expected := scalar
got := mat1.Ambient
if got != expected {
return fmt.Errorf("Expected %s.Ambient=%v; got %v", mat1name, expected, got)
}
return nil
}
func materialEqualDiffuse(mat1name string, scalar float64) error {
if mat1, ok = materials[mat1name]; !ok {
return fmt.Errorf("Unknown symbol (material) %s", mat1name)
}
expected := scalar
got := mat1.Diffuse
if got != expected {
return fmt.Errorf("Expected %s.Diffuse=%v; got %v", mat1name, expected, got)
}
return nil
}
func materialEqualSpecular(mat1name string, scalar float64) error {
if mat1, ok = materials[mat1name]; !ok {
return fmt.Errorf("Unknown symbol (material) %s", mat1name)
}
expected := scalar
got := mat1.Specular
if got != expected {
return fmt.Errorf("Expected %s.Specular=%v; got %v", mat1name, expected, got)
}
return nil
}
func materialEqualShininess(mat1name string, scalar float64) error {
if mat1, ok = materials[mat1name]; !ok {
return fmt.Errorf("Unknown symbol (material) %s", mat1name)
}
expected := scalar
got := mat1.Shininess
if got != expected {
return fmt.Errorf("Expected %s.Shininess=%v; got %v", mat1name, expected, got)
}
return nil
}
func materialEqualReflective(mat1name string, scalar float64) error {
if mat1, ok = materials[mat1name]; !ok {
return fmt.Errorf("Unknown symbol (material) %s", mat1name)
}
expected := scalar
got := mat1.Reflective
if got != expected {
return fmt.Errorf("Expected %s.Reflective=%v; got %v", mat1name, expected, got)
}
return nil
}
func materialEqualTransparency(mat1name string, scalar float64) error {
if mat1, ok = materials[mat1name]; !ok {
return fmt.Errorf("Unknown symbol (material) %s", mat1name)
}
expected := scalar
got := mat1.Transparency
if got != expected {
return fmt.Errorf("Expected %s.Reflective=%v; got %v", mat1name, expected, got)
}
return nil
}
func materialEqualRefractiveIndex(mat1name string, scalar float64) error {
if mat1, ok = materials[mat1name]; !ok {
return fmt.Errorf("Unknown symbol (material) %s", mat1name)
}
expected := scalar
got := mat1.RefractiveIndex
if got != expected {
return fmt.Errorf("Expected %s.Reflective=%v; got %v", mat1name, expected, got)
}
return nil
}
func materialAmbient(mat1name string, scalar float64) error {
if mat1, ok = materials[mat1name]; !ok {
return fmt.Errorf("Unknown symbol (material) %s", mat1name)
}
mat1.Ambient = scalar
return nil
}
func materialEqual(mat1name, mat2name string) error {
if mat1, ok = materials[mat1name]; !ok {
return fmt.Errorf("Unknown symbol (material) %s", mat1name)
}
if mat2, ok = materials[mat2name]; !ok {
return fmt.Errorf("Unknown symbol (material) %s", mat2name)
}
expected := mat2
got := mat1
if !got.Equal(expected) {
return fmt.Errorf("Expected %s=%v; got %v", mat1name, expected, got)
}
return nil
}
func lighting(c1name, mat1name, t1name, t2name, t3name string) error {
if mat1, ok = materials[mat1name]; !ok {
return fmt.Errorf("Unknown symbol (material) %s", mat1name)
}
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)
}
colors[c1name] = mat1.Lighting(light, NewSphere(), t1, t2, t3, inShadow)
return nil
}
func materialInShadow(f string) error {
if f == "true" {
inShadow = true
} else {
inShadow = false
}
return nil
}
func materialDiffuse(mat1name string, scalar float64) error {
if mat1, ok = materials[mat1name]; !ok {
return fmt.Errorf("Unknown symbol (material) %s", mat1name)
}
mat1.Diffuse = scalar
return nil
}
func materialSpecular(mat1name string, scalar float64) error {
if mat1, ok = materials[mat1name]; !ok {
return fmt.Errorf("Unknown symbol (material) %s", mat1name)
}
mat1.Specular = scalar
return nil
}
func materialPattern(mat1name string) error {
if mat1, ok = materials[mat1name]; !ok {
return fmt.Errorf("Unknown symbol (material) %s", mat1name)
}
mat1.Pattern = pattern
return nil
}