-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAxes.go
More file actions
80 lines (72 loc) · 1.54 KB
/
Axes.go
File metadata and controls
80 lines (72 loc) · 1.54 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
package types
import (
"strconv"
)
// Axes represents a set of orthogonal coordinate axes that are considered
// active.
type Axes struct {
X, Y, Z bool
}
// NewAxesFromAxis returns an Axes where the axes corresponding to the given
// Axis values are active.
func NewAxesFromAxis(axes ...Axis) Axes {
a := Axes{}
for _, axis := range axes {
switch axis {
case AxisX:
a.X = true
case AxisY:
a.Y = true
case AxisZ:
a.Z = true
}
}
return a
}
// NewAxesFromFace returns an Axes where the axes corresponding to the given
// Face values are active.
func NewAxesFromFace(faces ...Face) Axes {
a := Axes{}
for _, face := range faces {
switch face {
case FaceRight, FaceLeft:
a.X = true
case FaceTop, FaceBottom:
a.Y = true
case FaceBack, FaceFront:
a.Z = true
}
}
return a
}
// Face returns whether the axis corresponding to the given Face is active.
func (a Axes) Face(face Face) bool {
switch face {
case FaceRight, FaceLeft:
return a.X
case FaceTop, FaceBottom:
return a.Y
case FaceBack, FaceFront:
return a.Z
}
return false
}
// Type returns a string that identifies the type.
func (Axes) Type() string {
return "Axes"
}
// String returns a human-readable string representation of the value.
func (a Axes) String() string {
var b []byte
b = append(b, "X:"...)
b = strconv.AppendBool(b, a.X)
b = append(b, ", Y:"...)
b = strconv.AppendBool(b, a.Y)
b = append(b, ", Z:"...)
b = strconv.AppendBool(b, a.Z)
return string(b)
}
// Copy returns a copy of the value.
func (a Axes) Copy() PropValue {
return a
}