forked from AllenDang/cimgui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector_helpers.go
54 lines (45 loc) · 849 Bytes
/
vector_helpers.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
package imgui
// implement vector operations
// Vec2:
// Add returns a sum of v and another.
func (v Vec2) Add(another Vec2) Vec2 {
return Vec2{
X: v.X + another.X,
Y: v.Y + another.Y,
}
}
// Sub returns the vector v - another.
func (v Vec2) Sub(another Vec2) Vec2 {
return Vec2{
X: v.X - another.X,
Y: v.Y - another.Y,
}
}
// Mul returns the vector v*k.
func (v Vec2) Mul(k float32) Vec2 {
return Vec2{
X: v.X * k,
Y: v.Y * k,
}
}
// Div returns the vector v/k.
func (v Vec2) Div(k float32) Vec2 {
return Vec2{
X: v.X / k,
Y: v.Y / k,
}
}
// Vec4
// Add returns the rectangle r translated by p.
func (v Vec4) Add(p Vec2) Vec4 {
return Vec4{
X: v.X + p.X,
Y: v.Y + p.Y,
Z: v.Z + p.X,
W: v.W + p.Y,
}
}
// Sub returns the vec4 v translated by -p.
func (v Vec4) Sub(p Vec2) Vec4 {
return v.Add(p.Mul(-1))
}