2019-09-06 07:13:49 +00:00
|
|
|
using FluentAssertions;
|
|
|
|
using NUnit.Framework;
|
2019-10-31 22:57:04 +00:00
|
|
|
|
2020-02-20 23:03:34 +00:00
|
|
|
using MoonTools.Structs;
|
2019-10-31 22:57:04 +00:00
|
|
|
using System.Numerics;
|
2019-09-06 07:13:49 +00:00
|
|
|
|
|
|
|
namespace Tests
|
|
|
|
{
|
|
|
|
public class Transform2DTest
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void Equals()
|
|
|
|
{
|
|
|
|
var transformA = new Transform2D(new Position2D(0, 1), 4f, new Vector2(2, 1));
|
|
|
|
var transformB = new Transform2D(new Position2D(0, 1), 4f, new Vector2(2, 1));
|
|
|
|
|
2020-01-02 06:57:57 +00:00
|
|
|
transformA.Equals(transformB).Should().BeTrue();
|
2019-09-06 07:13:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void NotEquals()
|
|
|
|
{
|
|
|
|
var transformA = new Transform2D(new Position2D(2, 3));
|
|
|
|
var transformB = new Transform2D(new Position2D(5, 1));
|
|
|
|
|
2020-01-02 06:57:57 +00:00
|
|
|
transformA.Equals(transformB).Should().BeFalse();
|
2019-09-06 07:13:49 +00:00
|
|
|
}
|
|
|
|
|
2019-10-25 22:05:46 +00:00
|
|
|
[Test]
|
|
|
|
public void EqualsOperator()
|
|
|
|
{
|
|
|
|
var transformA = new Transform2D(new Position2D(0, 1), 4f, new Vector2(2, 1));
|
|
|
|
var transformB = new Transform2D(new Position2D(0, 1), 4f, new Vector2(2, 1));
|
|
|
|
|
|
|
|
(transformA == transformB).Should().BeTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void NotEqualsOperator()
|
|
|
|
{
|
|
|
|
var transformA = new Transform2D(new Position2D(2, 3));
|
|
|
|
var transformB = new Transform2D(new Position2D(5, 1));
|
|
|
|
|
|
|
|
(transformA != transformB).Should().BeTrue();
|
|
|
|
}
|
|
|
|
|
2019-09-06 07:13:49 +00:00
|
|
|
[Test]
|
|
|
|
public void Compose()
|
|
|
|
{
|
2019-10-31 23:01:15 +00:00
|
|
|
var transformA = new Transform2D(new Position2D(4, 1), (float)System.Math.PI / 2, new Vector2(3, 1));
|
|
|
|
var transformB = new Transform2D(new Position2D(15, 2), (float)System.Math.PI / 4, new Vector2(1, 2));
|
2019-09-06 07:13:49 +00:00
|
|
|
|
2019-10-31 23:01:15 +00:00
|
|
|
transformA.Compose(transformB).Should().BeEquivalentTo(new Transform2D(new Position2D(19, 3), 3 * (float)System.Math.PI / 4, new Vector2(3, 2)));
|
2019-09-06 07:13:49 +00:00
|
|
|
}
|
2020-01-02 06:57:57 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Transform()
|
|
|
|
{
|
|
|
|
var transformA = new Transform2D(Position2D.Zero, (float)System.Math.PI / 2, Vector2.One);
|
|
|
|
var transformB = new Transform2D(new Vector2(0, 2), (float)System.Math.PI, Vector2.One);
|
|
|
|
var transformC = new Transform2D(new Vector2(-2, 0), (float)System.Math.PI * 2, new Vector2(3, 1));
|
|
|
|
|
|
|
|
Vector2.Transform(new Vector2(-1, 0), transformA.TransformMatrix).Should().Be(new Vector2(0, -1));
|
|
|
|
Vector2.Transform(new Vector2(-1, 0), transformB.TransformMatrix).Should().Be(new Vector2(1, 2));
|
|
|
|
Vector2.Transform(new Vector2(-1, 0), transformC.TransformMatrix).Should().Be(new Vector2(-5, 0));
|
|
|
|
}
|
2019-09-06 07:13:49 +00:00
|
|
|
}
|
2020-02-20 23:03:34 +00:00
|
|
|
}
|