From dc97615fd46f40ccf3bcbd86fedfed46d13c7b2f Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Tue, 27 May 2025 19:26:50 +1000 Subject: [PATCH] Add some Box2i methods (#5969) Equivalent to Box2. --- Robust.Shared.Maths/Box2i.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Robust.Shared.Maths/Box2i.cs b/Robust.Shared.Maths/Box2i.cs index 4c1944d50..f0596ed57 100644 --- a/Robust.Shared.Maths/Box2i.cs +++ b/Robust.Shared.Maths/Box2i.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.Contracts; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -101,6 +102,7 @@ namespace Robust.Shared.Maths /// /// Returns the smallest rectangle that contains both of the rectangles. /// + [Pure] public readonly Box2i Union(in Box2i other) { var botLeft = Vector2i.ComponentMin(BottomLeft, other.BottomLeft); @@ -207,6 +209,7 @@ namespace Robust.Shared.Maths /// /// Multiplies each side of the box by the scalar. /// + [Pure] public Box2i Scale(int scalar) { return new Box2i( @@ -215,6 +218,21 @@ namespace Robust.Shared.Maths Right * scalar, Top * scalar); } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [Pure] + public bool Intersects(in Box2i other) + { + return other.Bottom <= this.Top && other.Top >= this.Bottom && other.Right >= this.Left && + other.Left <= this.Right; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [Pure] + public readonly Box2i Enlarged(int size) + { + return new(Left - size, Bottom - size, Right + size, Top + size); + } } ///