From 7bf418f8b2d8c7068f9eeff8cbd55a8d4c310995 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 13 Apr 2024 21:12:49 +0200 Subject: [PATCH] Allow NumberExtensions.GetPoints to include bottom and right coordinates --- CHANGELOG.md | 3 +++ MLEM/Extensions/NumberExtensions.cs | 36 +++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb13ca4..79bcc0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,9 @@ Jump to version: Additions - **Added the ability for formatted (tokenized) strings to be drawn with custom rotation, origin and flipping** +Improvements +- Allow NumberExtensions.GetPoints to include bottom and right coordinates + ### MLEM.Ui Additions - Added the ability to set the anchor that should be used when a tooltip attaches to an element or the mouse diff --git a/MLEM/Extensions/NumberExtensions.cs b/MLEM/Extensions/NumberExtensions.cs index 381f1dd..f12bfdc 100644 --- a/MLEM/Extensions/NumberExtensions.cs +++ b/MLEM/Extensions/NumberExtensions.cs @@ -166,28 +166,44 @@ namespace MLEM.Extensions { /// /// Returns a set of values that are contained in the given . - /// Note that and are inclusive, but and are not. + /// Note that, by default, and are inclusive, but and are not. /// /// The area whose points to get + /// Whether and should be inclusive, rather than exclusive. /// The points contained in the area - public static IEnumerable GetPoints(this Rectangle area) { - for (var x = area.Left; x < area.Right; x++) { - for (var y = area.Top; y < area.Bottom; y++) - yield return new Point(x, y); + public static IEnumerable GetPoints(this Rectangle area, bool bottomRightInclusive = false) { + if (bottomRightInclusive) { + for (var x = area.Left; x <= area.Right; x++) { + for (var y = area.Top; y <= area.Bottom; y++) + yield return new Point(x, y); + } + } else { + for (var x = area.Left; x < area.Right; x++) { + for (var y = area.Top; y < area.Bottom; y++) + yield return new Point(x, y); + } } } /// /// Returns a set of values that are contained in the given . - /// Note that and are inclusive, but and are not. + /// Note that, by default, and are inclusive, but and are not. /// /// The area whose points to get /// The distance that should be traveled between each point that is to be returned + /// Whether and should be inclusive, rather than exclusive. /// The points contained in the area - public static IEnumerable GetPoints(this RectangleF area, float interval = 1) { - for (var x = area.Left; x < area.Right; x += interval) { - for (var y = area.Top; y < area.Bottom; y += interval) - yield return new Vector2(x, y); + public static IEnumerable GetPoints(this RectangleF area, float interval = 1, bool bottomRightInclusive = false) { + if (bottomRightInclusive) { + for (var x = area.Left; x <= area.Right; x += interval) { + for (var y = area.Top; y <= area.Bottom; y += interval) + yield return new Vector2(x, y); + } + } else { + for (var x = area.Left; x < area.Right; x += interval) { + for (var y = area.Top; y < area.Bottom; y += interval) + yield return new Vector2(x, y); + } } }