LayoutTestResult.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. namespace QuestPDF.LayoutTests.TestEngine;
  2. internal sealed class LayoutTestResult
  3. {
  4. public Size PageSize { get; set; }
  5. public DocumentLayout ActualLayout { get; set; }
  6. public DocumentLayout ExpectedLayout { get; set; }
  7. public sealed class DocumentLayout
  8. {
  9. public ICollection<PageLayout> Pages { get; set; } = new List<PageLayout>();
  10. public bool GeneratesInfiniteLayout { get; set; }
  11. }
  12. public sealed class PageLayout
  13. {
  14. public Size RequiredArea { get; set; }
  15. public ICollection<MockLayoutPosition> Mocks { get; set; }
  16. }
  17. public sealed class MockLayoutPosition
  18. {
  19. public string MockId { get; set; }
  20. public Position Position { get; set; }
  21. public Size Size { get; set; }
  22. }
  23. }
  24. internal static class LayoutTestResultHelpers
  25. {
  26. public static IEnumerable<(LayoutTestResult.MockLayoutPosition Below, LayoutTestResult.MockLayoutPosition Above)> GetOverlappingItems(this ICollection<LayoutTestResult.MockLayoutPosition> items)
  27. {
  28. for (var i = 0; i < items.Count; i++)
  29. {
  30. for (var j = i + 1; j < items.Count; j++)
  31. {
  32. var beforeChild = items.ElementAt(i);
  33. var afterChild = items.ElementAt(j);
  34. var beforeBoundingBox = BoundingBox.From(beforeChild.Position, beforeChild.Size);
  35. var afterBoundingBox = BoundingBox.From(afterChild.Position, afterChild.Size);
  36. var intersection = BoundingBoxExtensions.Intersection(beforeBoundingBox, afterBoundingBox);
  37. if (intersection == null)
  38. continue;
  39. yield return (beforeChild, afterChild);
  40. }
  41. }
  42. }
  43. }