Skip to content

Commit

Permalink
Removed Normalize methods of Int2 and Int3; added Length/SquaredLen…
Browse files Browse the repository at this point in the history
…gth to Int4
  • Loading branch information
nemerle authored and xen2 committed Sep 25, 2018
1 parent da91d82 commit ac4e7e0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 89 deletions.
44 changes: 0 additions & 44 deletions sources/core/Xenko.Core.Mathematics/Int2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,6 @@ public Int2(int[] values)
Y = values[1];
}

/// <summary>
/// Gets a value indicting whether this instance is normalized.
/// </summary>
public bool IsNormalized
{
get { return Math.Abs((X * X) + (Y * Y) - 1f) < MathUtil.ZeroTolerance; }
}

/// <summary>
/// Gets or sets the component at the specified index.
/// </summary>
Expand Down Expand Up @@ -190,20 +182,6 @@ public int LengthSquared()
return (X * X) + (Y * Y);
}

/// <summary>
/// Converts the vector into a unit vector.
/// </summary>
public void Normalize()
{
int length = Length();
if (length > MathUtil.ZeroTolerance)
{
int inv = 1 / length;
X *= inv;
Y *= inv;
}
}

/// <summary>
/// Raises the exponent for each components.
/// </summary>
Expand Down Expand Up @@ -409,28 +387,6 @@ public static int Dot(Int2 left, Int2 right)
return (left.X * right.X) + (left.Y * right.Y);
}

/// <summary>
/// Converts the vector into a unit vector.
/// </summary>
/// <param name="value">The vector to normalize.</param>
/// <param name="result">When the method completes, contains the normalized vector.</param>
public static void Normalize(ref Int2 value, out Int2 result)
{
result = value;
result.Normalize();
}

/// <summary>
/// Converts the vector into a unit vector.
/// </summary>
/// <param name="value">The vector to normalize.</param>
/// <returns>The normalized vector.</returns>
public static Int2 Normalize(Int2 value)
{
value.Normalize();
return value;
}

/// <summary>
/// Performs a linear interpolation between two vectors.
/// </summary>
Expand Down
45 changes: 0 additions & 45 deletions sources/core/Xenko.Core.Mathematics/Int3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,6 @@ public Int3(int[] values)
Z = values[2];
}

/// <summary>
/// Gets a value indicting whether this instance is normalized.
/// </summary>
public bool IsNormalized
{
get { return Math.Abs((X * X) + (Y * Y) + (Z * Z) - 1f) < MathUtil.ZeroTolerance; }
}

/// <summary>
/// Gets or sets the component at the specified index.
/// </summary>
Expand Down Expand Up @@ -209,21 +201,6 @@ public int LengthSquared()
return (X * X) + (Y * Y) + (Z * Z);
}

/// <summary>
/// Converts the vector into a unit vector.
/// </summary>
public void Normalize()
{
int length = Length();
if (length > MathUtil.ZeroTolerance)
{
int inv = 1 / length;
X *= inv;
Y *= inv;
Z *= inv;
}
}

/// <summary>
/// Raises the exponent for each components.
/// </summary>
Expand Down Expand Up @@ -434,28 +411,6 @@ public static int Dot(Int3 left, Int3 right)
return (left.X * right.X) + (left.Y * right.Y) + (left.Z * right.Z);
}

/// <summary>
/// Converts the vector into a unit vector.
/// </summary>
/// <param name="value">The vector to normalize.</param>
/// <param name="result">When the method completes, contains the normalized vector.</param>
public static void Normalize(ref Int3 value, out Int3 result)
{
result = value;
result.Normalize();
}

/// <summary>
/// Converts the vector into a unit vector.
/// </summary>
/// <param name="value">The vector to normalize.</param>
/// <returns>The normalized vector.</returns>
public static Int3 Normalize(Int3 value)
{
value.Normalize();
return value;
}

/// <summary>
/// Performs a linear interpolation between two vectors.
/// </summary>
Expand Down
26 changes: 26 additions & 0 deletions sources/core/Xenko.Core.Mathematics/Int4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,32 @@ public int this[int index]
}
}

/// <summary>
/// Calculates the length of the vector.
/// </summary>
/// <returns>The length of the vector.</returns>
/// <remarks>
/// <see cref="Int4.LengthSquared"/> may be preferred when only the relative length is needed
/// and speed is of the essence.
/// </remarks>
public int Length()
{
return (int)Math.Sqrt((X * X) + (Y * Y) + (Z * Z) + (W * W));
}

/// <summary>
/// Calculates the squared length of the vector.
/// </summary>
/// <returns>The squared length of the vector.</returns>
/// <remarks>
/// This method may be preferred to <see cref="Int4.Length"/> when only a relative length is needed
/// and speed is of the essence.
/// </remarks>
public int LengthSquared()
{
return (X * X) + (Y * Y) + (Z * Z) + (W * W);
}

/// <summary>
/// Creates an array containing the elements of the vector.
/// </summary>
Expand Down

0 comments on commit ac4e7e0

Please sign in to comment.