This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
/
Vectors.go
108 lines (97 loc) · 1.89 KB
/
Vectors.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package imgui
// #include "wrapper/Types.h"
import "C"
// Vec2 represents a two-dimensional vector.
type Vec2 struct {
X float32
Y float32
}
func (vec *Vec2) wrapped() (out *C.IggVec2, finisher func()) {
if vec != nil {
out = &C.IggVec2{
x: C.float(vec.X),
y: C.float(vec.Y),
}
finisher = func() {
vec.X = float32(out.x) // nolint: gotype
vec.Y = float32(out.y) // nolint: gotype
}
} else {
finisher = func() {}
}
return
}
// Plus returns vec + other.
func (vec Vec2) Plus(other Vec2) Vec2 {
return Vec2{
X: vec.X + other.X,
Y: vec.Y + other.Y,
}
}
// Minus returns vec - other.
func (vec Vec2) Minus(other Vec2) Vec2 {
return Vec2{
X: vec.X - other.X,
Y: vec.Y - other.Y,
}
}
// Times returns vec * value.
func (vec Vec2) Times(value float32) Vec2 {
return Vec2{
X: vec.X * value,
Y: vec.Y * value,
}
}
// Vec4 represents a four-dimensional vector.
type Vec4 struct {
X float32
Y float32
Z float32
W float32
}
func (vec *Vec4) wrapped() (out *C.IggVec4, finisher func()) {
if vec != nil {
out = &C.IggVec4{
x: C.float(vec.X),
y: C.float(vec.Y),
z: C.float(vec.Z),
w: C.float(vec.W),
}
finisher = func() {
vec.X = float32(out.x) // nolint: gotype
vec.Y = float32(out.y) // nolint: gotype
vec.Z = float32(out.z) // nolint: gotype
vec.W = float32(out.w) // nolint: gotype
}
} else {
finisher = func() {}
}
return
}
// Plus returns vec + other.
func (vec Vec4) Plus(other Vec4) Vec4 {
return Vec4{
X: vec.X + other.X,
Y: vec.Y + other.Y,
Z: vec.Z + other.Z,
W: vec.W + other.W,
}
}
// Minus returns vec - other.
func (vec Vec4) Minus(other Vec4) Vec4 {
return Vec4{
X: vec.X - other.X,
Y: vec.Y - other.Y,
Z: vec.Z - other.Z,
W: vec.W - other.W,
}
}
// Times returns vec * value.
func (vec Vec4) Times(value float32) Vec4 {
return Vec4{
X: vec.X * value,
Y: vec.Y * value,
Z: vec.Z * value,
W: vec.W * value,
}
}