diff options
| author | Sarah Bradley <git@sarahduck.ca> | 2023-12-01 20:33:42 -0800 |
|---|---|---|
| committer | Sarah Bradley <git@sarahduck.ca> | 2023-12-01 20:33:42 -0800 |
| commit | 2793b94040a473538f01723d5ca5f53c4535e2af (patch) | |
| tree | cb30f0dae20bda6ef9d1c005325bfd9c986b3c8f /MathExtensions.cs | |
What I've got so far
Diffstat (limited to 'MathExtensions.cs')
| -rw-r--r-- | MathExtensions.cs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/MathExtensions.cs b/MathExtensions.cs new file mode 100644 index 0000000..81db592 --- /dev/null +++ b/MathExtensions.cs @@ -0,0 +1,33 @@ +using System.Numerics; + +namespace OnekoOnline; + +static class MathExtensions +{ + public static Vector2 LimitLength(this Vector2 toLimit, float lengthLimit) + { + float length = toLimit.Length(); + if (toLimit == Vector2.Zero) return Vector2.Zero; + return Vector2.Normalize(toLimit) * MathF.Min(length, lengthLimit); + } + + public static Vector2 Round(this Vector2 toRound) + { + return new(MathF.Round(toRound.X), MathF.Round(toRound.Y)); + } +} + +public static class Directions +{ + public static readonly Vector2 Up = new(0,-1); + public static readonly Vector2 Down = new(0,1); + public static readonly Vector2 Left = new(-1,0); + public static readonly Vector2 Right = new(1,0); + + public static readonly Vector2 UpLeft = Vector2.Normalize(Up+Left); + public static readonly Vector2 UpRight = Vector2.Normalize(Up+Right); + public static readonly Vector2 DownLeft = Vector2.Normalize(Down+Left); + public static readonly Vector2 DownRight = Vector2.Normalize(Down+Right); + + public static readonly Vector2[] AllDirections = [Up,Down,Left,Right,UpLeft,UpRight,DownLeft,DownRight]; +}
\ No newline at end of file |
