-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvector.go
More file actions
31 lines (27 loc) · 725 Bytes
/
vector.go
File metadata and controls
31 lines (27 loc) · 725 Bytes
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
// Package verlet contains the basic units to build more complex verlet systems.
package verlet
// Vector is a simple struct representing a 2d math vector.
type Vector struct {
X, Y float64
}
// Add sum 'other' to 'v' and return the result in a new vector.
func (v Vector) Add(other Vector) Vector {
return Vector{
X: v.X + other.X,
Y: v.Y + other.Y,
}
}
// Sub subtracts 'other' from 'v' and return the result in a new vector.
func (v Vector) Sub(other Vector) Vector {
return Vector{
X: v.X - other.X,
Y: v.Y - other.Y,
}
}
// Scale multiplies 'v' by a scalar and returns the result in a new vector.
func (v Vector) Scale(scalar float64) Vector {
return Vector{
X: v.X * scalar,
Y: v.Y * scalar,
}
}