mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-29 23:58:34 +01:00
added a utility method for getting the points contained in a rectangle
This commit is contained in:
parent
f3cf8dcc70
commit
a75d04cffc
1 changed files with 28 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using MLEM.Misc;
|
using MLEM.Misc;
|
||||||
|
|
||||||
|
@ -158,6 +159,33 @@ namespace MLEM.Extensions {
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a set of <see cref="Point"/> values that are contained in the given <see cref="Rectangle"/>.
|
||||||
|
/// Note that <see cref="Rectangle.Left"/> and <see cref="Rectangle.Top"/> are inclusive, but <see cref="Rectangle.Right"/> and <see cref="Rectangle.Bottom"/> are not.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="area">The area whose points to get</param>
|
||||||
|
/// <returns>The points contained in the area</returns>
|
||||||
|
public static IEnumerable<Point> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a set of <see cref="Vector2"/> values that are contained in the given <see cref="RectangleF"/>.
|
||||||
|
/// Note that <see cref="RectangleF.Left"/> and <see cref="RectangleF.Top"/> are inclusive, but <see cref="RectangleF.Right"/> and <see cref="RectangleF.Bottom"/> are not.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="area">The area whose points to get</param>
|
||||||
|
/// <param name="interval">The distance that should be traveled between each point that is to be returned</param>
|
||||||
|
/// <returns>The points contained in the area</returns>
|
||||||
|
public static IEnumerable<Vector2> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Turns the given 3-dimensional vector into a 2-dimensional vector by chopping off the z coordinate.
|
/// Turns the given 3-dimensional vector into a 2-dimensional vector by chopping off the z coordinate.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in a new issue