30 using System.Globalization;
31 using System.Runtime.InteropServices;
33 namespace SiliconStudio.Core.Mathematics
38 [DataContract(
"Int2")]
40 [StructLayout(LayoutKind.Sequential, Pack = 4)]
46 public static readonly
int SizeInBytes = Marshal.SizeOf(typeof(
Int2));
56 public static readonly
Int2 UnitX =
new Int2(1, 0);
61 public static readonly
Int2 UnitY =
new Int2(0, 1);
66 public static readonly
Int2 One =
new Int2(1, 1);
120 throw new ArgumentNullException(
"values");
121 if (values.Length != 2)
122 throw new ArgumentOutOfRangeException(
"values",
"There must be two and only two input values for Int2.");
131 public bool IsNormalized
143 public int this[
int index]
153 throw new ArgumentOutOfRangeException(
"index",
"Indices for Int2 run from 0 to 1, inclusive.");
160 case 0: X = value;
break;
161 case 1: Y = value;
break;
162 default:
throw new ArgumentOutOfRangeException(
"index",
"Indices for Int2 run from 0 to 1, inclusive.");
177 return (
int)Math.Sqrt((X * X) + (Y * Y));
190 return (X * X) + (Y * Y);
198 int length = Length();
201 int inv = 1 / length;
211 public void Pow(
int exponent)
213 X = (int)Math.Pow(X, exponent);
214 Y = (int)Math.Pow(Y, exponent);
223 return new int[] { X, Y };
234 result =
new Int2(left.X + right.X, left.Y + right.Y);
245 return new Int2(left.
X + right.
X, left.
Y + right.
Y);
256 result =
new Int2(left.X - right.X, left.Y - right.Y);
267 return new Int2(left.
X - right.
X, left.
Y - right.
Y);
278 result =
new Int2(value.X * scale, value.Y * scale);
289 return new Int2(value.
X * scale, value.
Y * scale);
300 result =
new Int2(left.X * right.X, left.Y * right.Y);
311 return new Int2(left.
X * right.
X, left.
Y * right.
Y);
322 result =
new Int2(value.X / scale, value.Y / scale);
333 return new Int2(value.
X / scale, value.
Y / scale);
343 result =
new Int2(-value.X, -value.Y);
353 return new Int2(-value.
X, -value.
Y);
366 x = (x > max.X) ? max.X : x;
367 x = (x < min.X) ? min.X : x;
370 y = (y > max.Y) ? max.Y : y;
371 y = (y < min.Y) ? min.Y :
y;
373 result =
new Int2(x, y);
386 Clamp(ref value, ref min, ref max, out result);
396 public static void Dot(ref
Int2 left, ref
Int2 right, out
int result)
398 result = (left.X * right.X) + (left.Y * right.Y);
409 return (left.
X * right.
X) + (left.Y * right.Y);
448 result.X = (int)(start.X + ((end.X - start.X) * amount));
449 result.Y = (int)(start.Y + ((end.Y - start.Y) * amount));
467 Lerp(ref start, ref end, amount, out result);
480 amount = (amount > 1) ? 1 : ((amount < 0) ? 0 : amount);
481 amount = (amount * amount) * (3 - (2 * amount));
483 result.X = (int)(start.X + ((end.X - start.X) * amount));
484 result.Y = (int)(start.Y + ((end.Y - start.Y) * amount));
497 SmoothStep(ref start, ref end, amount, out result);
509 result.X = (left.X > right.X) ? left.X : right.X;
510 result.Y = (left.Y > right.Y) ? left.Y : right.Y;
522 Max(ref left, ref right, out result);
534 result.X = (left.X < right.X) ? left.X : right.X;
535 result.Y = (left.Y < right.Y) ? left.Y : right.Y;
547 Min(ref left, ref right, out result);
559 return new Int2(left.
X + right.
X, left.
Y + right.
Y);
580 return new Int2(left.
X - right.
X, left.
Y - right.
Y);
590 return new Int2(-value.
X, -value.
Y);
601 return new Int2((
int)(value.
X * scale), (
int)(value.
Y * scale));
612 return new Int2((
int)(value.
X * scale), (
int)(value.
Y * scale));
621 public static Int2 operator /(
Int2 value,
float scale)
623 return new Int2((
int)(value.
X / scale), (
int)(value.
Y / scale));
632 public static bool operator ==(
Int2 left,
Int2 right)
634 return left.Equals(right);
643 public static bool operator !=(
Int2 left,
Int2 right)
645 return !left.Equals(right);
665 return new Vector4(value.
X, value.
Y, 0, 0);
676 return string.Format(CultureInfo.CurrentCulture,
"X:{0} Y:{1}", X, Y);
691 return string.Format(CultureInfo.CurrentCulture,
"X:{0} Y:{1}", X.ToString(
format, CultureInfo.CurrentCulture), Y.ToString(format, CultureInfo.CurrentCulture));
701 public string ToString(IFormatProvider formatProvider)
703 return string.Format(formatProvider,
"X:{0} Y:{1}", X, Y);
717 return ToString(formatProvider);
719 return string.Format(formatProvider,
"X:{0} Y:{1}", X.ToString(
format, formatProvider), Y.ToString(format, formatProvider));
730 return X.GetHashCode() + Y.GetHashCode();
742 return ((
float)Math.Abs(other.
X - X) < MathUtil.ZeroTolerance &&
743 (float)Math.Abs(other.
Y - Y) < MathUtil.ZeroTolerance);
753 public override bool Equals(
object value)
758 if (value.GetType() != GetType())
761 return Equals((
Int2)value);
769 public static implicit
operator System.Windows.Media.Media3D.Int3D(
Int2 value)
771 return new System.Windows.Media.Media3D.Int3D(value.X, value.Y, 0.0f);
779 public static explicit operator Int2(System.Windows.Media.Media3D.Int3D value)
781 return new Int2((
float)value.X, (
float)value.Y);
791 public static implicit
operator Microsoft.Xna.Framework.Int2(Int2 value)
793 return new Microsoft.Xna.Framework.Int2(value.X, value.Y);
801 public static implicit
operator Int2(Microsoft.Xna.Framework.Int2 value)
803 return new Int2(value.X, value.Y);
Int2(int x, int y)
Initializes a new instance of the SiliconStudio.Core.Mathematics.Int2 struct.
static int Dot(Int2 left, Int2 right)
Calculates the dot product of two vectors.
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
FbxDouble3 operator*(double factor, FbxDouble3 vector)
static Int2 Modulate(Int2 left, Int2 right)
Modulates a vector with another by performing component-wise multiplication.
string ToString(string format)
Returns a System.String that represents this instance.
static void Min(ref Int2 left, ref Int2 right, out Int2 result)
Returns a vector containing the smallest components of the specified vectors.
Represents a two dimensional mathematical vector.
static void Negate(ref Int2 value, out Int2 result)
Reverses the direction of a given vector.
Int2(Vector2 value)
Initializes a new instance of the SiliconStudio.Core.Mathematics.Int2 struct.
static void Normalize(ref Int2 value, out Int2 result)
Converts the vector into a unit vector.
static Int2 Min(Int2 left, Int2 right)
Returns a vector containing the smallest components of the specified vectors.
static Int2 Max(Int2 left, Int2 right)
Returns a vector containing the largest components of the specified vectors.
static void Max(ref Int2 left, ref Int2 right, out Int2 result)
Returns a vector containing the smallest components of the specified vectors.
static Int2 Normalize(Int2 value)
Converts the vector into a unit vector.
int Y
The Y component of the vector.
int X
The X component of the vector.
void Normalize()
Converts the vector into a unit vector.
int[] ToArray()
Creates an array containing the elements of the vector.
static void Multiply(ref Int2 value, int scale, out Int2 result)
Scales a vector by the given value.
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
const float ZeroTolerance
The value for which all absolute numbers smaller than are considered equal to zero.
static Int2 Subtract(Int2 left, Int2 right)
Subtracts two vectors.
static void Divide(ref Int2 value, int scale, out Int2 result)
Scales a vector by the given value.
static void Dot(ref Int2 left, ref Int2 right, out int result)
Calculates the dot product of two vectors.
static Int2 Multiply(Int2 value, int scale)
Scales a vector by the given value.
static Int2 Divide(Int2 value, int scale)
Scales a vector by the given value.
static Int2 Add(Int2 left, Int2 right)
Adds two vectors.
Represents a four dimensional mathematical vector.
override string ToString()
Returns a System.String that represents this instance.
static void Lerp(ref Int2 start, ref Int2 end, float amount, out Int2 result)
Performs a linear interpolation between two vectors.
int LengthSquared()
Calculates the squared length of the vector.
static void Modulate(ref Int2 left, ref Int2 right, out Int2 result)
Modulates a vector with another by performing component-wise multiplication.
static void Add(ref Int2 left, ref Int2 right, out Int2 result)
Adds two vectors.
void Pow(int exponent)
Raises the exponent for each components.
Represents a three dimensional mathematical vector.
float X
The X component of the vector.
static Int2 Negate(Int2 value)
Reverses the direction of a given vector.
string ToString(IFormatProvider formatProvider)
Returns a System.String that represents this instance.
static Int2 SmoothStep(Int2 start, Int2 end, float amount)
Performs a cubic interpolation between two vectors.
override int GetHashCode()
Returns a hash code for this instance.
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
int Length()
Calculates the length of the vector.
Int2(int[] values)
Initializes a new instance of the SiliconStudio.Core.Mathematics.Int2 struct.
Int2(int value)
Initializes a new instance of the SiliconStudio.Core.Mathematics.Int2 struct.
static Int2 Lerp(Int2 start, Int2 end, float amount)
Performs a linear interpolation between two vectors.
static void SmoothStep(ref Int2 start, ref Int2 end, float amount, out Int2 result)
Performs a cubic interpolation between two vectors.
static Int2 Clamp(Int2 value, Int2 min, Int2 max)
Restricts a value to be within a specified range.
static void Subtract(ref Int2 left, ref Int2 right, out Int2 result)
Subtracts two vectors.
string ToString(string format, IFormatProvider formatProvider)
Returns a System.String that represents this instance.
static void Clamp(ref Int2 value, ref Int2 min, ref Int2 max, out Int2 result)
Restricts a value to be within a specified range.
DataStyle
Specifies the style used for textual serialization when an array/list or a dictionary/map must be ser...
override bool Equals(object value)
Determines whether the specified System.Object is equal to this instance.
bool Equals(Int2 other)
Determines whether the specified SiliconStudio.Core.Mathematics.Int2 is equal to this instance...