LayoutTestResult.cs 1.7 KB

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