Adding Centroid to PdfRectangle.

This commit is contained in:
BobLd
2019-08-09 17:22:16 +01:00
parent d6757e69cb
commit ac065e988a

View File

@@ -30,6 +30,11 @@
/// </summary> /// </summary>
public PdfPoint BottomLeft { get; } public PdfPoint BottomLeft { get; }
/// <summary>
/// Centroid point of the rectangle.
/// </summary>
public PdfPoint Centroid { get; }
/// <summary> /// <summary>
/// Width of the rectangle. /// Width of the rectangle.
/// </summary> /// </summary>
@@ -105,15 +110,14 @@
BottomLeft = new PdfPoint(left, bottom); BottomLeft = new PdfPoint(left, bottom);
BottomRight = new PdfPoint(right, 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) 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) internal PdfRectangle(PdfPoint topLeft, PdfPoint topRight, PdfPoint bottomLeft, PdfPoint bottomRight)
@@ -123,6 +127,8 @@
BottomLeft = bottomLeft; BottomLeft = bottomLeft;
BottomRight = bottomRight; BottomRight = bottomRight;
Centroid = new PdfPoint(topLeft.X + (topRight.X - topLeft.X) / 2, bottomLeft.Y + (topLeft.Y - bottomLeft.Y) / 2);
} }
/// <summary> /// <summary>