| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using QuestPDF.Infrastructure;
- namespace QuestPDF.LayoutTests.TestEngine;
- internal class BoundingBox
- {
- public double MinX { get; init; }
- public double MinY { get; init; }
- public double MaxX { get; init; }
- public double MaxY { get; init; }
-
- public double Width => MaxX - MinX;
- public double Height => MaxY - MinY;
- public override string ToString() => $"BBox(Min: {MinX:N0}x{MinY:N0}, Max: {MaxX:N0}x{MaxY:N0}, W: {Width:N0}, H: {Height:N0})";
- public static BoundingBox From(Position position, Size size)
- {
- return new BoundingBox
- {
- MinX = position.X,
- MinY = position.Y,
- MaxX = position.X + size.Width,
- MaxY = position.Y + size.Height
- };
- }
- }
- internal static class BoundingBoxExtensions
- {
- public static BoundingBox? Intersection(BoundingBox first, BoundingBox second)
- {
- var common = new BoundingBox
- {
- MinX = Math.Max(first.MinX, second.MinX),
- MinY = Math.Max(first.MinY, second.MinY),
- MaxX = Math.Min(first.MaxX, second.MaxX),
- MaxY = Math.Min(first.MaxY, second.MaxY),
- };
- if (common.Width < 0 || common.Height < 0)
- return null;
- return common;
- }
- }
|