forked from YARC-Official/YARG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VectorExtensions.cs
211 lines (160 loc) · 5.1 KB
/
VectorExtensions.cs
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
namespace UnityEngine {
public static class VectorExtensions {
/*
* Vector2 Utils
*/
public static Vector2 WithX(this Vector2 vec, float x) {
return new Vector2(x, vec.y);
}
public static Vector2 WithY(this Vector2 vec, float y) {
return new Vector2(vec.x, y);
}
public static Vector2 AddX(this Vector2 vec, float x) {
return new Vector2(vec.x + x, vec.y);
}
public static Vector2 AddY(this Vector2 vec, float y) {
return new Vector2(vec.x, vec.y + y);
}
public static Vector2 InvertX(this Vector2 vec) {
return new Vector2(-vec.x, vec.y);
}
public static Vector2 InvertY(this Vector2 vec) {
return new Vector2(vec.x, -vec.y);
}
public static Vector2 Invert(this Vector2 vec) {
return new Vector2(-vec.x, -vec.y);
}
public static Vector2 Abs(this Vector2 vec) {
return new Vector2(Mathf.Abs(vec.x), Mathf.Abs(vec.y));
}
/*
* Vector3 Utils
*/
public static Vector3 WithX(this Vector3 vec, float x) {
return new Vector3(x, vec.y, vec.z);
}
public static Vector3 WithY(this Vector3 vec, float y) {
return new Vector3(vec.x, y, vec.z);
}
public static Vector3 WithZ(this Vector3 vec, float z) {
return new Vector3(vec.x, vec.y, z);
}
public static Vector3 AddX(this Vector3 vec, float x) {
return new Vector3(vec.x + x, vec.y, vec.z);
}
public static Vector3 AddY(this Vector3 vec, float y) {
return new Vector3(vec.x, vec.y + y, vec.z);
}
public static Vector3 AddZ(this Vector3 vec, float z) {
return new Vector3(vec.x, vec.y, vec.z + z);
}
public static Vector3 InvertX(this Vector3 vec) {
return new Vector3(-vec.x, vec.y, vec.z);
}
public static Vector3 InvertY(this Vector3 vec) {
return new Vector3(vec.x, -vec.y, vec.z);
}
public static Vector3 InvertZ(this Vector3 vec) {
return new Vector3(vec.x, vec.y, -vec.z);
}
public static Vector3 Invert(this Vector3 vec) {
return new Vector3(-vec.x, -vec.y, -vec.z);
}
public static Vector3 Abs(this Vector3 vec) {
return new Vector3(Mathf.Abs(vec.x), Mathf.Abs(vec.y), Mathf.Abs(vec.z));
}
/*
* Vector2Int Utils
*/
public static Vector2Int WithX(this Vector2Int vec, int x) {
return new Vector2Int(x, vec.y);
}
public static Vector2Int WithY(this Vector2Int vec, int y) {
return new Vector2Int(vec.x, y);
}
public static Vector2Int AddX(this Vector2Int vec, int x) {
return new Vector2Int(vec.x + x, vec.y);
}
public static Vector2Int AddY(this Vector2Int vec, int y) {
return new Vector2Int(vec.x, vec.y + y);
}
public static Vector2Int InvertX(this Vector2Int vec) {
return new Vector2Int(-vec.x, vec.y);
}
public static Vector2Int InvertY(this Vector2Int vec) {
return new Vector2Int(vec.x, -vec.y);
}
public static Vector2Int Invert(this Vector2Int vec) {
return new Vector2Int(-vec.x, -vec.y);
}
public static Vector2Int Abs(this Vector2Int vec) {
return new Vector2Int(Mathf.Abs(vec.x), Mathf.Abs(vec.y));
}
/*
* Vector3Int Utils
*/
public static Vector3Int WithX(this Vector3Int vec, int x) {
return new Vector3Int(x, vec.y, vec.z);
}
public static Vector3Int WithY(this Vector3Int vec, int y) {
return new Vector3Int(vec.x, y, vec.z);
}
public static Vector3Int WithZ(this Vector3Int vec, int z) {
return new Vector3Int(vec.x, vec.y, z);
}
public static Vector3Int AddX(this Vector3Int vec, int x) {
return new Vector3Int(vec.x + x, vec.y, vec.z);
}
public static Vector3Int AddY(this Vector3Int vec, int y) {
return new Vector3Int(vec.x, vec.y + y, vec.z);
}
public static Vector3Int AddZ(this Vector3Int vec, int z) {
return new Vector3Int(vec.x, vec.y, vec.z + z);
}
public static Vector3Int InvertX(this Vector3Int vec) {
return new Vector3Int(-vec.x, vec.y, vec.z);
}
public static Vector3Int InvertY(this Vector3Int vec) {
return new Vector3Int(vec.x, -vec.y, vec.z);
}
public static Vector3Int InvertZ(this Vector3Int vec) {
return new Vector3Int(vec.x, vec.y, -vec.z);
}
public static Vector3Int Invert(this Vector3Int vec) {
return new Vector3Int(-vec.x, -vec.y, -vec.z);
}
public static Vector3Int Abs(this Vector3Int vec) {
return new Vector3Int(Mathf.Abs(vec.x), Mathf.Abs(vec.y), Mathf.Abs(vec.z));
}
/*
* VectorInt -> Vector
*/
public static Vector3 ToVector3(this Vector2Int v) {
return new Vector3(v.x, v.y);
}
public static Vector3 ToVector3(this Vector3Int v) {
return new Vector3(v.x, v.y, v.z);
}
public static Vector2 ToVector2(this Vector2Int v) {
return new Vector2(v.x, v.y);
}
public static Vector2 ToVector2(this Vector3Int v) {
return new Vector2(v.x, v.y);
}
/*
* Vector -> VectorInt
*/
public static Vector3Int ToVector3Int(this Vector3 v) {
return new Vector3Int((int) v.x, (int) v.y, (int) v.z);
}
public static Vector3Int ToVector3Int(this Vector2 v) {
return new Vector3Int((int) v.x, (int) v.y, 0);
}
public static Vector2Int ToVector2Int(this Vector3 v) {
return new Vector2Int((int) v.x, (int) v.y);
}
public static Vector2Int ToVector2Int(this Vector2 v) {
return new Vector2Int((int) v.x, (int) v.y);
}
}
}