Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace UglyToad.PdfPig.DocumentLayoutAnalysis
/// https://en.wikipedia.org/wiki/Recursive_X-Y_cut
/// <para>See 'Recursive X-Y Cut using Bounding Boxes of Connected Components' by Jaekyu Ha, Robert M.Haralick and Ihsin T. Phillips</para>
/// </summary>
public class RecursiveXYCut
public static class RecursiveXYCut
{
/// <summary>
/// Get the blocks.
Expand Down
14 changes: 10 additions & 4 deletions src/UglyToad.PdfPig/Geometry/PdfRectangle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public struct PdfRectangle
/// </summary>
public PdfPoint BottomLeft { get; }

/// <summary>
/// Centroid point of the rectangle.
/// </summary>
public PdfPoint Centroid { get; }

/// <summary>
/// Width of the rectangle.
/// </summary>
Expand Down Expand Up @@ -105,15 +110,14 @@ public PdfRectangle(decimal x1, decimal y1, decimal x2, decimal y2)

BottomLeft = new PdfPoint(left, bottom);
BottomRight = new PdfPoint(right, bottom);

Centroid = new PdfPoint(left + (right - left) / 2, bottom + (top - bottom) / 2);
}

internal PdfRectangle(PdfVector topLeft, PdfVector topRight, PdfVector bottomLeft, PdfVector bottomRight)
: this(topLeft.ToPoint(), topRight.ToPoint(), bottomLeft.ToPoint(), bottomRight.ToPoint())
{
TopLeft = topLeft.ToPoint();
TopRight = topRight.ToPoint();

BottomLeft = bottomLeft.ToPoint();
BottomRight = bottomRight.ToPoint();
}

internal PdfRectangle(PdfPoint topLeft, PdfPoint topRight, PdfPoint bottomLeft, PdfPoint bottomRight)
Expand All @@ -123,6 +127,8 @@ internal PdfRectangle(PdfPoint topLeft, PdfPoint topRight, PdfPoint bottomLeft,

BottomLeft = bottomLeft;
BottomRight = bottomRight;

Centroid = new PdfPoint(topLeft.X + (topRight.X - topLeft.X) / 2, bottomLeft.Y + (topLeft.Y - bottomLeft.Y) / 2);
}

/// <summary>
Expand Down