Add grid merging (#3627)

* Add grid merging

* More preliminary cleanup

* Fixes

* Fixes

* weh

* tweaks

* Tests

* weh

* Fix direction test

* Release notes
This commit is contained in:
metalgearsloth
2024-01-21 17:41:04 +11:00
committed by GitHub
parent aae929966c
commit 59b3ffda4f
12 changed files with 376 additions and 56 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using JetBrains.Annotations;
using Robust.Shared.Utility;
@@ -258,7 +259,24 @@ namespace Robust.Shared.Maths
/// <param name="degrees">The angle in degrees.</param>
public static Angle FromDegrees(double degrees)
{
return new(MathHelper.DegreesToRadians(degrees));
// Avoid rounding issues with common use cases.
switch (degrees)
{
case -270:
return new Angle(Math.PI * -1.5);
case 90:
return new Angle(Math.PI / 2);
case -180:
return new Angle(-Math.PI);
case 180:
return new Angle(Math.PI);
case 270.0:
return new Angle(Math.PI * 1.5);
case -90:
return new Angle(Math.PI / -2);
default:
return new(MathHelper.DegreesToRadians(degrees));
}
}
/// <summary>

View File

@@ -109,6 +109,11 @@ namespace Robust.Shared.Maths
}
}
public Vector2i Rotate(Angle angle)
{
return (Vector2i) angle.RotateVec(this);
}
public static Vector2i operator -(Vector2i a, Vector2i b)
{
return new(a.X - b.X, a.Y - b.Y);