Fix some IntelliSense messages

This commit is contained in:
Stefan Müller 2025-08-27 17:57:30 +02:00
parent 235178be3d
commit e84746fab0
2 changed files with 13 additions and 10 deletions

View File

@ -3,21 +3,24 @@
internal static class ListExtensions
{
public static bool RemoveUnordered<T>(this List<T> list, T obj)
{
if (obj != null)
{
for (int i = 0; i < list.Count; i++)
{
if (list[i].Equals(obj))
if (obj.Equals(list[i]))
{
list.RemoveUnorderedAt(i);
return true;
}
}
}
return false;
}
public static void RemoveUnorderedAt<T>(this List<T> list, int index)
{
list[index] = list[list.Count - 1];
list[index] = list[^1];
list.RemoveAt(list.Count - 1);
}
}

View File

@ -48,18 +48,18 @@ namespace Quadtree
/// <summary>
/// Stack of vertex indices with their bounding boxes. It is reused for each query.
/// </summary>
private Stack<QuadtreeQuery> _queryStack;
private readonly Stack<QuadtreeQuery> _queryStack;
/// <summary>
/// Stack of vertex indices. It is reused for each query.
/// </summary>
private Stack<int> _vertexStack;
private readonly Stack<int> _vertexStack;
public Quadtree(int maxLeafSize, int maxTreeDepth)
{
_maxLeafSize = maxLeafSize;
_maxTreeDepth = maxTreeDepth;
_vertices = new List<QuadtreeVertex>() { new QuadtreeVertex(-1, 0) };
_vertices = new List<QuadtreeVertex>() { new(-1, 0) };
_items = new List<QuadtreeItem<IWorldObject>>();
_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)
{