aboutsummaryrefslogtreecommitdiff
path: root/units.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-05-06 23:40:20 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-05-06 23:40:20 +0200
commitb689698a7853bf8ce56a2d028e3ae47672ea090e (patch)
treede6980ce2962aef2bfc18d2441f5cd89851a168f /units.go
parent69668aa61de642ea275e6e2ace85f7b921480603 (diff)
add scan functions
Diffstat (limited to 'units.go')
-rw-r--r--units.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/units.go b/units.go
index c3da609..89abcc3 100644
--- a/units.go
+++ b/units.go
@@ -16,6 +16,11 @@ func (u Unit) String() string {
return fmt.Sprintf("%.2f", u)
}
+func ScanUnit(s string) (u Unit) {
+ fmt.Sscanf(s, "%v", &u)
+ return
+}
+
type Point struct {
X, Y Unit
}
@@ -24,6 +29,11 @@ func (p Point) String() string {
return fmt.Sprintf("%v,%v", p.X, p.Y)
}
+func ScanPoint(s string) (p Point) {
+ fmt.Sscanf(s, "%v,%v", &p.X, &p.Y)
+ return
+}
+
type Triple struct {
U, V, W Unit
}
@@ -32,6 +42,11 @@ func (t Triple) String() string {
return fmt.Sprintf("%v,%v,%v", t.U, t.V, t.W)
}
+func ScanTriple(s string) (t Triple) {
+ fmt.Sscanf(s, "%v,%v,%v", &t.U, &t.V, &t.W)
+ return
+}
+
type Polar struct {
R, Theta Unit
}