forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector3Int.cs
More file actions
276 lines (237 loc) · 11 KB
/
Copy pathVector3Int.cs
File metadata and controls
276 lines (237 loc) · 11 KB
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
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Globalization;
using System.Runtime.InteropServices;
using UnityEngine.Scripting;
using System.Runtime.CompilerServices;
namespace UnityEngine
{
[UsedByNativeCode]
[StructLayout(LayoutKind.Sequential)]
[Unity.IL2CPP.CompilerServices.Il2CppEagerStaticClassConstruction]
public struct Vector3Int : IEquatable<Vector3Int>, IFormattable
{
public int x { [MethodImpl(MethodImplOptionsEx.AggressiveInlining)] get { return m_X; }[MethodImpl(MethodImplOptionsEx.AggressiveInlining)] set { m_X = value; } }
public int y { [MethodImpl(MethodImplOptionsEx.AggressiveInlining)] get { return m_Y; }[MethodImpl(MethodImplOptionsEx.AggressiveInlining)] set { m_Y = value; } }
public int z { [MethodImpl(MethodImplOptionsEx.AggressiveInlining)] get { return m_Z; }[MethodImpl(MethodImplOptionsEx.AggressiveInlining)] set { m_Z = value; } }
private int m_X;
private int m_Y;
private int m_Z;
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public Vector3Int(int x, int y)
{
m_X = x;
m_Y = y;
m_Z = 0;
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public Vector3Int(int x, int y, int z)
{
m_X = x;
m_Y = y;
m_Z = z;
}
// Set x, y and z components of an existing Vector.
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public void Set(int x, int y, int z)
{
m_X = x;
m_Y = y;
m_Z = z;
}
// Access the /x/, /y/ or /z/ component using [0], [1] or [2] respectively.
public int this[int index]
{
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
get
{
switch (index)
{
case 0: return x;
case 1: return y;
case 2: return z;
default:
throw new IndexOutOfRangeException(UnityString.Format("Invalid Vector3Int index addressed: {0}!", index));
}
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
set
{
switch (index)
{
case 0: x = value; break;
case 1: y = value; break;
case 2: z = value; break;
default:
throw new IndexOutOfRangeException(UnityString.Format("Invalid Vector3Int index addressed: {0}!", index));
}
}
}
// Returns the length of this vector (RO).
public float magnitude { [MethodImpl(MethodImplOptionsEx.AggressiveInlining)] get { return Mathf.Sqrt((float)(x * x + y * y + z * z)); } }
// Returns the squared length of this vector (RO).
public int sqrMagnitude { [MethodImpl(MethodImplOptionsEx.AggressiveInlining)] get { return x * x + y * y + z * z; } }
// Returns the distance between /a/ and /b/.
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static float Distance(Vector3Int a, Vector3Int b) { return (a - b).magnitude; }
// Returns a vector that is made from the smallest components of two vectors.
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static Vector3Int Min(Vector3Int lhs, Vector3Int rhs) { return new Vector3Int(Mathf.Min(lhs.x, rhs.x), Mathf.Min(lhs.y, rhs.y), Mathf.Min(lhs.z, rhs.z)); }
// Returns a vector that is made from the largest components of two vectors.
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static Vector3Int Max(Vector3Int lhs, Vector3Int rhs) { return new Vector3Int(Mathf.Max(lhs.x, rhs.x), Mathf.Max(lhs.y, rhs.y), Mathf.Max(lhs.z, rhs.z)); }
// Multiplies two vectors component-wise.
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static Vector3Int Scale(Vector3Int a, Vector3Int b) { return new Vector3Int(a.x * b.x, a.y * b.y, a.z * b.z); }
// Multiplies every component of this vector by the same component of /scale/.
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public void Scale(Vector3Int scale) { x *= scale.x; y *= scale.y; z *= scale.z; }
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public void Clamp(Vector3Int min, Vector3Int max)
{
x = Math.Max(min.x, x);
x = Math.Min(max.x, x);
y = Math.Max(min.y, y);
y = Math.Min(max.y, y);
z = Math.Max(min.z, z);
z = Math.Min(max.z, z);
}
// Converts a Vector3Int to a [[Vector3]].
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static implicit operator Vector3(Vector3Int v)
{
return new Vector3(v.x, v.y, v.z);
}
// Converts a Vector3Int to a [[Vector2Int]].
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static explicit operator Vector2Int(Vector3Int v)
{
return new Vector2Int(v.x, v.y);
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static Vector3Int FloorToInt(Vector3 v)
{
return new Vector3Int(
Mathf.FloorToInt(v.x),
Mathf.FloorToInt(v.y),
Mathf.FloorToInt(v.z)
);
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static Vector3Int CeilToInt(Vector3 v)
{
return new Vector3Int(
Mathf.CeilToInt(v.x),
Mathf.CeilToInt(v.y),
Mathf.CeilToInt(v.z)
);
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static Vector3Int RoundToInt(Vector3 v)
{
return new Vector3Int(
Mathf.RoundToInt(v.x),
Mathf.RoundToInt(v.y),
Mathf.RoundToInt(v.z)
);
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static Vector3Int operator+(Vector3Int a, Vector3Int b)
{
return new Vector3Int(a.x + b.x, a.y + b.y, a.z + b.z);
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static Vector3Int operator-(Vector3Int a, Vector3Int b)
{
return new Vector3Int(a.x - b.x, a.y - b.y, a.z - b.z);
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static Vector3Int operator*(Vector3Int a, Vector3Int b)
{
return new Vector3Int(a.x * b.x, a.y * b.y, a.z * b.z);
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static Vector3Int operator-(Vector3Int a)
{
return new Vector3Int(-a.x, -a.y, -a.z);
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static Vector3Int operator*(Vector3Int a, int b)
{
return new Vector3Int(a.x * b, a.y * b, a.z * b);
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static Vector3Int operator*(int a, Vector3Int b)
{
return new Vector3Int(a * b.x, a * b.y, a * b.z);
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static Vector3Int operator/(Vector3Int a, int b)
{
return new Vector3Int(a.x / b, a.y / b, a.z / b);
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static bool operator==(Vector3Int lhs, Vector3Int rhs)
{
return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z;
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static bool operator!=(Vector3Int lhs, Vector3Int rhs)
{
return !(lhs == rhs);
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public override bool Equals(object other)
{
if (!(other is Vector3Int)) return false;
return Equals((Vector3Int)other);
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public bool Equals(Vector3Int other)
{
return this == other;
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public override int GetHashCode()
{
var yHash = y.GetHashCode();
var zHash = z.GetHashCode();
return x.GetHashCode() ^ (yHash << 4) ^ (yHash >> 28) ^ (zHash >> 4) ^ (zHash << 28);
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public override string ToString()
{
return ToString(null, null);
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public string ToString(string format)
{
return ToString(format, null);
}
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public string ToString(string format, IFormatProvider formatProvider)
{
if (formatProvider == null)
formatProvider = CultureInfo.InvariantCulture.NumberFormat;
return UnityString.Format("({0}, {1}, {2})", x.ToString(format, formatProvider), y.ToString(format, formatProvider), z.ToString(format, formatProvider));
}
public static Vector3Int zero { [MethodImpl(MethodImplOptionsEx.AggressiveInlining)] get { return s_Zero; } }
public static Vector3Int one { [MethodImpl(MethodImplOptionsEx.AggressiveInlining)] get { return s_One; } }
public static Vector3Int up { [MethodImpl(MethodImplOptionsEx.AggressiveInlining)] get { return s_Up; } }
public static Vector3Int down { [MethodImpl(MethodImplOptionsEx.AggressiveInlining)] get { return s_Down; } }
public static Vector3Int left { [MethodImpl(MethodImplOptionsEx.AggressiveInlining)] get { return s_Left; } }
public static Vector3Int right { [MethodImpl(MethodImplOptionsEx.AggressiveInlining)] get { return s_Right; } }
public static Vector3Int forward { [MethodImpl(MethodImplOptionsEx.AggressiveInlining)] get { return s_Forward; } }
public static Vector3Int back { [MethodImpl(MethodImplOptionsEx.AggressiveInlining)] get { return s_Back; } }
private static readonly Vector3Int s_Zero = new Vector3Int(0, 0, 0);
private static readonly Vector3Int s_One = new Vector3Int(1, 1, 1);
private static readonly Vector3Int s_Up = new Vector3Int(0, 1, 0);
private static readonly Vector3Int s_Down = new Vector3Int(0, -1, 0);
private static readonly Vector3Int s_Left = new Vector3Int(-1, 0, 0);
private static readonly Vector3Int s_Right = new Vector3Int(1, 0, 0);
private static readonly Vector3Int s_Forward = new Vector3Int(0, 0, 1);
private static readonly Vector3Int s_Back = new Vector3Int(0, 0, -1);
}
}