From e84746fab0d461adad3d3bb9d2fa77dfe6301e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Wed, 27 Aug 2025 17:57:30 +0200 Subject: [PATCH] Fix some IntelliSense messages --- ListExtensions.cs | 13 ++++++++----- Quadtree.cs | 10 +++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ListExtensions.cs b/ListExtensions.cs index a2c358c..9646bc6 100644 --- a/ListExtensions.cs +++ b/ListExtensions.cs @@ -4,12 +4,15 @@ { public static bool RemoveUnordered(this List list, T obj) { - for (int i = 0; i < list.Count; i++) + if (obj != null) { - if (list[i].Equals(obj)) + for (int i = 0; i < list.Count; i++) { - list.RemoveUnorderedAt(i); - return true; + if (obj.Equals(list[i])) + { + list.RemoveUnorderedAt(i); + return true; + } } } return false; @@ -17,7 +20,7 @@ public static void RemoveUnorderedAt(this List list, int index) { - list[index] = list[list.Count - 1]; + list[index] = list[^1]; list.RemoveAt(list.Count - 1); } } diff --git a/Quadtree.cs b/Quadtree.cs index acd0cce..a9a06b2 100644 --- a/Quadtree.cs +++ b/Quadtree.cs @@ -48,18 +48,18 @@ namespace Quadtree /// /// Stack of vertex indices with their bounding boxes. It is reused for each query. /// - private Stack _queryStack; + private readonly Stack _queryStack; /// /// Stack of vertex indices. It is reused for each query. /// - private Stack _vertexStack; + private readonly Stack _vertexStack; public Quadtree(int maxLeafSize, int maxTreeDepth) { _maxLeafSize = maxLeafSize; _maxTreeDepth = maxTreeDepth; - _vertices = new List() { new QuadtreeVertex(-1, 0) }; + _vertices = new List() { new(-1, 0) }; _items = new List>(); _rootBoundingBox = new BoundingBox2(Vector2.Zero, Vector2.Zero); _maxObjectRadius = 0f; @@ -153,7 +153,7 @@ namespace Quadtree QuadtreeQuery query = _queryStack.Pop(); int childIndex = _vertices[query.VertexIndex].FirstChildIndex; - BoundingBox2 halfBounds = new BoundingBox2(query.VertexBounds.Center, query.VertexBounds.Max); + BoundingBox2 halfBounds = new(query.VertexBounds.Center, query.VertexBounds.Max); Vector2 halfSize = halfBounds.Size; QueryProcessChildVertex(inflatedBox, box, childIndex++, halfBounds, resultList, _queryStack); @@ -184,7 +184,7 @@ namespace Quadtree private void ExpandRoot(Vector2 position) { // Finds the new index for the old root vertex and expands the bounds. - QuadtreeVertex newRoot = new QuadtreeVertex(_vertices.Count, -1); + QuadtreeVertex newRoot = new(_vertices.Count, -1); int oldRootIndex = _vertices.Count; if (position.X > _rootBoundingBox.Max.X) {