From 85d20b64336da6b5a7de35b0dafd68be6d4cf88e Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 13 Apr 2024 21:14:34 +0200 Subject: [PATCH] Added a RectangleF.FromCorners overload that accepts points --- CHANGELOG.md | 1 + MLEM/Misc/RectangleF.cs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79bcc0c..1c2d0b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Jump to version: ### MLEM Additions - **Added the ability for formatted (tokenized) strings to be drawn with custom rotation, origin and flipping** +- Added a RectangleF.FromCorners overload that accepts points Improvements - Allow NumberExtensions.GetPoints to include bottom and right coordinates diff --git a/MLEM/Misc/RectangleF.cs b/MLEM/Misc/RectangleF.cs index 8473f3a..95890a5 100644 --- a/MLEM/Misc/RectangleF.cs +++ b/MLEM/Misc/RectangleF.cs @@ -264,7 +264,7 @@ namespace MLEM.Misc { /// /// The first corner to use /// The second corner to use - /// + /// The created rectangle. public static RectangleF FromCorners(Vector2 corner1, Vector2 corner2) { var minX = Math.Min(corner1.X, corner2.X); var minY = Math.Min(corner1.Y, corner2.Y); @@ -273,6 +273,21 @@ namespace MLEM.Misc { return new RectangleF(minX, minY, maxX - minX, maxY - minY); } + /// + /// Creates a new rectangle based on two corners that form a bounding box. + /// The resulting rectangle will encompass both corners as well as all of the space between them. + /// + /// The first corner to use + /// The second corner to use + /// The created rectangle. + public static RectangleF FromCorners(Point corner1, Point corner2) { + var minX = Math.Min(corner1.X, corner2.X); + var minY = Math.Min(corner1.Y, corner2.Y); + var maxX = Math.Max(corner1.X, corner2.X); + var maxY = Math.Max(corner1.Y, corner2.Y); + return new RectangleF(minX, minY, maxX - minX, maxY - minY); + } + /// /// Converts an int-based rectangle to a float-based rectangle. ///