Skip to content
This repository was archived by the owner on Mar 30, 2019. It is now read-only.

Commit 8f830b5

Browse files
committed
[Maths] Add per component absolute value for vector2
1 parent 5852eda commit 8f830b5

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Source/SharpDX.Mathematics/Vector2.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,29 @@ public static Vector2 Negate(Vector2 value)
444444
return new Vector2(-value.X, -value.Y);
445445
}
446446

447+
/// <summary>
448+
/// Returns per component absolute value of a vector
449+
/// </summary>
450+
/// <param name="value">Input vector</param>
451+
/// <param name="result">When the method completes, contains a vector with each component being the absolute value of the input component</param>
452+
public static void Abs(ref Vector2 value, out Vector2 result)
453+
{
454+
result = new Vector2(value.X > 0.0f ? value.X : -value.X,
455+
value.Y > 0.0f ? value.Y : -value.Y);
456+
}
457+
458+
/// <summary>
459+
/// Returns per component absolute value of a vector
460+
/// </summary>
461+
/// <param name="value">Input vector</param>
462+
/// <returns>A vector with each component being the absolute value of the input component</returns>
463+
public static Vector2 Abs(Vector2 value)
464+
{
465+
return new Vector2(
466+
value.X > 0.0f ? value.X : -value.X,
467+
value.Y > 0.0f ? value.Y : -value.Y);
468+
}
469+
447470
/// <summary>
448471
/// Returns a <see cref="Vector2"/> containing the 2D Cartesian coordinates of a point specified in Barycentric coordinates relative to a 2D triangle.
449472
/// </summary>

0 commit comments

Comments
 (0)