-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
67 lines (63 loc) · 1.15 KB
/
utils.go
File metadata and controls
67 lines (63 loc) · 1.15 KB
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
package main
func Clamp(v, a, b int) int {
if v < a {
return a
}
if v > b {
return b
}
return v
}
type Vector2d struct {
x, y int
}
func (v *Vector2d) Negate() *Vector2d {
return &Vector2d{-v.x, -v.y}
}
var V = struct {
Zero Vector2d
Identity Vector2d
Left Vector2d
Right Vector2d
Up Vector2d
Down Vector2d
Equal func(Vector2d, Vector2d) bool
Negate func(Vector2d) Vector2d
Sum func(Vector2d, Vector2d) Vector2d
Multiply func(Vector2d, int) Vector2d
Divide func(Vector2d, int) Vector2d
}{
Zero: Vector2d{0, 0},
Identity: Vector2d{1, 1},
Left: Vector2d{-1, 0},
Right: Vector2d{1, 0},
Up: Vector2d{0, -1},
Down: Vector2d{0, 1},
Equal: func(a Vector2d, b Vector2d) bool {
return a.x == b.x && a.y == b.y
},
Negate: func(a Vector2d) Vector2d {
return Vector2d{
-a.x,
-a.y,
}
},
Sum: func(a Vector2d, b Vector2d) Vector2d {
return Vector2d{
a.x + b.x,
a.y + b.y,
}
},
Multiply: func(a Vector2d, b int) Vector2d {
return Vector2d{
a.x * b,
a.y * b,
}
},
Divide: func(a Vector2d, b int) Vector2d {
return Vector2d{
a.x / b,
a.y / b,
}
},
}