diff --git a/src/UglyToad.PdfPig/Geometry/PdfRectangle.cs b/src/UglyToad.PdfPig/Geometry/PdfRectangle.cs
index df8e985b..d658653a 100644
--- a/src/UglyToad.PdfPig/Geometry/PdfRectangle.cs
+++ b/src/UglyToad.PdfPig/Geometry/PdfRectangle.cs
@@ -30,6 +30,11 @@
///
public PdfPoint BottomLeft { get; }
+ ///
+ /// Centroid point of the rectangle.
+ ///
+ public PdfPoint Centroid { get; }
+
///
/// Width of the rectangle.
///
@@ -105,15 +110,14 @@
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)
@@ -123,6 +127,8 @@
BottomLeft = bottomLeft;
BottomRight = bottomRight;
+
+ Centroid = new PdfPoint(topLeft.X + (topRight.X - topLeft.X) / 2, bottomLeft.Y + (topLeft.Y - bottomLeft.Y) / 2);
}
///