-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeometricvertex.go
More file actions
95 lines (86 loc) · 1.71 KB
/
geometricvertex.go
File metadata and controls
95 lines (86 loc) · 1.71 KB
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
package main
import (
"strconv"
"strings"
)
// GeometricVertex _ (v)
type GeometricVertex struct {
X, Y, Z float32
W float32
}
// Marshal _
func (v *GeometricVertex) Marshal(options MarshalOptions) string {
var sb strings.Builder
sb.WriteString("v ")
sb.WriteString(strconv.FormatFloat(float64(v.X), 'f', options.FloatPrecision, 32))
sb.WriteRune(' ')
sb.WriteString(strconv.FormatFloat(float64(v.Y), 'f', options.FloatPrecision, 32))
sb.WriteRune(' ')
sb.WriteString(strconv.FormatFloat(float64(v.Z), 'f', options.FloatPrecision, 32))
if options.OmitDefaultOptional && v.W == 1 {
return sb.String()
}
sb.WriteRune(' ')
sb.WriteString(strconv.FormatFloat(float64(v.W), 'f', options.FloatPrecision, 32))
return sb.String()
}
// ErrVertexBadFieldX _
// var ErrVertexBadFieldX = errors.New("bad field x")
// // ErrVertexBadFieldY _
// var ErrVertexBadFieldY = errors.New("bad field y")
// // ErrVertexBadFieldZ _
// var ErrVertexBadFieldZ = errors.New("bad field y")
// UnmarshalVertex _
func UnmarshalVertex(v string) (vertex GeometricVertex, rest string, ok bool) {
if v == "" {
ok = false
return
}
if v[0] != 'v' {
ok = false
return
}
v, ok = skipSpaces(v[1:])
if !ok {
return
}
x, v, ok := parseFloat(v)
if !ok {
return
}
v, ok = skipSpaces(v)
if !ok {
return
}
y, v, ok := parseFloat(v)
if !ok {
return
}
v, ok = skipSpaces(v)
if !ok {
return
}
z, v, ok := parseFloat(v)
if !ok {
return
}
if v == "" {
vertex = GeometricVertex{x, y, z, 0}
return
}
v, ok = skipSpaces(v)
if !ok {
return
}
if v == "" {
vertex = GeometricVertex{x, y, z, 0}
return
}
w, v, ok := parseFloat(v)
if !ok {
return
}
rest = v
vertex = GeometricVertex{x, y, z, w}
return
}