Files
RobustToolbox/Robust.Client.Tests/Sprite/TransformCenteredBoxTest.cs
PJB3005 788e9386fd Split up test project
Robust.UnitTesting was both ALL tests for RT, and also API surface for content tests.

Tests are now split into separate projects as appropriate, and the API side has also been split off.
2025-12-16 01:36:53 +01:00

36 lines
1.4 KiB
C#

using System.Numerics;
using NUnit.Framework;
using Robust.Client.Graphics.Clyde;
using Robust.Shared.Maths;
using Robust.UnitTesting;
namespace Robust.Client.Tests.Sprite;
[TestFixture]
[TestOf(typeof(Clyde))]
public sealed class TransformCenteredBoxTest
{
private static IEnumerable<(Box2 box, float angle, Vector2 offset, Vector2 scale)> _args =
[
(Box2.UnitCentered, 0f, new Vector2(0f,0f), new Vector2(1f,-1f)),
(Box2.UnitCentered, MathF.PI / 7, new Vector2(0f, 0f), new Vector2(1f, -1f)),
(Box2.UnitCentered, MathF.PI / 7, new Vector2(-1f, 2.3f), new Vector2(1f, -1f)),
(Box2.UnitCentered, MathF.PI / 7, new Vector2(-1f, 2.3f), new Vector2(1.25f, -0.32f)),
(new Box2(1,2,3,4), MathF.PI / 7, new Vector2(-1f, 2.3f), new Vector2(1.25f, -0.32f)),
];
[Test]
public void TestTransformCenteredBox([ValueSource(nameof(_args))]
(Box2 box, float angle, Vector2 offset, Vector2 scale) args)
{
var result = Clyde.TransformCenteredBox(args.box, args.angle, args.offset, args.scale);
var expected = Matrix3x2.CreateRotation(args.angle).TransformBox(args.box).Translated(args.offset);
expected = new(
expected.Left * args.scale.X,
expected.Top * args.scale.Y,
expected.Right * args.scale.X,
expected.Bottom * args.scale.Y);
Assert.That(result, Is.Approximately(expected));
}
}