From 3fbfc1130ed915aa02ed4c250b2f7863d7ef6496 Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Tue, 20 Aug 2019 23:03:27 +0100 Subject: [PATCH] lazily evaluate centroid of rectangle --- src/UglyToad.PdfPig/Geometry/PdfRectangle.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/UglyToad.PdfPig/Geometry/PdfRectangle.cs b/src/UglyToad.PdfPig/Geometry/PdfRectangle.cs index d658653a..b869802b 100644 --- a/src/UglyToad.PdfPig/Geometry/PdfRectangle.cs +++ b/src/UglyToad.PdfPig/Geometry/PdfRectangle.cs @@ -33,7 +33,7 @@ /// /// Centroid point of the rectangle. /// - public PdfPoint Centroid { get; } + public PdfPoint Centroid => new PdfPoint(TopLeft.X + (TopLeft.X - TopLeft.X) / 2, BottomLeft.Y + (TopLeft.Y - BottomLeft.Y) / 2); /// /// Width of the rectangle. @@ -71,7 +71,7 @@ public decimal Bottom => BottomRight.Y; internal PdfRectangle(PdfPoint point1, PdfPoint point2) : this(point1.X, point1.Y, point2.X, point2.Y) { } - internal PdfRectangle(short x1, short y1, short x2, short y2) : this((decimal) x1, y1, x2, y2) { } + internal PdfRectangle(short x1, short y1, short x2, short y2) : this((decimal)x1, y1, x2, y2) { } /// /// Create a new . @@ -110,14 +110,11 @@ 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()) { - } internal PdfRectangle(PdfPoint topLeft, PdfPoint topRight, PdfPoint bottomLeft, PdfPoint bottomRight) @@ -127,8 +124,6 @@ BottomLeft = bottomLeft; BottomRight = bottomRight; - - Centroid = new PdfPoint(topLeft.X + (topRight.X - topLeft.X) / 2, bottomLeft.Y + (topLeft.Y - bottomLeft.Y) / 2); } ///