feat: Vector2D Min, Max, Clamp & Lerp
This commit is contained in:
parent
55bde3bafd
commit
a83d983177
|
@ -4,4 +4,6 @@ public static class Math
|
||||||
{
|
{
|
||||||
public const float RadianToDegree = 57.29577866666166f;
|
public const float RadianToDegree = 57.29577866666166f;
|
||||||
public const float DegreeToRadian = 0.01745329277777778f;
|
public const float DegreeToRadian = 0.01745329277777778f;
|
||||||
|
|
||||||
|
public static float Clamp(float value, float min, float max) => (value < min) ? min : (value > max) ? max : value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,11 @@ public record Vector2D(float X, float Y)
|
||||||
public static Vector2D FromTo(Vector2D from, Vector2D to) => to - from;
|
public static Vector2D FromTo(Vector2D from, Vector2D to) => to - from;
|
||||||
public static Vector2D Scale(Vector2D vector, Vector2D scale) => new(vector.X * scale.X, vector.Y * scale.Y);
|
public static Vector2D Scale(Vector2D vector, Vector2D scale) => new(vector.X * scale.X, vector.Y * scale.Y);
|
||||||
|
|
||||||
|
public static Vector2D Min(Vector2D left, Vector2D right) => new((left.X < right.X) ? left.X : right.X, (left.Y < right.Y) ? left.Y : right.Y);
|
||||||
|
public static Vector2D Max(Vector2D left, Vector2D right) => new((left.X > right.X) ? left.X : right.X, (left.Y > right.Y) ? left.Y : right.Y);
|
||||||
|
public static Vector2D Clamp(Vector2D vector, Vector2D min, Vector2D max) => new(Math.Clamp(vector.X, min.X, max.X), Math.Clamp(vector.Y, min.Y, max.Y));
|
||||||
|
public static Vector2D Lerp(Vector2D from, Vector2D to, float t) => from + FromTo(from, to) * t;
|
||||||
|
|
||||||
public static float Cross(Vector2D left, Vector2D right) => left.X * right.Y - left.Y * right.X;
|
public static float Cross(Vector2D left, Vector2D right) => left.X * right.Y - left.Y * right.X;
|
||||||
public static float Angle(Vector2D left, Vector2D right) => MathF.Acos(Dot(left, right) / (Length(left) * Length(right)));
|
public static float Angle(Vector2D left, Vector2D right) => MathF.Acos(Dot(left, right) / (Length(left) * Length(right)));
|
||||||
public static float Dot(Vector2D left, Vector2D right) => left.X * right.X + left.Y * right.Y;
|
public static float Dot(Vector2D left, Vector2D right) => left.X * right.X + left.Y * right.Y;
|
||||||
|
|
|
@ -11,6 +11,11 @@ public static class Vector2DExtensions
|
||||||
public static Vector2D FromTo(this Vector2D from, Vector2D to) => Vector2D.FromTo(from, to);
|
public static Vector2D FromTo(this Vector2D from, Vector2D to) => Vector2D.FromTo(from, to);
|
||||||
public static Vector2D Scale(this Vector2D vector, Vector2D scale) => Vector2D.FromTo(vector, scale);
|
public static Vector2D Scale(this Vector2D vector, Vector2D scale) => Vector2D.FromTo(vector, scale);
|
||||||
|
|
||||||
|
public static Vector2D Min(this Vector2D left, Vector2D right) => Vector2D.Min(left, right);
|
||||||
|
public static Vector2D Max(this Vector2D left, Vector2D right) => Vector2D.Max(left, right);
|
||||||
|
public static Vector2D Clamp(this Vector2D vector, Vector2D min, Vector2D max) => Vector2D.Clamp(vector, min, max);
|
||||||
|
public static Vector2D Lerp(this Vector2D from, Vector2D to, float t) => Vector2D.Lerp(from, to, t);
|
||||||
|
|
||||||
public static float Cross(this Vector2D left, Vector2D right) => Vector2D.Cross(left, right);
|
public static float Cross(this Vector2D left, Vector2D right) => Vector2D.Cross(left, right);
|
||||||
public static float AngleBetween(this Vector2D left, Vector2D right) => Vector2D.Angle(left, right);
|
public static float AngleBetween(this Vector2D left, Vector2D right) => Vector2D.Angle(left, right);
|
||||||
public static float Dot(this Vector2D left, Vector2D right) => Vector2D.Dot(left, right);
|
public static float Dot(this Vector2D left, Vector2D right) => Vector2D.Dot(left, right);
|
||||||
|
|
Loading…
Reference in New Issue