This repository was archived by the owner on Apr 9, 2024. It is now read-only.
forked from sheenobu/go-obj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshared_test.go
86 lines (67 loc) · 1.85 KB
/
shared_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
package obj
import "fmt"
// shared test code
type stringList []string
func (sl stringList) ToByteList() (arr [][]byte) {
for _, s := range sl {
arr = append(arr, []byte(s))
}
return
}
func comparePoints(p1 *Point, p2 *Point) bool {
if p1 == p2 {
return true
}
if (p1 != nil && p2 == nil) || (p1 == nil && p2 != nil) {
return false
}
eq := true
eq = eq && compareVertices(p1.Vertex, p2.Vertex)
eq = eq && compareNormals(p1.Normal, p2.Normal)
eq = eq && compareTextureCoords(p1.Texture, p2.Texture)
return eq
}
func compareVertices(v1 *Vertex, v2 *Vertex) bool {
if v1 == nil && v2 != nil || v1 != nil && v2 == nil {
return false
}
return v1 == nil && v2 == nil || v1.Index == v2.Index && v1.X == v2.X && v1.Y == v2.Y && v1.Z == v2.Z
}
func compareNormals(n1 *Normal, n2 *Normal) bool {
if n1 == nil && n2 != nil || n1 != nil && n2 == nil {
return false
}
return n1 == nil && n2 == nil || n1.Index == n2.Index && n1.X == n2.X && n1.Y == n2.Y && n1.Z == n2.Z
}
func compareTextureCoords(t1 *TextureCoord, t2 *TextureCoord) bool {
if (t1 == nil && t2 != nil) || (t1 != nil && t2 == nil) {
return false
}
return t1 == nil && t2 == nil || t1.Index == t2.Index && t1.U == t2.U && t1.V == t2.V && t1.W == t2.W
}
func compareErrors(err error, expected string) bool {
if expected == "" && err != nil {
return false
} else if err != nil && expected != err.Error() {
return false
}
return true
}
func (v *Vertex) String() string {
if v == nil {
return "Vertex{nil}"
}
return fmt.Sprintf("Vertex{%d %f %f %f}", v.Index, v.X, v.Y, v.Z)
}
func (n *Normal) String() string {
if n == nil {
return "Normal{nil}"
}
return fmt.Sprintf("Normal{%d %f %f %f}", n.Index, n.X, n.Y, n.Z)
}
func (t *TextureCoord) String() string {
if t == nil {
return "TextureCoord{nil}"
}
return fmt.Sprintf("TextureCoord{%d %f %f %f}", t.Index, t.U, t.V, t.W)
}