aboutsummaryrefslogtreecommitdiff
path: root/units.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-05-06 23:35:58 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-05-06 23:35:58 +0200
commit69668aa61de642ea275e6e2ace85f7b921480603 (patch)
tree94636741247c3c5142124de1b842de2eb3083ecd /units.go
parent67add8501fdc57029b5bf7d0ceff1bfb9acf49c2 (diff)
Separate Units
Diffstat (limited to 'units.go')
-rw-r--r--units.go48
1 files changed, 47 insertions, 1 deletions
diff --git a/units.go b/units.go
index 4ee5e2a..c3da609 100644
--- a/units.go
+++ b/units.go
@@ -1,9 +1,55 @@
package main
+import "fmt"
+
const (
- MM = 20.0
+ MM = Unit(20.0)
CM = 10 * MM
DM = 10 * CM
IN = 25.4 * MM
PT = IN / 72
)
+
+type Unit float64
+
+func (u Unit) String() string {
+ return fmt.Sprintf("%.2f", u)
+}
+
+type Point struct {
+ X, Y Unit
+}
+
+func (p Point) String() string {
+ return fmt.Sprintf("%v,%v", p.X, p.Y)
+}
+
+type Triple struct {
+ U, V, W Unit
+}
+
+func (t Triple) String() string {
+ return fmt.Sprintf("%v,%v,%v", t.U, t.V, t.W)
+}
+
+type Polar struct {
+ R, Theta Unit
+}
+
+type Path []Point
+
+func (p Point) Add(u Point) Point {
+ return Point{p.X + u.X, p.Y + u.Y}
+}
+
+func (p Point) Sub(u Point) Point {
+ return Point{p.X - u.X, p.Y - u.Y}
+}
+
+func (p Point) AddX(u Unit) Point {
+ return Point{p.X + u, p.Y}
+}
+
+func (p Point) AddY(u Unit) Point {
+ return Point{p.X, p.Y + u}
+}