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

Commit 10a850d

Browse files
authored
Merge pull request #923 from mrvux/mathutils
* [Mathematics] Add per component absolute value for vector3 * [Maths] Add per component absolute value for vector2 * [Maths] Add properties for bounding box (size + center) * Simplify bounding box
2 parents 6e04f29 + 229a00e commit 10a850d

3 files changed

Lines changed: 88 additions & 0 deletions

File tree

Source/SharpDX.Mathematics/BoundingBox.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,46 @@ public BoundingBox(Vector3 minimum, Vector3 maximum)
7777
this.Maximum = maximum;
7878
}
7979

80+
/// <summary>
81+
/// Returns the width of the bounding box
82+
/// </summary>
83+
public float Width
84+
{
85+
get { return this.Maximum.X - this.Minimum.X; }
86+
}
87+
88+
/// <summary>
89+
/// Returns the height of the bounding box
90+
/// </summary>
91+
public float Height
92+
{
93+
get { return this.Maximum.Y - this.Minimum.Y; }
94+
}
95+
96+
/// <summary>
97+
/// Returns the height of the bounding box
98+
/// </summary>
99+
public float Depth
100+
{
101+
get { return this.Maximum.Z - this.Minimum.Z; }
102+
}
103+
104+
/// <summary>
105+
/// Returns the size of the bounding box
106+
/// </summary>
107+
public Vector3 Size
108+
{
109+
get { return this.Maximum - this.Minimum; }
110+
}
111+
112+
/// <summary>
113+
/// Returns the size of the bounding box
114+
/// </summary>
115+
public Vector3 Center
116+
{
117+
get { return (this.Maximum + this.Minimum) * 0.5f; }
118+
}
119+
80120
/// <summary>
81121
/// Retrieves the eight corners of the bounding box.
82122
/// </summary>

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>

Source/SharpDX.Mathematics/Vector3.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,31 @@ public static Vector3 Negate(Vector3 value)
513513
return new Vector3(-value.X, -value.Y, -value.Z);
514514
}
515515

516+
/// <summary>
517+
/// Returns per component absolute value of a vector
518+
/// </summary>
519+
/// <param name="value">Input vector</param>
520+
/// <param name="result">When the method completes, contains a vector with each component being the absolute value of the input component</param>
521+
public static void Abs(ref Vector3 value, out Vector3 result)
522+
{
523+
result = new Vector3(value.X > 0.0f ? value.X : -value.X,
524+
value.Y > 0.0f ? value.Y : -value.Y,
525+
value.Z > 0.0f ? value.Z : -value.Z);
526+
}
527+
528+
/// <summary>
529+
/// Returns per component absolute value of a vector
530+
/// </summary>
531+
/// <param name="value">Input vector</param>
532+
/// <returns>A vector with each component being the absolute value of the input component</returns>
533+
public static Vector3 Abs(Vector3 value)
534+
{
535+
return new Vector3(
536+
value.X > 0.0f ? value.X : -value.X,
537+
value.Y > 0.0f ? value.Y : -value.Y,
538+
value.Z > 0.0f ? value.Z : -value.Z);
539+
}
540+
516541
/// <summary>
517542
/// Returns a <see cref="Vector3"/> containing the 3D Cartesian coordinates of a point specified in Barycentric coordinates relative to a 3D triangle.
518543
/// </summary>

0 commit comments

Comments
 (0)