2
0

BoundingBox.cs 1.1 KB

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