Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Int4.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under MIT License. See LICENSE.md for details.
3 //
4 // Copyright (c) 2010-2011 SharpDX - Alexandre Mutel
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 // THE SOFTWARE.
23 using System;
24 using System.Globalization;
25 using System.Runtime.InteropServices;
26 
27 namespace SiliconStudio.Core.Mathematics
28 {
29  /// <summary>
30  /// Represents a four dimensional mathematical vector.
31  /// </summary>
32  [DataContract("Int4")]
33  [DataStyle(DataStyle.Compact)]
34  [StructLayout(LayoutKind.Sequential, Pack = 4)]
35  public struct Int4 : IEquatable<Int4>, IFormattable
36  {
37  /// <summary>
38  /// The size of the <see cref = "Int4" /> type, in bytes.
39  /// </summary>
40  public static readonly int SizeInBytes = Marshal.SizeOf(typeof (Int4));
41 
42  /// <summary>
43  /// A <see cref = "Int4" /> with all of its components set to zero.
44  /// </summary>
45  public static readonly Int4 Zero = new Int4();
46 
47  /// <summary>
48  /// The X unit <see cref = "Int4" /> (1, 0, 0, 0).
49  /// </summary>
50  public static readonly Int4 UnitX = new Int4(1, 0, 0, 0);
51 
52  /// <summary>
53  /// The Y unit <see cref = "Int4" /> (0, 1, 0, 0).
54  /// </summary>
55  public static readonly Int4 UnitY = new Int4(0, 1, 0, 0);
56 
57  /// <summary>
58  /// The Z unit <see cref = "Int4" /> (0, 0, 1, 0).
59  /// </summary>
60  public static readonly Int4 UnitZ = new Int4(0, 0, 1, 0);
61 
62  /// <summary>
63  /// The W unit <see cref = "Int4" /> (0, 0, 0, 1).
64  /// </summary>
65  public static readonly Int4 UnitW = new Int4(0, 0, 0, 1);
66 
67  /// <summary>
68  /// A <see cref = "Int4" /> with all of its components set to one.
69  /// </summary>
70  public static readonly Int4 One = new Int4(1, 1, 1, 1);
71 
72  /// <summary>
73  /// The X component of the vector.
74  /// </summary>
75  [DataMember(0)]
76  public int X;
77 
78  /// <summary>
79  /// The Y component of the vector.
80  /// </summary>
81  [DataMember(1)]
82  public int Y;
83 
84  /// <summary>
85  /// The Z component of the vector.
86  /// </summary>
87  [DataMember(2)]
88  public int Z;
89 
90  /// <summary>
91  /// The W component of the vector.
92  /// </summary>
93  [DataMember(3)]
94  public int W;
95 
96 
97  /// <summary>
98  /// Initializes a new instance of the <see cref = "Int4" /> struct.
99  /// </summary>
100  /// <param name = "value">The value that will be assigned to all components.</param>
101  public Int4(int value)
102  {
103  X = value;
104  Y = value;
105  Z = value;
106  W = value;
107  }
108 
109  /// <summary>
110  /// Initializes a new instance of the <see cref = "Int4" /> struct.
111  /// </summary>
112  /// <param name = "x">Initial value for the X component of the vector.</param>
113  /// <param name = "y">Initial value for the Y component of the vector.</param>
114  /// <param name = "z">Initial value for the Z component of the vector.</param>
115  /// <param name = "w">Initial value for the W component of the vector.</param>
116  public Int4(int x, int y, int z, int w)
117  {
118  X = x;
119  Y = y;
120  Z = z;
121  W = w;
122  }
123 
124 
125  /// <summary>
126  /// Initializes a new instance of the <see cref = "Int4" /> struct.
127  /// </summary>
128  /// <param name = "values">The values to assign to the X, Y, Z, and W components of the vector. This must be an array with four elements.</param>
129  /// <exception cref = "ArgumentNullException">Thrown when <paramref name = "values" /> is <c>null</c>.</exception>
130  /// <exception cref = "ArgumentOutOfRangeException">Thrown when <paramref name = "values" /> contains more or less than four elements.</exception>
131  public Int4(int[] values)
132  {
133  if (values == null)
134  throw new ArgumentNullException("values");
135  if (values.Length != 4)
136  throw new ArgumentOutOfRangeException("values",
137  "There must be four and only four input values for Int4.");
138 
139  X = values[0];
140  Y = values[1];
141  Z = values[2];
142  W = values[3];
143  }
144 
145  /// <summary>
146  /// Gets or sets the component at the specified index.
147  /// </summary>
148  /// <value>The value of the X, Y, Z, or W component, depending on the index.</value>
149  /// <param name = "index">The index of the component to access. Use 0 for the X component, 1 for the Y component, 2 for the Z component, and 3 for the W component.</param>
150  /// <returns>The value of the component at the specified index.</returns>
151  /// <exception cref = "System.ArgumentOutOfRangeException">Thrown when the <paramref name = "index" /> is out of the range [0, 3].</exception>
152  public int this[int index]
153  {
154  get
155  {
156  switch (index)
157  {
158  case 0:
159  return X;
160  case 1:
161  return Y;
162  case 2:
163  return Z;
164  case 3:
165  return W;
166  }
167 
168  throw new ArgumentOutOfRangeException("index", "Indices for Int4 run from 0 to 3, inclusive.");
169  }
170 
171  set
172  {
173  switch (index)
174  {
175  case 0:
176  X = value;
177  break;
178  case 1:
179  Y = value;
180  break;
181  case 2:
182  Z = value;
183  break;
184  case 3:
185  W = value;
186  break;
187  default:
188  throw new ArgumentOutOfRangeException("index", "Indices for Int4 run from 0 to 3, inclusive.");
189  }
190  }
191  }
192 
193  /// <summary>
194  /// Creates an array containing the elements of the vector.
195  /// </summary>
196  /// <returns>A four-element array containing the components of the vector.</returns>
197  public int[] ToArray()
198  {
199  return new int[] {X, Y, Z, W};
200  }
201 
202  /// <summary>
203  /// Adds two vectors.
204  /// </summary>
205  /// <param name = "left">The first vector to add.</param>
206  /// <param name = "right">The second vector to add.</param>
207  /// <param name = "result">When the method completes, contains the sum of the two vectors.</param>
208  public static void Add(ref Int4 left, ref Int4 right, out Int4 result)
209  {
210  result = new Int4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W);
211  }
212 
213  /// <summary>
214  /// Adds two vectors.
215  /// </summary>
216  /// <param name = "left">The first vector to add.</param>
217  /// <param name = "right">The second vector to add.</param>
218  /// <returns>The sum of the two vectors.</returns>
219  public static Int4 Add(Int4 left, Int4 right)
220  {
221  return new Int4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W);
222  }
223 
224  /// <summary>
225  /// Subtracts two vectors.
226  /// </summary>
227  /// <param name = "left">The first vector to subtract.</param>
228  /// <param name = "right">The second vector to subtract.</param>
229  /// <param name = "result">When the method completes, contains the difference of the two vectors.</param>
230  public static void Subtract(ref Int4 left, ref Int4 right, out Int4 result)
231  {
232  result = new Int4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W);
233  }
234 
235  /// <summary>
236  /// Subtracts two vectors.
237  /// </summary>
238  /// <param name = "left">The first vector to subtract.</param>
239  /// <param name = "right">The second vector to subtract.</param>
240  /// <returns>The difference of the two vectors.</returns>
241  public static Int4 Subtract(Int4 left, Int4 right)
242  {
243  return new Int4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W);
244  }
245 
246  /// <summary>
247  /// Scales a vector by the given value.
248  /// </summary>
249  /// <param name = "value">The vector to scale.</param>
250  /// <param name = "scale">The amount by which to scale the vector.</param>
251  /// <param name = "result">When the method completes, contains the scaled vector.</param>
252  public static void Multiply(ref Int4 value, int scale, out Int4 result)
253  {
254  result = new Int4(value.X*scale, value.Y*scale, value.Z*scale, value.W*scale);
255  }
256 
257  /// <summary>
258  /// Scales a vector by the given value.
259  /// </summary>
260  /// <param name = "value">The vector to scale.</param>
261  /// <param name = "scale">The amount by which to scale the vector.</param>
262  /// <returns>The scaled vector.</returns>
263  public static Int4 Multiply(Int4 value, int scale)
264  {
265  return new Int4(value.X*scale, value.Y*scale, value.Z*scale, value.W*scale);
266  }
267 
268  /// <summary>
269  /// Modulates a vector with another by performing component-wise multiplication.
270  /// </summary>
271  /// <param name = "left">The first vector to modulate.</param>
272  /// <param name = "right">The second vector to modulate.</param>
273  /// <param name = "result">When the method completes, contains the modulated vector.</param>
274  public static void Modulate(ref Int4 left, ref Int4 right, out Int4 result)
275  {
276  result = new Int4(left.X*right.X, left.Y*right.Y, left.Z*right.Z, left.W*right.W);
277  }
278 
279  /// <summary>
280  /// Modulates a vector with another by performing component-wise multiplication.
281  /// </summary>
282  /// <param name = "left">The first vector to modulate.</param>
283  /// <param name = "right">The second vector to modulate.</param>
284  /// <returns>The modulated vector.</returns>
285  public static Int4 Modulate(Int4 left, Int4 right)
286  {
287  return new Int4(left.X*right.X, left.Y*right.Y, left.Z*right.Z, left.W*right.W);
288  }
289 
290  /// <summary>
291  /// Scales a vector by the given value.
292  /// </summary>
293  /// <param name = "value">The vector to scale.</param>
294  /// <param name = "scale">The amount by which to scale the vector.</param>
295  /// <param name = "result">When the method completes, contains the scaled vector.</param>
296  public static void Divide(ref Int4 value, int scale, out Int4 result)
297  {
298  result = new Int4(value.X/scale, value.Y/scale, value.Z/scale, value.W/scale);
299  }
300 
301  /// <summary>
302  /// Scales a vector by the given value.
303  /// </summary>
304  /// <param name = "value">The vector to scale.</param>
305  /// <param name = "scale">The amount by which to scale the vector.</param>
306  /// <returns>The scaled vector.</returns>
307  public static Int4 Divide(Int4 value, int scale)
308  {
309  return new Int4(value.X/scale, value.Y/scale, value.Z/scale, value.W/scale);
310  }
311 
312  /// <summary>
313  /// Reverses the direction of a given vector.
314  /// </summary>
315  /// <param name = "value">The vector to negate.</param>
316  /// <param name = "result">When the method completes, contains a vector facing in the opposite direction.</param>
317  public static void Negate(ref Int4 value, out Int4 result)
318  {
319  result = new Int4(-value.X, -value.Y, -value.Z, -value.W);
320  }
321 
322  /// <summary>
323  /// Reverses the direction of a given vector.
324  /// </summary>
325  /// <param name = "value">The vector to negate.</param>
326  /// <returns>A vector facing in the opposite direction.</returns>
327  public static Int4 Negate(Int4 value)
328  {
329  return new Int4(-value.X, -value.Y, -value.Z, -value.W);
330  }
331 
332  /// <summary>
333  /// Restricts a value to be within a specified range.
334  /// </summary>
335  /// <param name = "value">The value to clamp.</param>
336  /// <param name = "min">The minimum value.</param>
337  /// <param name = "max">The maximum value.</param>
338  /// <param name = "result">When the method completes, contains the clamped value.</param>
339  public static void Clamp(ref Int4 value, ref Int4 min, ref Int4 max, out Int4 result)
340  {
341  int x = value.X;
342  x = (x > max.X) ? max.X : x;
343  x = (x < min.X) ? min.X : x;
344 
345  int y = value.Y;
346  y = (y > max.Y) ? max.Y : y;
347  y = (y < min.Y) ? min.Y : y;
348 
349  int z = value.Z;
350  z = (z > max.Z) ? max.Z : z;
351  z = (z < min.Z) ? min.Z : z;
352 
353  int w = value.W;
354  w = (w > max.W) ? max.W : w;
355  w = (w < min.W) ? min.W : w;
356 
357  result = new Int4(x, y, z, w);
358  }
359 
360  /// <summary>
361  /// Restricts a value to be within a specified range.
362  /// </summary>
363  /// <param name = "value">The value to clamp.</param>
364  /// <param name = "min">The minimum value.</param>
365  /// <param name = "max">The maximum value.</param>
366  /// <returns>The clamped value.</returns>
367  public static Int4 Clamp(Int4 value, Int4 min, Int4 max)
368  {
369  Int4 result;
370  Clamp(ref value, ref min, ref max, out result);
371  return result;
372  }
373 
374  /// <summary>
375  /// Returns a vector containing the smallest components of the specified vectors.
376  /// </summary>
377  /// <param name = "left">The first source vector.</param>
378  /// <param name = "right">The second source vector.</param>
379  /// <param name = "result">When the method completes, contains an new vector composed of the largest components of the source vectors.</param>
380  public static void Max(ref Int4 left, ref Int4 right, out Int4 result)
381  {
382  result.X = (left.X > right.X) ? left.X : right.X;
383  result.Y = (left.Y > right.Y) ? left.Y : right.Y;
384  result.Z = (left.Z > right.Z) ? left.Z : right.Z;
385  result.W = (left.W > right.W) ? left.W : right.W;
386  }
387 
388  /// <summary>
389  /// Returns a vector containing the largest components of the specified vectors.
390  /// </summary>
391  /// <param name = "left">The first source vector.</param>
392  /// <param name = "right">The second source vector.</param>
393  /// <returns>A vector containing the largest components of the source vectors.</returns>
394  public static Int4 Max(Int4 left, Int4 right)
395  {
396  Int4 result;
397  Max(ref left, ref right, out result);
398  return result;
399  }
400 
401  /// <summary>
402  /// Returns a vector containing the smallest components of the specified vectors.
403  /// </summary>
404  /// <param name = "left">The first source vector.</param>
405  /// <param name = "right">The second source vector.</param>
406  /// <param name = "result">When the method completes, contains an new vector composed of the smallest components of the source vectors.</param>
407  public static void Min(ref Int4 left, ref Int4 right, out Int4 result)
408  {
409  result.X = (left.X < right.X) ? left.X : right.X;
410  result.Y = (left.Y < right.Y) ? left.Y : right.Y;
411  result.Z = (left.Z < right.Z) ? left.Z : right.Z;
412  result.W = (left.W < right.W) ? left.W : right.W;
413  }
414 
415  /// <summary>
416  /// Returns a vector containing the smallest components of the specified vectors.
417  /// </summary>
418  /// <param name = "left">The first source vector.</param>
419  /// <param name = "right">The second source vector.</param>
420  /// <returns>A vector containing the smallest components of the source vectors.</returns>
421  public static Int4 Min(Int4 left, Int4 right)
422  {
423  Int4 result;
424  Min(ref left, ref right, out result);
425  return result;
426  }
427 
428  /// <summary>
429  /// Adds two vectors.
430  /// </summary>
431  /// <param name = "left">The first vector to add.</param>
432  /// <param name = "right">The second vector to add.</param>
433  /// <returns>The sum of the two vectors.</returns>
434  public static Int4 operator +(Int4 left, Int4 right)
435  {
436  return new Int4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W);
437  }
438 
439  /// <summary>
440  /// Assert a vector (return it unchanged).
441  /// </summary>
442  /// <param name = "value">The vector to assert (unchange).</param>
443  /// <returns>The asserted (unchanged) vector.</returns>
444  public static Int4 operator +(Int4 value)
445  {
446  return value;
447  }
448 
449  /// <summary>
450  /// Subtracts two vectors.
451  /// </summary>
452  /// <param name = "left">The first vector to subtract.</param>
453  /// <param name = "right">The second vector to subtract.</param>
454  /// <returns>The difference of the two vectors.</returns>
455  public static Int4 operator -(Int4 left, Int4 right)
456  {
457  return new Int4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W);
458  }
459 
460  /// <summary>
461  /// Reverses the direction of a given vector.
462  /// </summary>
463  /// <param name = "value">The vector to negate.</param>
464  /// <returns>A vector facing in the opposite direction.</returns>
465  public static Int4 operator -(Int4 value)
466  {
467  return new Int4(-value.X, -value.Y, -value.Z, -value.W);
468  }
469 
470  /// <summary>
471  /// Scales a vector by the given value.
472  /// </summary>
473  /// <param name = "value">The vector to scale.</param>
474  /// <param name = "scale">The amount by which to scale the vector.</param>
475  /// <returns>The scaled vector.</returns>
476  public static Int4 operator *(int scale, Int4 value)
477  {
478  return new Int4(value.X*scale, value.Y*scale, value.Z*scale, value.W*scale);
479  }
480 
481  /// <summary>
482  /// Scales a vector by the given value.
483  /// </summary>
484  /// <param name = "value">The vector to scale.</param>
485  /// <param name = "scale">The amount by which to scale the vector.</param>
486  /// <returns>The scaled vector.</returns>
487  public static Int4 operator *(Int4 value, int scale)
488  {
489  return new Int4(value.X*scale, value.Y*scale, value.Z*scale, value.W*scale);
490  }
491 
492  /// <summary>
493  /// Scales a vector by the given value.
494  /// </summary>
495  /// <param name = "value">The vector to scale.</param>
496  /// <param name = "scale">The amount by which to scale the vector.</param>
497  /// <returns>The scaled vector.</returns>
498  public static Int4 operator /(Int4 value, int scale)
499  {
500  return new Int4(value.X/scale, value.Y/scale, value.Z/scale, value.W/scale);
501  }
502 
503  /// <summary>
504  /// Tests for equality between two objects.
505  /// </summary>
506  /// <param name = "left">The first value to compare.</param>
507  /// <param name = "right">The second value to compare.</param>
508  /// <returns><c>true</c> if <paramref name = "left" /> has the same value as <paramref name = "right" />; otherwise, <c>false</c>.</returns>
509  public static bool operator ==(Int4 left, Int4 right)
510  {
511  return left.Equals(right);
512  }
513 
514  /// <summary>
515  /// Tests for inequality between two objects.
516  /// </summary>
517  /// <param name = "left">The first value to compare.</param>
518  /// <param name = "right">The second value to compare.</param>
519  /// <returns><c>true</c> if <paramref name = "left" /> has a different value than <paramref name = "right" />; otherwise, <c>false</c>.</returns>
520  public static bool operator !=(Int4 left, Int4 right)
521  {
522  return !left.Equals(right);
523  }
524 
525  /// <summary>
526  /// Performs an explicit conversion from <see cref = "Int4" /> to <see cref = "Vector2" />.
527  /// </summary>
528  /// <param name = "value">The value.</param>
529  /// <returns>The result of the conversion.</returns>
530  public static explicit operator Vector2(Int4 value)
531  {
532  return new Vector2(value.X, value.Y);
533  }
534 
535  /// <summary>
536  /// Performs an explicit conversion from <see cref = "Int4" /> to <see cref = "Vector3" />.
537  /// </summary>
538  /// <param name = "value">The value.</param>
539  /// <returns>The result of the conversion.</returns>
540  public static explicit operator Vector3(Int4 value)
541  {
542  return new Vector3(value.X, value.Y, value.Z);
543  }
544 
545  /// <summary>
546  /// Performs an explicit conversion from <see cref = "Int4" /> to <see cref = "Vector4" />.
547  /// </summary>
548  /// <param name = "value">The value.</param>
549  /// <returns>The result of the conversion.</returns>
550  public static explicit operator Vector4(Int4 value)
551  {
552  return new Vector4(value.X, value.Y, value.Z, value.W);
553  }
554 
555  /// <summary>
556  /// Returns a <see cref = "System.String" /> that represents this instance.
557  /// </summary>
558  /// <returns>
559  /// A <see cref = "System.String" /> that represents this instance.
560  /// </returns>
561  public override string ToString()
562  {
563  return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W);
564  }
565 
566  /// <summary>
567  /// Returns a <see cref = "System.String" /> that represents this instance.
568  /// </summary>
569  /// <param name = "format">The format.</param>
570  /// <returns>
571  /// A <see cref = "System.String" /> that represents this instance.
572  /// </returns>
573  public string ToString(string format)
574  {
575  if (format == null)
576  return ToString();
577 
578  return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}",
579  X.ToString(format, CultureInfo.CurrentCulture),
580  Y.ToString(format, CultureInfo.CurrentCulture),
581  Z.ToString(format, CultureInfo.CurrentCulture),
582  W.ToString(format, CultureInfo.CurrentCulture));
583  }
584 
585  /// <summary>
586  /// Returns a <see cref = "System.String" /> that represents this instance.
587  /// </summary>
588  /// <param name = "formatProvider">The format provider.</param>
589  /// <returns>
590  /// A <see cref = "System.String" /> that represents this instance.
591  /// </returns>
592  public string ToString(IFormatProvider formatProvider)
593  {
594  return string.Format(formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W);
595  }
596 
597  /// <summary>
598  /// Returns a <see cref = "System.String" /> that represents this instance.
599  /// </summary>
600  /// <param name = "format">The format.</param>
601  /// <param name = "formatProvider">The format provider.</param>
602  /// <returns>
603  /// A <see cref = "System.String" /> that represents this instance.
604  /// </returns>
605  public string ToString(string format, IFormatProvider formatProvider)
606  {
607  if (format == null)
608  ToString(formatProvider);
609 
610  return string.Format(formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X.ToString(format, formatProvider),
611  Y.ToString(format, formatProvider), Z.ToString(format, formatProvider),
612  W.ToString(format, formatProvider));
613  }
614 
615  /// <summary>
616  /// Returns a hash code for this instance.
617  /// </summary>
618  /// <returns>
619  /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
620  /// </returns>
621  public override int GetHashCode()
622  {
623  return X.GetHashCode() + Y.GetHashCode() + Z.GetHashCode() + W.GetHashCode();
624  }
625 
626  /// <summary>
627  /// Determines whether the specified <see cref = "Int4" /> is equal to this instance.
628  /// </summary>
629  /// <param name = "other">The <see cref = "Int4" /> to compare with this instance.</param>
630  /// <returns>
631  /// <c>true</c> if the specified <see cref = "Int4" /> is equal to this instance; otherwise, <c>false</c>.
632  /// </returns>
633  public bool Equals(Int4 other)
634  {
635  return other.X == X && other.Y == Y && other.Z == Z && other.W == W;
636  }
637 
638  /// <summary>
639  /// Determines whether the specified <see cref = "System.Object" /> is equal to this instance.
640  /// </summary>
641  /// <param name = "value">The <see cref = "System.Object" /> to compare with this instance.</param>
642  /// <returns>
643  /// <c>true</c> if the specified <see cref = "System.Object" /> is equal to this instance; otherwise, <c>false</c>.
644  /// </returns>
645  public override bool Equals(object value)
646  {
647  if (value == null)
648  return false;
649 
650  if (value.GetType() != GetType())
651  return false;
652 
653  return Equals((Int4) value);
654  }
655 
656  /// <summary>
657  /// Performs an implicit conversion from <see cref="int"/> array to <see cref="SiliconStudio.Core.Mathematics.Int4"/>.
658  /// </summary>
659  /// <param name="input">The input.</param>
660  /// <returns>The result of the conversion.</returns>
661  public static implicit operator Int4(int[] input)
662  {
663  return new Int4(input);
664  }
665 
666  /// <summary>
667  /// Performs an implicit conversion from <see cref="SiliconStudio.Core.Mathematics.Int4"/> to <see cref="System.Int32"/> array.
668  /// </summary>
669  /// <param name="input">The input.</param>
670  /// <returns>The result of the conversion.</returns>
671  public static implicit operator int[](Int4 input)
672  {
673  return input.ToArray();
674  }
675  }
676 }
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
FbxDouble3 operator*(double factor, FbxDouble3 vector)
bool Equals(Int4 other)
Determines whether the specified Int4 is equal to this instance.
Definition: Int4.cs:633
static void Clamp(ref Int4 value, ref Int4 min, ref Int4 max, out Int4 result)
Restricts a value to be within a specified range.
Definition: Int4.cs:339
static Int4 Clamp(Int4 value, Int4 min, Int4 max)
Restricts a value to be within a specified range.
Definition: Int4.cs:367
Int4(int x, int y, int z, int w)
Initializes a new instance of the Int4 struct.
Definition: Int4.cs:116
string ToString(IFormatProvider formatProvider)
Returns a System.String that represents this instance.
Definition: Int4.cs:592
Int4(int[] values)
Initializes a new instance of the Int4 struct.
Definition: Int4.cs:131
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
Definition: DirectXTexP.h:191
static void Subtract(ref Int4 left, ref Int4 right, out Int4 result)
Subtracts two vectors.
Definition: Int4.cs:230
static Int4 Divide(Int4 value, int scale)
Scales a vector by the given value.
Definition: Int4.cs:307
static void Modulate(ref Int4 left, ref Int4 right, out Int4 result)
Modulates a vector with another by performing component-wise multiplication.
Definition: Int4.cs:274
static void Multiply(ref Int4 value, int scale, out Int4 result)
Scales a vector by the given value.
Definition: Int4.cs:252
static void Min(ref Int4 left, ref Int4 right, out Int4 result)
Returns a vector containing the smallest components of the specified vectors.
Definition: Int4.cs:407
static Int4 Max(Int4 left, Int4 right)
Returns a vector containing the largest components of the specified vectors.
Definition: Int4.cs:394
static void Negate(ref Int4 value, out Int4 result)
Reverses the direction of a given vector.
Definition: Int4.cs:317
override bool Equals(object value)
Determines whether the specified System.Object is equal to this instance.
Definition: Int4.cs:645
Represents a four dimensional mathematical vector.
Definition: Vector4.cs:42
static void Divide(ref Int4 value, int scale, out Int4 result)
Scales a vector by the given value.
Definition: Int4.cs:296
static Int4 Min(Int4 left, Int4 right)
Returns a vector containing the smallest components of the specified vectors.
Definition: Int4.cs:421
static Int4 Negate(Int4 value)
Reverses the direction of a given vector.
Definition: Int4.cs:327
Represents a four dimensional mathematical vector.
Definition: Int4.cs:35
static Int4 Add(Int4 left, Int4 right)
Adds two vectors.
Definition: Int4.cs:219
override int GetHashCode()
Returns a hash code for this instance.
Definition: Int4.cs:621
static void Add(ref Int4 left, ref Int4 right, out Int4 result)
Adds two vectors.
Definition: Int4.cs:208
int Y
The Y component of the vector.
Definition: Int4.cs:82
int X
The X component of the vector.
Definition: Int4.cs:76
string ToString(string format)
Returns a System.String that represents this instance.
Definition: Int4.cs:573
string ToString(string format, IFormatProvider formatProvider)
Returns a System.String that represents this instance.
Definition: Int4.cs:605
SiliconStudio.Core.Mathematics.Vector3 Vector3
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
Definition: DirectXTexP.h:175
static void Max(ref Int4 left, ref Int4 right, out Int4 result)
Returns a vector containing the smallest components of the specified vectors.
Definition: Int4.cs:380
int[] ToArray()
Creates an array containing the elements of the vector.
Definition: Int4.cs:197
Int4(int value)
Initializes a new instance of the Int4 struct.
Definition: Int4.cs:101
override string ToString()
Returns a System.String that represents this instance.
Definition: Int4.cs:561
static Int4 Multiply(Int4 value, int scale)
Scales a vector by the given value.
Definition: Int4.cs:263
static Int4 Subtract(Int4 left, Int4 right)
Subtracts two vectors.
Definition: Int4.cs:241
int Z
The Z component of the vector.
Definition: Int4.cs:88
int W
The W component of the vector.
Definition: Int4.cs:94
static Int4 Modulate(Int4 left, Int4 right)
Modulates a vector with another by performing component-wise multiplication.
Definition: Int4.cs:285
DataStyle
Specifies the style used for textual serialization when an array/list or a dictionary/map must be ser...
Definition: DataStyle.cs:9
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t size_t z
Definition: DirectXTexP.h:191