diff options
author | Dimitri Sokolyuk <demon@dim13.org> | 2015-05-03 16:13:31 +0200 |
---|---|---|
committer | Dimitri Sokolyuk <demon@dim13.org> | 2015-05-03 16:13:31 +0200 |
commit | 05b47262e327607d5da1b3e8ff6336d0e5eaa77c (patch) | |
tree | 5c47b3217933306126971419f96673fe7b8d8e96 /pic.go | |
parent | 9f75aa9fe83e46a4bb3bea9d36ed78a41a4036e3 (diff) |
Add pic parser
Diffstat (limited to 'pic.go')
-rw-r--r-- | pic.go | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -0,0 +1,43 @@ +package main + +import ( + "bufio" + "fmt" + "log" + "os" + "strings" +) + +type Page []Path + +const scale = 24.5 * 20 + +func truncate(f float64) float64 { + return float64(int(f*100)) / 100 +} + +func parseLine(s string) (pa Path) { + if strings.HasPrefix(s, "line from ") { + for _, p := range strings.Split(s[10:], " to ") { + var po Point + fmt.Sscanf(p, "%v,%v", &po.Y, &po.X) + po.X = truncate(5440 - po.X*scale) + po.Y = truncate(po.Y * scale) + pa = append(pa, po) + } + } + return pa +} + +func parsePage() (pa Page) { + scanner := bufio.NewScanner(os.Stdin) + for scanner.Scan() { + if p := parseLine(scanner.Text()); p != nil { + pa = append(pa, p) + } + } + if err := scanner.Err(); err != nil { + log.Fatal(err) + } + return pa +} |