From 07dc369c2c5eb8bb9f7e3878b54b2ab1aa426d6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Wed, 27 Aug 2025 17:47:08 +0200 Subject: [PATCH] Add BoundingBox2 implementation --- BoundingBox.cs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/BoundingBox.cs b/BoundingBox.cs index 01088e1..9d2f037 100644 --- a/BoundingBox.cs +++ b/BoundingBox.cs @@ -6,13 +6,19 @@ namespace BoundingBox public class BoundingBox2 { + /// + /// Vector containing the lowest X and Y coordinates contained in the bounding box. + /// public Vector2 Min; + /// + /// Vector containing the highest X and Y coordinates contained in the bounding box. + /// public Vector2 Max; - public Vector2 Center => ; + public Vector2 Center => (Max + Min) * 0.5f; - public Vector2 Size =>; + public Vector2 Size => Max - Min; public BoundingBox2(Vector2 min, Vector2 max) { @@ -22,21 +28,34 @@ namespace BoundingBox public bool Contains(Vector2 position) { - + return Min.X <= position.X && position.X <= Max.X && Min.Y <= position.Y && position.Y <= Max.Y; } public IntersectionType Intersects(BoundingBox2 other) { + if (Min.X <= other.Min.X && other.Max.X <= Max.X && Min.Y <= other.Min.Y && other.Max.Y <= Max.Y) + { + return IntersectionType.Contains; + } + if ((other.Max.X <= Min.X || Max.X <= other.Min.X) && (other.Max.Y <= Min.Y || Max.Y <= other.Min.Y)) + { + return IntersectionType.Disjoint; + } + return IntersectionType.Intersects; } public void Translate(Vector2 translation) { - + Min += translation; + Max += translation; } public void Expand(float expansion) { - + Min.X -= expansion; + Min.Y -= expansion; + Max.X += expansion; + Max.Y += expansion; } } }