-
Notifications
You must be signed in to change notification settings - Fork 0
/
xyzcmd.go
91 lines (82 loc) · 2.01 KB
/
xyzcmd.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
package pbrtparser
import (
"fmt"
"strconv"
"strings"
)
// XYZCmd stores parameters of xyz command
// COMMANDTYPE X Y Z
type XYZCmd struct {
Cmd
X float64 `json:"x"`
Y float64 `json:"y"`
Z float64 `json:"z"`
}
func isXYZCmd(rawCommand string) bool {
for _, prefix := range []string{
"Translate",
"Scale",
} {
if strings.HasPrefix(rawCommand, prefix) {
return true
}
}
return false
}
func parseXYZCmd(rawCommand string) (*XYZCmd, error) {
parts := strings.Fields(rawCommand)
if len(parts) != 4 {
return nil, fmt.Errorf("pbrtparser.parseXYZCmd: Error form")
}
var err error
cmd := XYZCmd{}
cmd.X, err = strconv.ParseFloat(parts[1], 64)
if err != nil {
return nil, fmt.Errorf("pbrtparser.parseXYZCmd: %s", err)
}
cmd.Y, err = strconv.ParseFloat(parts[2], 64)
if err != nil {
return nil, fmt.Errorf("pbrtparser.parseXYZCmd: %s", err)
}
cmd.Z, err = strconv.ParseFloat(parts[3], 64)
if err != nil {
return nil, fmt.Errorf("pbrtparser.parseXYZCmd: %s", err)
}
cmd.CmdType = parts[0]
return &cmd, nil
}
// RotateCmd stores the parameters of lookat command:
// Rotate angle x y z
type RotateCmd struct {
Cmd
Angle float64 `json:"angle"`
X float64 `json:"x"`
Y float64 `json:"y"`
Z float64 `json:"z"`
}
func parseRotateCmd(rawCommand string) (*RotateCmd, error) {
parts := strings.Fields(rawCommand)
if len(parts) != 5 {
return nil, fmt.Errorf("pbrtparser.parseRotateCmd: Error form")
}
var err error
cmd := RotateCmd{}
cmd.Angle, err = strconv.ParseFloat(parts[1], 64)
if err != nil {
return nil, fmt.Errorf("pbrtparser.parseRotateCmd: %s", err)
}
cmd.X, err = strconv.ParseFloat(parts[2], 64)
if err != nil {
return nil, fmt.Errorf("pbrtparser.parseRotateCmd: %s", err)
}
cmd.Y, err = strconv.ParseFloat(parts[3], 64)
if err != nil {
return nil, fmt.Errorf("pbrtparser.parseRotateCmd: %s", err)
}
cmd.Z, err = strconv.ParseFloat(parts[4], 64)
if err != nil {
return nil, fmt.Errorf("pbrtparser.parseRotateCmd: %s", err)
}
cmd.CmdType = "Rotate"
return &cmd, nil
}