BoundingBox.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using QuestPDF.Infrastructure;
  2. namespace QuestPDF.LayoutTests.TestEngine;
  3. internal class BoundingBox
  4. {
  5. public double MinX { get; init; }
  6. public double MinY { get; init; }
  7. public double MaxX { get; init; }
  8. public double MaxY { get; init; }
  9. public double Width => MaxX - MinX;
  10. public double Height => MaxY - MinY;
  11. public static BoundingBox From(Position position, Size size)
  12. {
  13. return new BoundingBox
  14. {
  15. MinX = position.X,
  16. MinY = position.Y,
  17. MaxX = position.X + size.Width,
  18. MaxY = position.Y + size.Height
  19. };
  20. }
  21. }
  22. internal static class BoundingBoxExtensions
  23. {
  24. public static BoundingBox? Intersection(BoundingBox first, BoundingBox second)
  25. {
  26. var common = new BoundingBox
  27. {
  28. MinX = Math.Max(first.MinX, second.MinX),
  29. MinY = Math.Max(first.MinY, second.MinY),
  30. MaxX = Math.Min(first.MaxX, second.MaxX),
  31. MaxY = Math.Min(first.MaxY, second.MaxY),
  32. };
  33. if (common.Width < 0 || common.Height < 0)
  34. return null;
  35. return common;
  36. }
  37. }