DrawOperationTests.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using Avalonia.Media;
  3. using Avalonia.Platform;
  4. using Avalonia.Rendering.SceneGraph;
  5. using Xunit;
  6. namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
  7. {
  8. public class DrawOperationTests
  9. {
  10. [Fact]
  11. public void Empty_Bounds_Remain_Empty()
  12. {
  13. var target = new TestDrawOperation(Rect.Empty, Matrix.Identity, null);
  14. Assert.Equal(Rect.Empty, target.Bounds);
  15. }
  16. [Theory]
  17. [InlineData(10, 10, 10, 10, 1, 1, 1, 9, 9, 12, 12)]
  18. [InlineData(10, 10, 10, 10, 1, 1, 2, 9, 9, 12, 12)]
  19. [InlineData(10, 10, 10, 10, 1.5, 1.5, 1, 14, 14, 17, 17)]
  20. public void Rectangle_Bounds_Are_Snapped_To_Pixels(
  21. double x,
  22. double y,
  23. double width,
  24. double height,
  25. double scaleX,
  26. double scaleY,
  27. double? penThickness,
  28. double expectedX,
  29. double expectedY,
  30. double expectedWidth,
  31. double expectedHeight)
  32. {
  33. var target = new TestDrawOperation(
  34. new Rect(x, y, width, height),
  35. Matrix.CreateScale(scaleX, scaleY),
  36. penThickness.HasValue ? new Pen(Brushes.Black, penThickness.Value) : null);
  37. Assert.Equal(new Rect(expectedX, expectedY, expectedWidth, expectedHeight), target.Bounds);
  38. }
  39. private class TestDrawOperation : DrawOperation
  40. {
  41. public TestDrawOperation(Rect bounds, Matrix transform, Pen pen)
  42. :base(bounds, transform, pen)
  43. {
  44. }
  45. public override bool HitTest(Point p) => false;
  46. public override void Render(IDrawingContextImpl context) { }
  47. }
  48. }
  49. }