RectangleFTests.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. namespace MonoGame.Extended.Tests;
  2. public sealed class RectangleFTests
  3. {
  4. [Fact]
  5. public void Normalize_WithNegativeWidthAndHeight_AdjustsPositionAndMakesDimensionsPositive()
  6. {
  7. RectangleF rectangle = new RectangleF(32, 32, -32, -32);
  8. rectangle.Normalize();
  9. RectangleF expected = new RectangleF(0, 0, 32, 32);
  10. Assert.Equal(expected, rectangle);
  11. }
  12. [Fact]
  13. public void Normalize_WithNegativeWidthOnly_AdjustsXAndMakesWidthPositive()
  14. {
  15. RectangleF rectangle = new RectangleF(100, 50, -20, 30);
  16. rectangle.Normalize();
  17. RectangleF expected = new RectangleF(80, 50, 20, 30);
  18. Assert.Equal(expected, rectangle);
  19. }
  20. [Fact]
  21. public void Normalize_WithNegativeHeightOnly_AdjustsYAndMakesHeightPositive()
  22. {
  23. RectangleF rectangle = new RectangleF(50, 100, 30, -20);
  24. rectangle.Normalize();
  25. RectangleF expected = new RectangleF(50, 80, 30, 20);
  26. Assert.Equal(expected, rectangle);
  27. }
  28. [Fact]
  29. public void Normalize_WithPositiveDimensions_DoesNotModifyRectangle()
  30. {
  31. RectangleF rectangle = new RectangleF(10, 20, 30, 40);
  32. rectangle.Normalize();
  33. RectangleF expected = new RectangleF(10, 20, 30, 40);
  34. Assert.Equal(expected, rectangle);
  35. }
  36. [Fact]
  37. public void Normalize_StaticMethod_ReturnsNormalizedRectangle()
  38. {
  39. RectangleF rectangle = new RectangleF(32, 32, -32, -32);
  40. RectangleF actual = RectangleF.Normalize(rectangle);
  41. RectangleF expected = new RectangleF(0, 0, 32, 32);
  42. Assert.Equal(expected, actual);
  43. }
  44. [Fact]
  45. public void Normalize_RefOutMethod_OutputsNormalizedRectangle()
  46. {
  47. RectangleF rectangle = new RectangleF(32, 32, -32, -32);
  48. RectangleF.Normalize(ref rectangle, out RectangleF actual);
  49. RectangleF expected = new RectangleF(0, 0, 32, 32);
  50. Assert.Equal(expected, actual);
  51. }
  52. [Trait("Issue", "#793")]
  53. public sealed class RectangleFIssue747
  54. {
  55. [Fact]
  56. public void Normalize_FixesIntersectionIssue_FromGitHubIssue747()
  57. {
  58. // This was the original reported issue
  59. RectangleF shape1 = new RectangleF(32, 32, -32, -32);
  60. RectangleF shape2 = new RectangleF(16, 16, -32, -32);
  61. shape1.Normalize();
  62. shape2.Normalize();
  63. Assert.True(shape1.Intersects(shape2));
  64. }
  65. }
  66. }