2019-08-06 14:20:11 +02:00
|
|
|
using System;
|
2019-08-07 00:45:40 +02:00
|
|
|
using Microsoft.Xna.Framework;
|
2019-11-02 14:53:59 +01:00
|
|
|
using MLEM.Misc;
|
2019-08-06 14:20:11 +02:00
|
|
|
|
|
|
|
namespace MLEM.Extensions {
|
|
|
|
public static class NumberExtensions {
|
|
|
|
|
|
|
|
public static int Floor(this float f) {
|
|
|
|
return (int) Math.Floor(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int Ceil(this float f) {
|
|
|
|
return (int) Math.Ceiling(f);
|
|
|
|
}
|
|
|
|
|
2019-08-07 00:45:40 +02:00
|
|
|
public static Vector2 Floor(this Vector2 vec) {
|
|
|
|
return new Vector2(vec.X.Floor(), vec.Y.Floor());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Vector3 Floor(this Vector3 vec) {
|
|
|
|
return new Vector3(vec.X.Floor(), vec.Y.Floor(), vec.Z.Floor());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Vector4 Floor(this Vector4 vec) {
|
|
|
|
return new Vector4(vec.X.Floor(), vec.Y.Floor(), vec.Z.Floor(), vec.W.Floor());
|
|
|
|
}
|
2019-08-06 14:20:11 +02:00
|
|
|
|
2019-08-11 21:24:09 +02:00
|
|
|
public static Point Multiply(this Point point, float f) {
|
|
|
|
return new Point((point.X * f).Floor(), (point.Y * f).Floor());
|
|
|
|
}
|
|
|
|
|
2019-08-15 14:59:15 +02:00
|
|
|
public static Point Divide(this Point point, float f) {
|
|
|
|
return new Point((point.X / f).Floor(), (point.Y / f).Floor());
|
|
|
|
}
|
|
|
|
|
2019-09-02 19:55:26 +02:00
|
|
|
public static Point Transform(this Point position, Matrix matrix) {
|
|
|
|
return new Point(
|
|
|
|
(position.X * matrix.M11 + position.Y * matrix.M21 + matrix.M41).Floor(),
|
|
|
|
(position.X * matrix.M12 + position.Y * matrix.M22 + matrix.M42).Floor());
|
|
|
|
}
|
|
|
|
|
2019-08-12 19:44:16 +02:00
|
|
|
public static Rectangle OffsetCopy(this Rectangle rect, Point offset) {
|
|
|
|
rect.X += offset.X;
|
|
|
|
rect.Y += offset.Y;
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2019-11-02 14:53:59 +01:00
|
|
|
public static RectangleF OffsetCopy(this RectangleF rect, Vector2 offset) {
|
|
|
|
rect.X += offset.X;
|
|
|
|
rect.Y += offset.Y;
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2019-09-10 23:28:25 +02:00
|
|
|
public static Rectangle Shrink(this Rectangle rect, Point padding) {
|
|
|
|
rect.X += padding.X;
|
|
|
|
rect.Y += padding.Y;
|
|
|
|
rect.Width -= padding.X * 2;
|
|
|
|
rect.Height -= padding.Y * 2;
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2019-11-02 14:53:59 +01:00
|
|
|
public static RectangleF Shrink(this RectangleF rect, Vector2 padding) {
|
|
|
|
rect.X += padding.X;
|
|
|
|
rect.Y += padding.Y;
|
|
|
|
rect.Width -= padding.X * 2;
|
|
|
|
rect.Height -= padding.Y * 2;
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2019-12-14 14:00:12 +01:00
|
|
|
public static RectangleF Shrink(this RectangleF rect, Padding padding) {
|
|
|
|
rect.X += padding.Left;
|
2019-12-14 14:07:00 +01:00
|
|
|
rect.Y += padding.Top;
|
2019-12-14 14:00:12 +01:00
|
|
|
rect.Width -= padding.Width;
|
|
|
|
rect.Height -= padding.Height;
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2019-08-06 14:20:11 +02:00
|
|
|
}
|
|
|
|
}
|