Table of Contents

Class NumberExtensions

Namespace
MLEM.Maths
Assembly
MLEM.dll

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

f float

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

vec Vector2

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

vec Vector3

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

vec Vector4

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

point Point

The point

f float

The 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

first Quaternion

The first number to equate

second Quaternion

The second number to equate

tolerance float

The 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

first Vector2

The first number to equate

second Vector2

The second number to equate

tolerance float

The 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

first Vector3

The first number to equate

second Vector3

The second number to equate

tolerance float

The 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

first Vector4

The first number to equate

second Vector4

The second number to equate

tolerance float

The 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

first float

The first number to equate

second float

The second number to equate

tolerance float

The equality tolerance

Returns

bool

Whether or not the two values are different by at most tolerance

Floor(float)

Returns the largest integer less than or equal to the specified decimal number.

public static int Floor(this float f)

Parameters

f float

Returns

int

The largest integer less than or equal to d. Note that the method returns an integral value of type Math.

FloorCopy(Vector2)

Returns the largest integer less than or equal to the specified decimal number.

public static Vector2 FloorCopy(this Vector2 vec)

Parameters

vec Vector2

Returns

Vector2

The largest integer less than or equal to d. Note that the method returns an integral value of type Math.

FloorCopy(Vector3)

Returns the largest integer less than or equal to the specified decimal number.

public static Vector3 FloorCopy(this Vector3 vec)

Parameters

vec Vector3

Returns

Vector3

The largest integer less than or equal to d. Note that the method returns an integral value of type Math.

FloorCopy(Vector4)

Returns the largest integer less than or equal to the specified decimal number.

public static Vector4 FloorCopy(this Vector4 vec)

Parameters

vec Vector4

Returns

Vector4

The largest integer less than or equal to d. Note that the method returns an integral value of type Math.

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

area RectangleF

The area whose points to get

interval float

The distance that should be traveled between each point that is to be returned

bottomRightInclusive bool

Whether 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

area Rectangle

The area whose points to get

bottomRightInclusive bool

Whether 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

point Point

The point

f float

The 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

rect RectangleF

The rectangle to move

offset Vector2

The 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

rect Rectangle

The rectangle to move

offset Point

The 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

rect RectangleF

The rectangle to do the penetration

other RectangleF

The rectangle that should be penetrated

normal Vector2

The direction that the penetration occured in

penetration float

The 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

matrix Matrix

The 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

matrix Matrix

The 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

quaternion Quaternion

The 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

matrix Matrix

The 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

rect RectangleF

The rectangle to shrink

padding Padding

The 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

rect RectangleF

The rectangle to shrink

padding Vector2

The 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

rect Rectangle

The rectangle to shrink

padding Point

The 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

vector Vector3

The 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

position Point

The point

matrix Matrix

The matrix

Returns

Point

The point, transformed by the matrix