-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
points.go
75 lines (64 loc) · 1.18 KB
/
points.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
66
67
68
69
70
71
72
73
74
75
package glyph
import (
"fmt"
"sort"
"strconv"
)
type Point struct {
X float64
Y float64
}
type Points map[string]*Point
func (p Points) Get(key string) (*Point, error) {
v, ok := p[key]
if !ok {
return nil, fmt.Errorf("invalid key: %s", key)
}
return v, nil
}
func (p Points) Keys() []string {
keys := []string{}
for k := range p {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}
const dx = 8.660254
const dy = 5.0
var cPoints = Points{}
func GetPoints() Points {
if len(cPoints) > 0 {
return cPoints
}
points := Points{}
px := 0xf
py := 0x0
f0x := 55.0
f0y := 5.0
maxy := 10
// f,e,d,c,b,a
for i := 0; i <= 5; i++ {
max := maxy - i
for j := 0; j <= max; j++ {
key := fmt.Sprintf("%s%x", strconv.FormatInt(int64(px-i), 21), py+j)
points[key] = &Point{
X: f0x - float64(i)*dx,
Y: f0y + float64(i)*dy + float64(j)*dy*2,
}
}
}
// g,h,i,j,k
for i := 1; i <= 5; i++ {
max := maxy - i
for j := 0; j <= max; j++ {
key := fmt.Sprintf("%s%x", strconv.FormatInt(int64(px+i), 21), py+j)
points[key] = &Point{
X: f0x + float64(i)*dx,
Y: f0y + float64(i)*dy + float64(j)*dy*2,
}
}
}
cPoints = points
return points
}