Class NumberExtensions
A set of extensions for dealing with float, Microsoft.Xna.Framework.Vector2, Microsoft.Xna.Framework.Vector3, Microsoft.Xna.Framework.Vector4, Microsoft.Xna.Framework.Point, Microsoft.Xna.Framework.Matrix, Microsoft.Xna.Framework.Rectangle and RectangleF
public static class NumberExtensions
- Inheritance
-
NumberExtensions
- Inherited Members
Methods
Ceil(float)
Returns the smallest integral value that is greater than or equal to the specified decimal number.
public static int Ceil(this float f)
Parameters
ffloat
Returns
- int
The smallest integral value that is greater than or equal to
d. Note that this method returns a decimal instead of an integral type.
CeilCopy(Vector2)
Returns the smallest integral value that is greater than or equal to the specified decimal number.
public static Vector2 CeilCopy(this Vector2 vec)
Parameters
vecVector2
Returns
- Vector2
The smallest integral value that is greater than or equal to
d. Note that this method returns a decimal instead of an integral type.
CeilCopy(Vector3)
Returns the smallest integral value that is greater than or equal to the specified decimal number.
public static Vector3 CeilCopy(this Vector3 vec)
Parameters
vecVector3
Returns
- Vector3
The smallest integral value that is greater than or equal to
d. Note that this method returns a decimal instead of an integral type.
CeilCopy(Vector4)
Returns the smallest integral value that is greater than or equal to the specified decimal number.
public static Vector4 CeilCopy(this Vector4 vec)
Parameters
vecVector4
Returns
- Vector4
The smallest integral value that is greater than or equal to
d. Note that this method returns a decimal instead of an integral type.
Divide(Point, float)
Divides a point by a given scalar.
public static Point Divide(this Point point, float f)
Parameters
pointPointThe point
ffloatThe scalar
Returns
- Point
The point, divided by the scalar memberwise
Equals(Quaternion, Quaternion, float)
Checks for decimal equality with a given tolerance.
public static bool Equals(this Quaternion first, Quaternion second, float tolerance)
Parameters
firstQuaternionThe first number to equate
secondQuaternionThe second number to equate
tolerancefloatThe equality tolerance
Returns
- bool
Whether or not the two values are different by at most
tolerance
Equals(Vector2, Vector2, float)
Checks for decimal equality with a given tolerance.
public static bool Equals(this Vector2 first, Vector2 second, float tolerance)
Parameters
firstVector2The first number to equate
secondVector2The second number to equate
tolerancefloatThe equality tolerance
Returns
- bool
Whether or not the two values are different by at most
tolerance
Equals(Vector3, Vector3, float)
Checks for decimal equality with a given tolerance.
public static bool Equals(this Vector3 first, Vector3 second, float tolerance)
Parameters
firstVector3The first number to equate
secondVector3The second number to equate
tolerancefloatThe equality tolerance
Returns
- bool
Whether or not the two values are different by at most
tolerance
Equals(Vector4, Vector4, float)
Checks for decimal equality with a given tolerance.
public static bool Equals(this Vector4 first, Vector4 second, float tolerance)
Parameters
firstVector4The first number to equate
secondVector4The second number to equate
tolerancefloatThe equality tolerance
Returns
- bool
Whether or not the two values are different by at most
tolerance
Equals(float, float, float)
Checks for decimal equality with a given tolerance.
public static bool Equals(this float first, float second, float tolerance)
Parameters
firstfloatThe first number to equate
secondfloatThe second number to equate
tolerancefloatThe equality tolerance
Returns
- bool
Whether or not the two values are different by at most
tolerance
Floor(float)
Returns the largest integral value less than or equal to the specified decimal number.
public static int Floor(this float f)
Parameters
ffloat
Returns
- int
The largest integral value less than or equal to
d. Note that the method returns an integral value of type decimal.
FloorCopy(Vector2)
Returns the largest integral value less than or equal to the specified decimal number.
public static Vector2 FloorCopy(this Vector2 vec)
Parameters
vecVector2
Returns
- Vector2
The largest integral value less than or equal to
d. Note that the method returns an integral value of type decimal.
FloorCopy(Vector3)
Returns the largest integral value less than or equal to the specified decimal number.
public static Vector3 FloorCopy(this Vector3 vec)
Parameters
vecVector3
Returns
- Vector3
The largest integral value less than or equal to
d. Note that the method returns an integral value of type decimal.
FloorCopy(Vector4)
Returns the largest integral value less than or equal to the specified decimal number.
public static Vector4 FloorCopy(this Vector4 vec)
Parameters
vecVector4
Returns
- Vector4
The largest integral value less than or equal to
d. Note that the method returns an integral value of type decimal.
GetPoints(RectangleF, float, bool)
Returns a set of Microsoft.Xna.Framework.Vector2 values that are contained in the given RectangleF. Note that, by default, Left and Top are inclusive, but Right and Bottom are not.
public static IEnumerable<Vector2> GetPoints(this RectangleF area, float interval = 1, bool bottomRightInclusive = false)
Parameters
areaRectangleFThe area whose points to get
intervalfloatThe distance that should be traveled between each point that is to be returned
bottomRightInclusiveboolWhether Right and Bottom should be inclusive, rather than exclusive.
Returns
- IEnumerable<Vector2>
The points contained in the area
GetPoints(Rectangle, bool)
Returns a set of Microsoft.Xna.Framework.Point values that are contained in the given Microsoft.Xna.Framework.Rectangle. Note that, by default, Microsoft.Xna.Framework.Rectangle.Left and Microsoft.Xna.Framework.Rectangle.Top are inclusive, but Microsoft.Xna.Framework.Rectangle.Right and Microsoft.Xna.Framework.Rectangle.Bottom are not.
public static IEnumerable<Point> GetPoints(this Rectangle area, bool bottomRightInclusive = false)
Parameters
areaRectangleThe area whose points to get
bottomRightInclusiveboolWhether Microsoft.Xna.Framework.Rectangle.Right and Microsoft.Xna.Framework.Rectangle.Bottom should be inclusive, rather than exclusive.
Returns
- IEnumerable<Point>
The points contained in the area
Multiply(Point, float)
Multiplies a point by a given scalar.
public static Point Multiply(this Point point, float f)
Parameters
pointPointThe point
ffloatThe scalar
Returns
- Point
The point, multiplied by the scalar memberwise
OffsetCopy(RectangleF, Vector2)
Returns a copy of the given rectangle, moved by the given point. The rectangle's size remains unchanged.
public static RectangleF OffsetCopy(this RectangleF rect, Vector2 offset)
Parameters
rectRectangleFThe rectangle to move
offsetVector2The amount to move by
Returns
- RectangleF
The moved rectangle
OffsetCopy(Rectangle, Point)
Returns a copy of the given rectangle, moved by the given point. The rectangle's size remains unchanged.
public static Rectangle OffsetCopy(this Rectangle rect, Point offset)
Parameters
rectRectangleThe rectangle to move
offsetPointThe amount to move by
Returns
- Rectangle
The moved rectangle
Penetrate(RectangleF, RectangleF, out Vector2, out float)
Calculates the amount that the rectangle rect is penetrating the rectangle other by.
If a penetration on both axes is occuring, the one with the lower value is returned.
This is useful for collision detection, as it can be used to push colliding objects out of each other.
public static bool Penetrate(this RectangleF rect, RectangleF other, out Vector2 normal, out float penetration)
Parameters
rectRectangleFThe rectangle to do the penetration
otherRectangleFThe rectangle that should be penetrated
normalVector2The direction that the penetration occured in
penetrationfloatThe amount that the penetration occured by, in the direction of
normal
Returns
- bool
Whether or not a penetration occured
Rotation(Matrix)
Returns the rotation that the given matrix represents, as a Microsoft.Xna.Framework.Quaternion. Returns Microsoft.Xna.Framework.Quaternion.Identity if the matrix does not contain valid rotation information, or is not rotated.
public static Quaternion Rotation(this Matrix matrix)
Parameters
matrixMatrixThe matrix
Returns
- Quaternion
The rotation of the matrix
RotationVector(Matrix)
Returns the rotation that the given matrix represents, as a Microsoft.Xna.Framework.Vector3 that contains the x, y and z rotations in radians. Returns Microsoft.Xna.Framework.Vector3.Zero if the matrix does not contain valid rotation information, or is not rotated.
public static Vector3 RotationVector(this Matrix matrix)
Parameters
matrixMatrixThe matrix
Returns
- Vector3
The rotation of the matrix
RotationVector(Quaternion)
Returns the rotation that the given quaternion represents, as a Microsoft.Xna.Framework.Vector3 that contains the x, y and z rotations in radians. Returns Microsoft.Xna.Framework.Vector3.Zero if the quaternion does not contain valid rotation information, or is not rotated.
public static Vector3 RotationVector(this Quaternion quaternion)
Parameters
quaternionQuaternionThe quaternion
Returns
- Vector3
The rotation of the quaternion
Scale(Matrix)
Returns the 3-dimensional scale of the given matrix.
public static Vector3 Scale(this Matrix matrix)
Parameters
matrixMatrixThe matrix
Returns
- Vector3
The scale of the matrix
Shrink(RectangleF, Padding)
Shrinks the rectangle by the given padding, causing its size to decrease by twice the amount and its position to be moved inwards by the amount.
public static RectangleF Shrink(this RectangleF rect, Padding padding)
Parameters
rectRectangleFThe rectangle to shrink
paddingPaddingThe padding to shrink by
Returns
- RectangleF
The shrunk rectangle
Shrink(RectangleF, Vector2)
Shrinks the rectangle by the given padding, causing its size to decrease by twice the amount and its position to be moved inwards by the amount.
public static RectangleF Shrink(this RectangleF rect, Vector2 padding)
Parameters
rectRectangleFThe rectangle to shrink
paddingVector2The padding to shrink by
Returns
- RectangleF
The shrunk rectangle
Shrink(Rectangle, Point)
Shrinks the rectangle by the given padding, causing its size to decrease by twice the amount and its position to be moved inwards by the amount.
public static Rectangle Shrink(this Rectangle rect, Point padding)
Parameters
rectRectangleThe rectangle to shrink
paddingPointThe padding to shrink by
Returns
- Rectangle
The shrunk rectangle
ToVector2(Vector3)
Turns the given 3-dimensional vector into a 2-dimensional vector by chopping off the z coordinate.
public static Vector2 ToVector2(this Vector3 vector)
Parameters
vectorVector3The vector to convert
Returns
- Vector2
The resulting 2-dimensional vector
Transform(Point, Matrix)
Transforms a point by a given matrix.
public static Point Transform(this Point position, Matrix matrix)
Parameters
positionPointThe point
matrixMatrixThe matrix
Returns
- Point
The point, transformed by the matrix