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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
/////////////////////////////////////////////////////////////////////////////////
//
// author: hanjun
// date: 2018/12/03 16:31:57
// desc: 某类
//
//
//
//
//
/////////////////////////////////////////////////////////////////////////////////
using UnityEngine;
using System.Collections;
namespace WK
{
[System.Serializable]
public struct IntVector2
{
public int x;
public int y;
public IntVector2(int x, int y)
{
this.x = x;
this.y = y;
}
static IntVector2 mZero = new IntVector2(0, 0);
static IntVector2 mOne = new IntVector2(1, 1);
public static IntVector2 Zero
{
get
{
return mZero;
}
}
public static IntVector2 One
{
get
{
return mOne;
}
}
public int ConstCount
{
get
{
return 2;
}
}
public int this[int index]
{
get
{
switch (index)
{
case 0:
return x;
case 1:
return y;
default:
throw new System.ArgumentOutOfRangeException("IntVector2索引越界");
}
}
set
{
switch (index)
{
case 0:
x = value;
break;
case 1:
y = value;
break;
default:
throw new System.ArgumentOutOfRangeException("IntVector2索引越界");
}
}
}
public static implicit operator Vector2(IntVector2 v)
{
return new Vector2(v.x, v.y);
}
public static IntVector2 operator *(int d, IntVector2 a)
{
a.x *= d;
a.y *= d;
return a;
}
public static bool operator ==(IntVector2 lhs, IntVector2 rhs)
{
return (lhs.x == rhs.x && lhs.y == rhs.y);
}
public static bool operator !=(IntVector2 lhs, IntVector2 rhs)
{
return (lhs.x != rhs.x || lhs.y != rhs.y);
}
public override string ToString()
{
return StringUtil.Concat(x.ToTempString(), ",", y.ToTempString());
}
public override bool Equals(object obj)
{
if (obj is IntVector2)
{
IntVector2 other = (IntVector2)obj;
return other.x == x && other.y == y;
}
else
{
return false;
}
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
public struct IntVector3
{
public int x;
public int y;
public int z;
public IntVector3(int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
}
static IntVector3 mZero = new IntVector3(0, 0, 0);
public static IntVector3 Zero
{
get
{
return mZero;
}
}
public int ConstCount
{
get
{
return 3;
}
}
public int this[int index]
{
get
{
switch (index)
{
case 0:
return x;
case 1:
return y;
case 2:
return z;
default:
throw new System.ArgumentOutOfRangeException("IntVector3索引越界");
}
}
set
{
switch (index)
{
case 0:
x = value;
break;
case 1:
y = value;
break;
case 2:
z = value;
break;
default:
throw new System.ArgumentOutOfRangeException("IntVector3索引越界");
}
}
}
public static implicit operator Vector3(IntVector3 v)
{
return new Vector3(v.x, v.y, v.z);
}
public static IntVector3 operator *(int d, IntVector3 a)
{
a.x *= d;
a.y *= d;
a.z *= d;
return a;
}
public static bool operator ==(IntVector3 lhs, IntVector3 rhs)
{
return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z);
}
public static bool operator !=(IntVector3 lhs, IntVector3 rhs)
{
return (lhs.x != rhs.x || lhs.y != rhs.y || lhs.z != rhs.z);
}
public override string ToString()
{
return StringUtil.Concat(x.ToTempString(), ",", y.ToTempString(), ",", z.ToTempString());
}
public override bool Equals(object obj)
{
if (obj is IntVector3)
{
IntVector3 other = (IntVector3)obj;
return other.x == x && other.y == y && other.z == z;
}
else
{
return false;
}
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public bool Contains(int a)
{
if (x == a || y == a || z == a)
return true;
return false;
}
}
public struct IntVector4
{
public int x;
public int y;
public int z;
public int w;
public IntVector4(int x, int y, int z, int w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
static IntVector4 mZero = new IntVector4(0, 0, 0, 0);
public static IntVector4 Zero
{
get
{
return mZero;
}
}
public static int ConstCount
{
get
{
return 4;
}
}
public int this[int index]
{
get
{
switch (index)
{
case 0:
return x;
case 1:
return y;
case 2:
return z;
case 3:
return w;
default:
throw new System.ArgumentOutOfRangeException("IntVector4索引越界");
}
}
set
{
switch (index)
{
case 0:
x = value;
break;
case 1:
y = value;
break;
case 2:
z = value;
break;
case 3:
w = value;
break;
default:
throw new System.ArgumentOutOfRangeException("IntVector4索引越界");
}
}
}
public static implicit operator Vector4(IntVector4 v)
{
return new Vector4(v.x, v.y, v.z, v.w);
}
public static IntVector4 operator *(int d, IntVector4 a)
{
a.x *= d;
a.y *= d;
a.z *= d;
a.w *= d;
return a;
}
public static bool operator ==(IntVector4 lhs, IntVector4 rhs)
{
return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z && lhs.w == rhs.w);
}
public static bool operator !=(IntVector4 lhs, IntVector4 rhs)
{
return (lhs.x != rhs.x || lhs.y != rhs.y || lhs.z != rhs.z || lhs.w != rhs.w);
}
public override string ToString()
{
return StringUtil.Concat(x.ToTempString(), ",", y.ToTempString(), ",", z.ToTempString(), ",", w.ToTempString());
}
public override bool Equals(object obj)
{
if (obj is IntVector4)
{
IntVector4 other = (IntVector4)obj;
return other.x == x && other.y == y && other.z == z && other.w == w;
}
else
{
return false;
}
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}
|