PathTests.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using Avalonia.Controls.Shapes;
  4. using Avalonia.Layout;
  5. using Avalonia.Media;
  6. using Xunit;
  7. namespace Avalonia.Direct2D1.UnitTests.Controls.Shapes
  8. {
  9. public class PathTests
  10. {
  11. private static readonly RectComparer Compare = new RectComparer();
  12. [Fact]
  13. public void Should_Measure_Expander_Triangle_Correctly()
  14. {
  15. using (AvaloniaLocator.EnterScope())
  16. {
  17. Direct2D1Platform.Initialize();
  18. var target = new Path
  19. {
  20. Data = StreamGeometry.Parse("M 0 2 L 4 6 L 0 10 Z"),
  21. StrokeThickness = 0,
  22. HorizontalAlignment = HorizontalAlignment.Left,
  23. VerticalAlignment = VerticalAlignment.Top,
  24. UseLayoutRounding = false,
  25. };
  26. target.Measure(new Size(100, 100));
  27. target.Arrange(new Rect(0, 0, 100, 100));
  28. Assert.Equal(new Rect(0, 0, 4, 10), target.Bounds, Compare);
  29. }
  30. }
  31. [Fact]
  32. public void Should_Measure_Expander_Triangle_With_Stroke_Correctly()
  33. {
  34. using (AvaloniaLocator.EnterScope())
  35. {
  36. Direct2D1Platform.Initialize();
  37. var target = new Path
  38. {
  39. Data = StreamGeometry.Parse("M 0 2 L 4 6 L 0 10 Z"),
  40. Stroke = Brushes.Black,
  41. StrokeThickness = 2,
  42. HorizontalAlignment = HorizontalAlignment.Left,
  43. VerticalAlignment = VerticalAlignment.Top,
  44. UseLayoutRounding = false,
  45. };
  46. target.Measure(new Size(100, 100));
  47. target.Arrange(new Rect(0, 0, 100, 100));
  48. // Measured geometry with stroke of 2px is:
  49. //
  50. // {-1, -0.414, 6.414, 12.828} (see GeometryTests)
  51. //
  52. // With origin at 0,0 the bounds should equal:
  53. //
  54. // Assert.Equal(new Rect(0, 0, 5.414, 12.414), target.Bounds, compare);
  55. //
  56. // However Path.Measure doesn't correctly handle strokes currently, so testing for
  57. // the (incorrect) current output for now...
  58. Assert.Equal(new Rect(0, 0, 4, 10), target.Bounds, Compare);
  59. }
  60. }
  61. }
  62. }