-
Notifications
You must be signed in to change notification settings - Fork 0
/
coords.go
47 lines (38 loc) · 1.01 KB
/
coords.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
package naiad
import "github.com/faiface/pixel"
// Vector represents a coordinate pair. It can be used to specify things such as
// bounds, or 2D coordinates.
type Vector struct {
x float64
y float64
}
// V is a quick way to create a new vector out of x and y coordinates.
func V(x, y float64) (vector Vector) {
vector.x = x
vector.y = y
return
}
// pixellate converts a naiad vector into a pixel vector.
func (vector Vector) pixellate() (vec pixel.Vec) {
return pixel.Vec{X: vector.x, Y: vector.y}
}
// vFromPixel converts a pixel vector into a naiad vector.
func vFromPixel(vec pixel.Vec) (vector Vector) {
return V(vec.X, vec.Y)
}
// X returns the x value of the vector.
func (vector Vector) X() (x float64) {
return vector.x
}
// Y returns thw x value of the vector.
func (vector Vector) Y() (y float64) {
return vector.y
}
// SetX sets the x value of the vector.
func (vector *Vector) SetX(x float64) {
vector.x = x
}
// SetY sets the y value of the vector.
func (vector *Vector) SetY(y float64) {
vector.y = y
}