v1.5.7.0 (Summer Update)

This commit is contained in:
Regalis11
2024-06-18 16:49:51 +03:00
parent 4a63dacbce
commit 230d1b6e78
263 changed files with 7792 additions and 2845 deletions
@@ -5,6 +5,7 @@ using Xunit;
using Barotrauma;
using FluentAssertions;
using FsCheck;
using Microsoft.Xna.Framework;
namespace TestProject;
@@ -56,4 +57,44 @@ public sealed class GenericToolBoxTests
ToolBox.StatIdentifierMatches(pair.First, pair.Second).Should().BeFalse();
}).VerboseCheckThrowOnFailure();
}
[Fact]
public void PointOnRectClosestToPoint()
{
RectangleF rect1 = new(0, 0, 5, 5);
Vector2 point1 = new(10, 10);
// Should be the bottom right corner of the rectangle
Test(rect1, point1, expectedClosest: new Vector2(5, 5));
RectangleF rect2 = new(0, 0, 5, 5);
Vector2 point2 = new(2, 10);
// Should be the bottom edge of the rectangle at x = 2 since the point is between the bottom left and bottom right corners
Test(rect2, point2, expectedClosest: new Vector2(2, 5));
RectangleF rect3 = new(0, 0, 5, 5);
Vector2 point3 = new(-10, -3);
// Should be the top left corner of the rectangle
Test(rect3, point3, expectedClosest: new Vector2(0, 0));
RectangleF rect4 = new(0, 0, 100, 100);
Vector2 point4 = new(55, 52);
// Should be the point itself since it's inside the rectangle
Test(rect4, point4, expectedClosest: point4);
RectangleF rect5 = new(0, 0, 100, 100);
Vector2 point5 = new(55, 102);
// Should be the top edge of the rectangle at y = 100 since the point is between the top left and top right corners
Test(rect5, point5, expectedClosest: new Vector2(55, 100));
void Test(RectangleF rect, Vector2 point, Vector2 expectedClosest)
{
var closest = ToolBox.GetClosestPointOnRectangle(rect, point);
closest.Should().BeEquivalentTo(expectedClosest);
}
}
}