using Microsoft.Xna.Framework;
using MLEM.Extensions;
using MonoGame.Extended;
namespace MLEM.Extended.Extensions {
///
/// A set of extension methods that convert MLEM types to MonoGame.Extended types and vice versa.
///
public static class NumberExtensions {
///
/// Converts a MLEM to a MonoGame.Extended .
///
/// The rectangle to convert
/// The converted rectangle
public static RectangleF ToExtended(this Misc.RectangleF rect) {
return new RectangleF(rect.X, rect.Y, rect.Width, rect.Height);
}
///
/// Converts a MonoGame.Extended to a MLEM .
///
/// The rectangle to convert
/// The converted rectangle
public static Misc.RectangleF ToMlem(this RectangleF rect) {
return new Misc.RectangleF(rect.X, rect.Y, rect.Width, rect.Height);
}
///
/// Calculates the amount that the rectangle is penetrating the rectangle 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.
///
/// The rectangle to do the penetration
/// The rectangle that should be penetrated
/// The direction that the penetration occured in
/// The amount that the penetration occured by, in the direction of
/// Whether or not a penetration occured
public static bool Penetrate(this RectangleF rect, RectangleF other, out Vector2 normal, out float penetration) {
return rect.ToMlem().Penetrate(other.ToMlem(), out normal, out penetration);
}
}
}