-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
units.go
65 lines (51 loc) · 951 Bytes
/
units.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
package robo
import "fmt"
const (
MM = Unit(20.0)
CM = 10 * MM
M = 100 * CM
IN = 25.4 * MM
FT = 12 * IN
PT = IN / 72
)
var A4 = Point{272 * MM, 200 * MM}
type Unit float64
func (u Unit) String() string {
if u == Unit(int(u)) {
return fmt.Sprint(int(u))
} else {
return fmt.Sprintf("%.3f", u)
}
}
func parseUnit(s string) (u Unit) {
fmt.Sscanf(s, "%v", &u)
return
}
type Point struct {
X, Y Unit
}
var orientation = Portrait
func (p Point) String() (s string) {
switch orientation {
case Portrait:
s = fmt.Sprintf("%v,%v", p.X, p.Y)
case Landscape:
s = fmt.Sprintf("%v,%v", p.Y, p.X)
}
return
}
func parsePoint(s string) (p Point) {
fmt.Sscanf(s, "%v,%v", &p.X, &p.Y)
return
}
type Triple struct {
U, V, W Unit
}
func (t Triple) String() string {
return fmt.Sprintf("%v,%v,%v", t.U, t.V, t.W)
}
func parseTriple(s string) (t Triple) {
fmt.Sscanf(s, "%v,%v,%v", &t.U, &t.V, &t.W)
return
}
type Path []Point