mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-16 15:22:27 +02:00
* FastPoly * Inline polygon vertices No more pooling, pooling bad. No more arrays in engine, only span. I made a slim version that's only the 4 verts so no padding on it compared to Polygon. Slightly more clamplicated code but entitylookup + mapmanager are both hotpaths and it's easy to do. Memory usage will likely go up for now but heap allocations should drop significantly due to removing the pooling. * Unhide these * Fixes * More fixes * More fixes * Avoid potential bomb
60 lines
1.6 KiB
C#
60 lines
1.6 KiB
C#
using System.Numerics;
|
|
using NUnit.Framework;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Physics;
|
|
using Robust.Shared.Physics.Shapes;
|
|
|
|
namespace Robust.UnitTesting.Shared.Physics;
|
|
|
|
[TestFixture]
|
|
public sealed class Polygon_Test
|
|
{
|
|
/// <summary>
|
|
/// Check that Slim and normal Polygon are equals
|
|
/// </summary>
|
|
[Test]
|
|
public void TestSlim()
|
|
{
|
|
var slim = new SlimPolygon(Box2.UnitCentered.Translated(Vector2.One));
|
|
|
|
var poly = new Polygon(Box2.UnitCentered.Translated(Vector2.One));
|
|
|
|
Assert.That(slim.Equals(poly));
|
|
}
|
|
|
|
[Test]
|
|
public void TestAABB()
|
|
{
|
|
var shape = new SlimPolygon(Box2.UnitCentered.Translated(Vector2.One));
|
|
|
|
Assert.That(shape.ComputeAABB(Transform.Empty, 0), Is.EqualTo(Box2.UnitCentered.Translated(Vector2.One)));
|
|
}
|
|
|
|
[Test]
|
|
public void TestBox2()
|
|
{
|
|
var shape = new SlimPolygon(Box2.UnitCentered.Translated(Vector2.One));
|
|
Assert.That(shape._vertices.AsSpan.ToArray(), Is.EqualTo(new Vector2[]
|
|
{
|
|
new Vector2(0.5f, 0.5f),
|
|
new Vector2(1.5f, 0.5f),
|
|
new Vector2(1.5f, 1.5f),
|
|
new Vector2(0.5f, 1.5f),
|
|
}));
|
|
}
|
|
|
|
[Test]
|
|
public void TestBox2Rotated()
|
|
{
|
|
var shape = new SlimPolygon(new Box2Rotated(Box2.UnitCentered, Angle.FromDegrees(90)));
|
|
|
|
Assert.That(shape._vertices.AsSpan.ToArray(), Is.EqualTo(new Vector2[]
|
|
{
|
|
new Vector2(0.5f, -0.5f),
|
|
new Vector2(0.5f, 0.5f),
|
|
new Vector2(-0.5f, 0.5f),
|
|
new Vector2(-0.5f, -0.5f),
|
|
}));
|
|
}
|
|
}
|