Skip to content

Commit d4afa21

Browse files
committed
Add Point/Rectangle overloads
1 parent 81e48da commit d4afa21

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

SharpMap/Rendering/VectorRenderer.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,25 @@ internal static Rectangle ToRectangle(this RectangleF self)
973973
(int)Math.Ceiling(self.Bottom));
974974
}
975975

976+
977+
/// <summary>
978+
/// Utility method to return Rectangle enclosing given RectangleF.
979+
/// Top-left coordinate is rounded towards origin, while bottom-right coordinate is rounded away from origin.
980+
/// </summary>
981+
/// <param name="self"></param>
982+
/// <returns></returns>
983+
internal static Rectangle ToRectangle(this System.Drawing.Point[] self)
984+
{
985+
if (self.Length < 4) return Rectangle.Empty;
986+
987+
int minX = self.Min(p => p.X);
988+
int maxX = self.Max(p => p.X);
989+
int minY = self.Min(p => p.Y);
990+
int maxY = self.Max(p => p.Y);
991+
992+
return new Rectangle(minX, minY, maxX - minX, maxY - minY);
993+
}
994+
976995
/// <summary>
977996
/// Utility method to return enclosing rectangle. Source array must have 4 or more points.
978997
/// </summary>
@@ -1006,6 +1025,22 @@ internal static PointF[] ToPointArray(this RectangleF self)
10061025
};
10071026
}
10081027

1028+
/// <summary>
1029+
/// Utility method to return points defining rectangle, ordered clockwise from top left
1030+
/// </summary>
1031+
/// <param name="self"></param>
1032+
/// <returns></returns>
1033+
internal static System.Drawing.Point[] ToPointArray(this Rectangle self)
1034+
{
1035+
return new[]
1036+
{
1037+
new System.Drawing.Point(self.X, self.Y),
1038+
new System.Drawing.Point(self.X + self.Width, self.Y),
1039+
new System.Drawing.Point(self.X + self.Width, self.Y +self.Height),
1040+
new System.Drawing.Point(self.X, self.Y + self.Height)
1041+
};
1042+
}
1043+
10091044
/// <summary>
10101045
/// Basic rectilinear union. Rectangles are assumed to be a common graphics coordinate system.
10111046
/// </summary>

0 commit comments

Comments
 (0)