Files
RobustToolbox/Robust.UnitTesting/Shared/Physics/Shape_Test.cs
T
metalgearslothandGitHub 45dc9ad80e Inline polygon vertices (#5758)
* 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
2025-03-20 21:26:05 +11:00

34 lines
1.1 KiB
C#

using System;
using System.Numerics;
using NUnit.Framework;
using Robust.Shared.Physics.Collision.Shapes;
namespace Robust.UnitTesting.Shared.Physics
{
[TestFixture]
[TestOf(typeof(IPhysShape))]
public sealed class Shape_Test : RobustUnitTest
{
[Test]
public void TestPolyNormals()
{
var poly = new PolygonShape();
Span<Vector2> verts = stackalloc Vector2[4];
verts[0] = new Vector2(1f, -1f);
verts[1] = new Vector2(1f, 1f);
verts[2] = new Vector2(-1f, 1f);
verts[3] = new Vector2(-1f, -1f);
poly.Set(verts, 4);
Assert.That(poly.VertexCount == 4);
Assert.That(poly.Normals[0], Is.EqualTo(new Vector2(1, 0)), $"Vert is {poly.Vertices[0]}");
Assert.That(poly.Normals[1], Is.EqualTo(new Vector2(0, 1)), $"Vert is {poly.Vertices[1]}");
Assert.That(poly.Normals[2], Is.EqualTo(new Vector2(-1, 0)), $"Vert is {poly.Vertices[2]}");
Assert.That(poly.Normals[3], Is.EqualTo(new Vector2(0, -1)), $"Vert is {poly.Vertices[3]}");
}
}
}