blob: 8c9f126a6abaec150fa8da3ff4939b60028b4c8e (
plain)
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
|
package structs
type Vec2 struct {
X float64 `json:"X"`
Y float64 `json:"Y"`
}
// NewVec2 returns a new Vec2 using the given coordinates
func NewVec2(x float64, y float64) Vec2 {
return Vec2{
X: x,
Y: y,
}
}
// Copy creates a copy of the vector
func (v *Vec2) Copy() Vec2 {
return Vec2{v.X, v.Y}
}
// returns the product of the vector and a scalar s
func (v *Vec2) Multiply(s float64) Vec2 {
return Vec2{v.X * s, v.Y * s}
}
// returns the sum of this vector and the vector v2
func (v1 *Vec2) Add(v2 Vec2) Vec2 {
return Vec2{v1.X + v2.X, v1.Y + v2.Y}
}
|