Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Matrix3x2.cs
Go to the documentation of this file.
3
4namespace System.Numerics;
5
6[Intrinsic]
7public struct Matrix3x2 : IEquatable<Matrix3x2>
8{
9 private static readonly Matrix3x2 _identity = new Matrix3x2(1f, 0f, 0f, 1f, 0f, 0f);
10
11 public float M11;
12
13 public float M12;
14
15 public float M21;
16
17 public float M22;
18
19 public float M31;
20
21 public float M32;
22
23 public static Matrix3x2 Identity => _identity;
24
25 public readonly bool IsIdentity => this == Identity;
26
28 {
29 readonly get
30 {
31 return new Vector2(M31, M32);
32 }
33 set
34 {
35 M31 = value.X;
36 M32 = value.Y;
37 }
38 }
39
40 public Matrix3x2(float m11, float m12, float m21, float m22, float m31, float m32)
41 {
42 M11 = m11;
43 M12 = m12;
44 M21 = m21;
45 M22 = m22;
46 M31 = m31;
47 M32 = m32;
48 }
49
50 public static Matrix3x2 operator +(Matrix3x2 value1, Matrix3x2 value2)
51 {
52 System.Runtime.CompilerServices.Unsafe.SkipInit(out Matrix3x2 result);
53 result.M11 = value1.M11 + value2.M11;
54 result.M12 = value1.M12 + value2.M12;
55 result.M21 = value1.M21 + value2.M21;
56 result.M22 = value1.M22 + value2.M22;
57 result.M31 = value1.M31 + value2.M31;
58 result.M32 = value1.M32 + value2.M32;
59 return result;
60 }
61
62 public static bool operator ==(Matrix3x2 value1, Matrix3x2 value2)
63 {
64 if (value1.M11 == value2.M11 && value1.M22 == value2.M22 && value1.M12 == value2.M12 && value1.M21 == value2.M21 && value1.M31 == value2.M31)
65 {
66 return value1.M32 == value2.M32;
67 }
68 return false;
69 }
70
71 public static bool operator !=(Matrix3x2 value1, Matrix3x2 value2)
72 {
73 return !(value1 == value2);
74 }
75
76 public static Matrix3x2 operator *(Matrix3x2 value1, Matrix3x2 value2)
77 {
78 System.Runtime.CompilerServices.Unsafe.SkipInit(out Matrix3x2 result);
79 result.M11 = value1.M11 * value2.M11 + value1.M12 * value2.M21;
80 result.M12 = value1.M11 * value2.M12 + value1.M12 * value2.M22;
81 result.M21 = value1.M21 * value2.M11 + value1.M22 * value2.M21;
82 result.M22 = value1.M21 * value2.M12 + value1.M22 * value2.M22;
83 result.M31 = value1.M31 * value2.M11 + value1.M32 * value2.M21 + value2.M31;
84 result.M32 = value1.M31 * value2.M12 + value1.M32 * value2.M22 + value2.M32;
85 return result;
86 }
87
88 public static Matrix3x2 operator *(Matrix3x2 value1, float value2)
89 {
90 System.Runtime.CompilerServices.Unsafe.SkipInit(out Matrix3x2 result);
91 result.M11 = value1.M11 * value2;
92 result.M12 = value1.M12 * value2;
93 result.M21 = value1.M21 * value2;
94 result.M22 = value1.M22 * value2;
95 result.M31 = value1.M31 * value2;
96 result.M32 = value1.M32 * value2;
97 return result;
98 }
99
100 public static Matrix3x2 operator -(Matrix3x2 value1, Matrix3x2 value2)
101 {
102 System.Runtime.CompilerServices.Unsafe.SkipInit(out Matrix3x2 result);
103 result.M11 = value1.M11 - value2.M11;
104 result.M12 = value1.M12 - value2.M12;
105 result.M21 = value1.M21 - value2.M21;
106 result.M22 = value1.M22 - value2.M22;
107 result.M31 = value1.M31 - value2.M31;
108 result.M32 = value1.M32 - value2.M32;
109 return result;
110 }
111
113 {
114 System.Runtime.CompilerServices.Unsafe.SkipInit(out Matrix3x2 result);
115 result.M11 = 0f - value.M11;
116 result.M12 = 0f - value.M12;
117 result.M21 = 0f - value.M21;
118 result.M22 = 0f - value.M22;
119 result.M31 = 0f - value.M31;
120 result.M32 = 0f - value.M32;
121 return result;
122 }
123
124 [MethodImpl(MethodImplOptions.AggressiveInlining)]
125 public static Matrix3x2 Add(Matrix3x2 value1, Matrix3x2 value2)
126 {
127 return value1 + value2;
128 }
129
130 public static Matrix3x2 CreateRotation(float radians)
131 {
132 radians = MathF.IEEERemainder(radians, (float)Math.PI * 2f);
133 float num;
134 float num2;
135 if (radians > -1.7453294E-05f && radians < 1.7453294E-05f)
136 {
137 num = 1f;
138 num2 = 0f;
139 }
140 else if (radians > 1.570779f && radians < 1.5708138f)
141 {
142 num = 0f;
143 num2 = 1f;
144 }
145 else if (radians < -3.1415753f || radians > 3.1415753f)
146 {
147 num = -1f;
148 num2 = 0f;
149 }
150 else if (radians > -1.5708138f && radians < -1.570779f)
151 {
152 num = 0f;
153 num2 = -1f;
154 }
155 else
156 {
157 num = MathF.Cos(radians);
158 num2 = MathF.Sin(radians);
159 }
160 Matrix3x2 identity = Identity;
161 identity.M11 = num;
162 identity.M12 = num2;
163 identity.M21 = 0f - num2;
164 identity.M22 = num;
165 return identity;
166 }
167
168 public static Matrix3x2 CreateRotation(float radians, Vector2 centerPoint)
169 {
170 radians = MathF.IEEERemainder(radians, (float)Math.PI * 2f);
171 float num;
172 float num2;
173 if (radians > -1.7453294E-05f && radians < 1.7453294E-05f)
174 {
175 num = 1f;
176 num2 = 0f;
177 }
178 else if (radians > 1.570779f && radians < 1.5708138f)
179 {
180 num = 0f;
181 num2 = 1f;
182 }
183 else if (radians < -3.1415753f || radians > 3.1415753f)
184 {
185 num = -1f;
186 num2 = 0f;
187 }
188 else if (radians > -1.5708138f && radians < -1.570779f)
189 {
190 num = 0f;
191 num2 = -1f;
192 }
193 else
194 {
195 num = MathF.Cos(radians);
196 num2 = MathF.Sin(radians);
197 }
198 float m = centerPoint.X * (1f - num) + centerPoint.Y * num2;
199 float m2 = centerPoint.Y * (1f - num) - centerPoint.X * num2;
200 System.Runtime.CompilerServices.Unsafe.SkipInit(out Matrix3x2 result);
201 result.M11 = num;
202 result.M12 = num2;
203 result.M21 = 0f - num2;
204 result.M22 = num;
205 result.M31 = m;
206 result.M32 = m2;
207 return result;
208 }
209
210 public static Matrix3x2 CreateScale(Vector2 scales)
211 {
212 Matrix3x2 identity = Identity;
213 identity.M11 = scales.X;
214 identity.M22 = scales.Y;
215 return identity;
216 }
217
218 public static Matrix3x2 CreateScale(float xScale, float yScale)
219 {
220 Matrix3x2 identity = Identity;
221 identity.M11 = xScale;
222 identity.M22 = yScale;
223 return identity;
224 }
225
226 public static Matrix3x2 CreateScale(float xScale, float yScale, Vector2 centerPoint)
227 {
228 Matrix3x2 identity = Identity;
229 float m = centerPoint.X * (1f - xScale);
230 float m2 = centerPoint.Y * (1f - yScale);
231 identity.M11 = xScale;
232 identity.M22 = yScale;
233 identity.M31 = m;
234 identity.M32 = m2;
235 return identity;
236 }
237
238 public static Matrix3x2 CreateScale(Vector2 scales, Vector2 centerPoint)
239 {
240 Matrix3x2 identity = Identity;
241 float m = centerPoint.X * (1f - scales.X);
242 float m2 = centerPoint.Y * (1f - scales.Y);
243 identity.M11 = scales.X;
244 identity.M22 = scales.Y;
245 identity.M31 = m;
246 identity.M32 = m2;
247 return identity;
248 }
249
250 public static Matrix3x2 CreateScale(float scale)
251 {
252 Matrix3x2 identity = Identity;
253 identity.M11 = scale;
254 identity.M22 = scale;
255 return identity;
256 }
257
258 public static Matrix3x2 CreateScale(float scale, Vector2 centerPoint)
259 {
260 Matrix3x2 identity = Identity;
261 float m = centerPoint.X * (1f - scale);
262 float m2 = centerPoint.Y * (1f - scale);
263 identity.M11 = scale;
264 identity.M22 = scale;
265 identity.M31 = m;
266 identity.M32 = m2;
267 return identity;
268 }
269
270 public static Matrix3x2 CreateSkew(float radiansX, float radiansY)
271 {
272 Matrix3x2 identity = Identity;
273 float m = MathF.Tan(radiansX);
274 float m2 = MathF.Tan(radiansY);
275 identity.M12 = m2;
276 identity.M21 = m;
277 return identity;
278 }
279
280 public static Matrix3x2 CreateSkew(float radiansX, float radiansY, Vector2 centerPoint)
281 {
282 Matrix3x2 identity = Identity;
283 float num = MathF.Tan(radiansX);
284 float num2 = MathF.Tan(radiansY);
285 float m = (0f - centerPoint.Y) * num;
286 float m2 = (0f - centerPoint.X) * num2;
287 identity.M12 = num2;
288 identity.M21 = num;
289 identity.M31 = m;
290 identity.M32 = m2;
291 return identity;
292 }
293
294 public static Matrix3x2 CreateTranslation(Vector2 position)
295 {
296 Matrix3x2 identity = Identity;
297 identity.M31 = position.X;
298 identity.M32 = position.Y;
299 return identity;
300 }
301
302 public static Matrix3x2 CreateTranslation(float xPosition, float yPosition)
303 {
304 Matrix3x2 identity = Identity;
305 identity.M31 = xPosition;
306 identity.M32 = yPosition;
307 return identity;
308 }
309
310 public static bool Invert(Matrix3x2 matrix, out Matrix3x2 result)
311 {
312 float num = matrix.M11 * matrix.M22 - matrix.M21 * matrix.M12;
313 if (MathF.Abs(num) < float.Epsilon)
314 {
315 result = new Matrix3x2(float.NaN, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN);
316 return false;
317 }
318 float num2 = 1f / num;
319 result.M11 = matrix.M22 * num2;
320 result.M12 = (0f - matrix.M12) * num2;
321 result.M21 = (0f - matrix.M21) * num2;
322 result.M22 = matrix.M11 * num2;
323 result.M31 = (matrix.M21 * matrix.M32 - matrix.M31 * matrix.M22) * num2;
324 result.M32 = (matrix.M31 * matrix.M12 - matrix.M11 * matrix.M32) * num2;
325 return true;
326 }
327
328 public static Matrix3x2 Lerp(Matrix3x2 matrix1, Matrix3x2 matrix2, float amount)
329 {
330 System.Runtime.CompilerServices.Unsafe.SkipInit(out Matrix3x2 result);
331 result.M11 = matrix1.M11 + (matrix2.M11 - matrix1.M11) * amount;
332 result.M12 = matrix1.M12 + (matrix2.M12 - matrix1.M12) * amount;
333 result.M21 = matrix1.M21 + (matrix2.M21 - matrix1.M21) * amount;
334 result.M22 = matrix1.M22 + (matrix2.M22 - matrix1.M22) * amount;
335 result.M31 = matrix1.M31 + (matrix2.M31 - matrix1.M31) * amount;
336 result.M32 = matrix1.M32 + (matrix2.M32 - matrix1.M32) * amount;
337 return result;
338 }
339
340 [MethodImpl(MethodImplOptions.AggressiveInlining)]
341 public static Matrix3x2 Multiply(Matrix3x2 value1, Matrix3x2 value2)
342 {
343 return value1 * value2;
344 }
345
346 [MethodImpl(MethodImplOptions.AggressiveInlining)]
347 public static Matrix3x2 Multiply(Matrix3x2 value1, float value2)
348 {
349 return value1 * value2;
350 }
351
352 [MethodImpl(MethodImplOptions.AggressiveInlining)]
354 {
355 return -value;
356 }
357
358 [MethodImpl(MethodImplOptions.AggressiveInlining)]
359 public static Matrix3x2 Subtract(Matrix3x2 value1, Matrix3x2 value2)
360 {
361 return value1 - value2;
362 }
363
364 [MethodImpl(MethodImplOptions.AggressiveInlining)]
365 public override readonly bool Equals([NotNullWhen(true)] object? obj)
366 {
367 if (obj is Matrix3x2 other)
368 {
369 return Equals(other);
370 }
371 return false;
372 }
373
374 public readonly bool Equals(Matrix3x2 other)
375 {
376 return this == other;
377 }
378
379 public readonly float GetDeterminant()
380 {
381 return M11 * M22 - M21 * M12;
382 }
383
384 public override readonly int GetHashCode()
385 {
386 return HashCode.Combine(M11, M12, M21, M22, M31, M32);
387 }
388
389 public override readonly string ToString()
390 {
391 return $"{{ {{M11:{M11} M12:{M12}}} {{M21:{M21} M22:{M22}}} {{M31:{M31} M32:{M32}}} }}";
392 }
393}
static float Abs(float x)
Definition MathF.cs:130
static float Cos(float x)
static float IEEERemainder(float x, float y)
Definition MathF.cs:191
static float Sin(float x)
static float Tan(float x)
const double PI
Definition Math.cs:16
readonly float GetDeterminant()
Definition Matrix3x2.cs:379
static readonly Matrix3x2 _identity
Definition Matrix3x2.cs:9
static Matrix3x2 Subtract(Matrix3x2 value1, Matrix3x2 value2)
Definition Matrix3x2.cs:359
static Matrix3x2 CreateTranslation(Vector2 position)
Definition Matrix3x2.cs:294
readonly bool Equals(Matrix3x2 other)
Definition Matrix3x2.cs:374
static Matrix3x2 CreateTranslation(float xPosition, float yPosition)
Definition Matrix3x2.cs:302
static bool operator==(Matrix3x2 value1, Matrix3x2 value2)
Definition Matrix3x2.cs:62
static Matrix3x2 CreateRotation(float radians)
Definition Matrix3x2.cs:130
Matrix3x2(float m11, float m12, float m21, float m22, float m31, float m32)
Definition Matrix3x2.cs:40
static Matrix3x2 Multiply(Matrix3x2 value1, Matrix3x2 value2)
Definition Matrix3x2.cs:341
static Matrix3x2 CreateRotation(float radians, Vector2 centerPoint)
Definition Matrix3x2.cs:168
override readonly int GetHashCode()
Definition Matrix3x2.cs:384
static Matrix3x2 Identity
Definition Matrix3x2.cs:23
override readonly string ToString()
Definition Matrix3x2.cs:389
static Matrix3x2 CreateScale(float xScale, float yScale, Vector2 centerPoint)
Definition Matrix3x2.cs:226
static Matrix3x2 CreateSkew(float radiansX, float radiansY, Vector2 centerPoint)
Definition Matrix3x2.cs:280
static Matrix3x2 CreateScale(float scale)
Definition Matrix3x2.cs:250
static bool operator!=(Matrix3x2 value1, Matrix3x2 value2)
Definition Matrix3x2.cs:71
static Matrix3x2 CreateScale(Vector2 scales)
Definition Matrix3x2.cs:210
static Matrix3x2 CreateScale(Vector2 scales, Vector2 centerPoint)
Definition Matrix3x2.cs:238
static bool Invert(Matrix3x2 matrix, out Matrix3x2 result)
Definition Matrix3x2.cs:310
static Matrix3x2 operator+(Matrix3x2 value1, Matrix3x2 value2)
Definition Matrix3x2.cs:50
override readonly bool Equals([NotNullWhen(true)] object? obj)
Definition Matrix3x2.cs:365
static Matrix3x2 CreateScale(float scale, Vector2 centerPoint)
Definition Matrix3x2.cs:258
static Matrix3x2 CreateScale(float xScale, float yScale)
Definition Matrix3x2.cs:218
static Matrix3x2 Multiply(Matrix3x2 value1, float value2)
Definition Matrix3x2.cs:347
readonly bool IsIdentity
Definition Matrix3x2.cs:25
static Matrix3x2 Lerp(Matrix3x2 matrix1, Matrix3x2 matrix2, float amount)
Definition Matrix3x2.cs:328
static Matrix3x2 Add(Matrix3x2 value1, Matrix3x2 value2)
Definition Matrix3x2.cs:125
static Matrix3x2 Negate(Matrix3x2 value)
Definition Matrix3x2.cs:353
static Matrix3x2 CreateSkew(float radiansX, float radiansY)
Definition Matrix3x2.cs:270
static Matrix3x2 operator*(Matrix3x2 value1, Matrix3x2 value2)
Definition Matrix3x2.cs:76
static Matrix3x2 operator-(Matrix3x2 value1, Matrix3x2 value2)
Definition Matrix3x2.cs:100