diff --git a/Structs/Position2D.cs b/Structs/Position2D.cs index 85f4207..0225631 100644 --- a/Structs/Position2D.cs +++ b/Structs/Position2D.cs @@ -38,8 +38,8 @@ namespace MoonTools.Core.Structs public Position2D(float X, float Y) { - _x = Floor(X); - _y = Floor(Y); + _x = Truncate(X); + _y = Truncate(Y); remainder = new Vector2(Remainder(X), Remainder(Y)); } @@ -147,6 +147,11 @@ namespace MoonTools.Core.Structs return (int)Math.Floor(value); } + private static int Truncate(float value) + { + return (int)Math.Truncate(value); + } + public override bool Equals(object other) { if (other is Position2D otherPosition) diff --git a/Tests/Position2DTest.cs b/Tests/Position2DTest.cs index c566fc2..5fb10fc 100644 --- a/Tests/Position2DTest.cs +++ b/Tests/Position2DTest.cs @@ -8,6 +8,17 @@ namespace Tests { public class Position2DTest { + [Test] + public void Negatives() + { + var position = new Position2D(-3.6f, -4.2f); + + position.X.Should().Be(-3); + position.Y.Should().Be(-4); + position.ToVector2().X.Should().Be(-3.6f); + position.ToVector2().Y.Should().Be(-4.2f); + } + [Test] public void PositionVectorAddition() { @@ -99,4 +110,4 @@ namespace Tests (one != two).Should().BeTrue(); } } -} \ No newline at end of file +}