From 59331dc5b5e219be31a51dbcc242b4ba6acef955 Mon Sep 17 00:00:00 2001 From: Andreas Torebring Date: Sat, 19 Nov 2022 01:58:23 +0100 Subject: [PATCH 1/5] Use actual target bounds when testing collision --- .../QuadTree/CollisionComponent.cs | 3 +- .../QuadTree/QuadTreeData.cs | 7 +- .../CollisionComponentTests.cs | 141 +++++++++++++----- 3 files changed, 111 insertions(+), 40 deletions(-) diff --git a/src/cs/MonoGame.Extended.Collisions/QuadTree/CollisionComponent.cs b/src/cs/MonoGame.Extended.Collisions/QuadTree/CollisionComponent.cs index 8e31d347..26d3d280 100644 --- a/src/cs/MonoGame.Extended.Collisions/QuadTree/CollisionComponent.cs +++ b/src/cs/MonoGame.Extended.Collisions/QuadTree/CollisionComponent.cs @@ -54,7 +54,6 @@ namespace MonoGame.Extended.Collisions }; target.OnCollision(collisionInfo); - value.Bounds = value.Target.Bounds; } _collisionTree.Insert(value); } @@ -230,4 +229,4 @@ namespace MonoGame.Extended.Collisions #endregion } -} \ No newline at end of file +} diff --git a/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTreeData.cs b/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTreeData.cs index d7046d5c..94a706a1 100644 --- a/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTreeData.cs +++ b/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTreeData.cs @@ -12,7 +12,6 @@ namespace MonoGame.Extended.Collisions public QuadtreeData(ICollisionActor target) { Target = target; - Bounds = target.Bounds; } public void RemoveParent(Quadtree parent) @@ -39,7 +38,7 @@ namespace MonoGame.Extended.Collisions /// /// Gets or sets the Target for collision. /// - public ICollisionActor Target { get; set; } + public ICollisionActor Target { get; } /// /// Gets or sets whether Target has had its collision handled this @@ -60,6 +59,6 @@ namespace MonoGame.Extended.Collisions /// /// Gets or sets the bounding box for collision detection. /// - public IShapeF Bounds { get; set; } + public IShapeF Bounds => Target.Bounds; } -} \ No newline at end of file +} diff --git a/src/cs/Tests/MonoGame.Extended.Collisions.Tests/CollisionComponentTests.cs b/src/cs/Tests/MonoGame.Extended.Collisions.Tests/CollisionComponentTests.cs index 77f3c3c9..60c1b09d 100644 --- a/src/cs/Tests/MonoGame.Extended.Collisions.Tests/CollisionComponentTests.cs +++ b/src/cs/Tests/MonoGame.Extended.Collisions.Tests/CollisionComponentTests.cs @@ -13,16 +13,14 @@ namespace MonoGame.Extended.Collisions.Tests /// public class CollisionComponentTests { - private CollisionComponent collisionComponent; - - private GameTime _gameTime = new GameTime(TimeSpan.Zero, TimeSpan.FromMilliseconds(16)); + private readonly CollisionComponent _collisionComponent; + private readonly GameTime _gameTime = new GameTime(TimeSpan.Zero, TimeSpan.FromMilliseconds(16)); public CollisionComponentTests() { - collisionComponent = new CollisionComponent(new RectangleF(Point2.Zero, new Point2(10, 10))); + _collisionComponent = new CollisionComponent(new RectangleF(Point2.Zero, new Point2(10, 10))); } - #region Circle Circle [Fact] @@ -46,9 +44,9 @@ namespace MonoGame.Extended.Collisions.Tests }; Assert.True(shape1.Intersects(shape2)); - collisionComponent.Insert(actor1); - collisionComponent.Insert(actor2); - collisionComponent.Update(_gameTime); + _collisionComponent.Insert(actor1); + _collisionComponent.Insert(actor2); + _collisionComponent.Update(_gameTime); Assert.True(Math.Abs(actor1.Position.Y - -4f) < float.Epsilon); } @@ -73,9 +71,9 @@ namespace MonoGame.Extended.Collisions.Tests }; Assert.True(shape1.Intersects(shape2)); - collisionComponent.Insert(actor1); - collisionComponent.Insert(actor2); - collisionComponent.Update(_gameTime); + _collisionComponent.Insert(actor1); + _collisionComponent.Insert(actor2); + _collisionComponent.Update(_gameTime); // Actor should have moved up because the distance is shorter. Assert.True(actor1.Position.Y > actor2.Position.Y); // The circle centers should be about 4 units away after moving @@ -103,9 +101,9 @@ namespace MonoGame.Extended.Collisions.Tests }; Assert.True(shape1.Intersects(shape2)); - collisionComponent.Insert(actor1); - collisionComponent.Insert(actor2); - collisionComponent.Update(_gameTime); + _collisionComponent.Insert(actor1); + _collisionComponent.Insert(actor2); + _collisionComponent.Update(_gameTime); // Actor should have moved up because the distance is shorter. Assert.True(actor1.Position.Y > actor2.Position.Y); // The circle centers should be about 4 units away after moving @@ -134,9 +132,9 @@ namespace MonoGame.Extended.Collisions.Tests }; Assert.True(shape1.Intersects(shape2)); - collisionComponent.Insert(actor1); - collisionComponent.Insert(actor2); - collisionComponent.Update(_gameTime); + _collisionComponent.Insert(actor1); + _collisionComponent.Insert(actor2); + _collisionComponent.Update(_gameTime); // Actor should have moved up because the distance is shorter. Assert.True(actor1.Position.Y > actor2.Position.Y); // The circle centers should be about 4 units away after moving @@ -169,9 +167,9 @@ namespace MonoGame.Extended.Collisions.Tests }; Assert.True(shape1.Intersects(shape2)); - collisionComponent.Insert(actor1); - collisionComponent.Insert(actor2); - collisionComponent.Update(_gameTime); + _collisionComponent.Insert(actor1); + _collisionComponent.Insert(actor2); + _collisionComponent.Update(_gameTime); Assert.True(Math.Abs(actor1.Position.X - 0.0f) < float.Epsilon); Assert.True(Math.Abs(actor1.Position.Y - 3.0f) < float.Epsilon); } @@ -198,9 +196,9 @@ namespace MonoGame.Extended.Collisions.Tests }; Assert.True(shape1.Intersects(shape2)); - collisionComponent.Insert(actor1); - collisionComponent.Insert(actor2); - collisionComponent.Update(_gameTime); + _collisionComponent.Insert(actor1); + _collisionComponent.Insert(actor2); + _collisionComponent.Update(_gameTime); Assert.True(Math.Abs(actor1.Position.X - 0.0f) < float.Epsilon); Assert.True(Math.Abs(actor1.Position.Y - -2.0f) < float.Epsilon); } @@ -227,9 +225,9 @@ namespace MonoGame.Extended.Collisions.Tests }; Assert.True(shape1.Intersects(shape2)); - collisionComponent.Insert(actor1); - collisionComponent.Insert(actor2); - collisionComponent.Update(_gameTime); + _collisionComponent.Insert(actor1); + _collisionComponent.Insert(actor2); + _collisionComponent.Update(_gameTime); Assert.True(Math.Abs(actor1.Position.X - 2.0f) < float.Epsilon); Assert.True(Math.Abs(actor1.Position.Y - 3.0f) < float.Epsilon); } @@ -260,9 +258,9 @@ namespace MonoGame.Extended.Collisions.Tests }; Assert.True(shape1.Intersects(shape2)); - collisionComponent.Insert(actor1); - collisionComponent.Insert(actor2); - collisionComponent.Update(_gameTime); + _collisionComponent.Insert(actor1); + _collisionComponent.Insert(actor2); + _collisionComponent.Update(_gameTime); Assert.True(Math.Abs(actor1.Position.X - 0.0f) < float.Epsilon); Assert.True(Math.Abs(actor1.Position.Y - 1.0f) < float.Epsilon); } @@ -289,15 +287,90 @@ namespace MonoGame.Extended.Collisions.Tests }; Assert.True(shape1.Intersects(shape2)); - collisionComponent.Insert(actor1); - collisionComponent.Insert(actor2); - collisionComponent.Update(_gameTime); + _collisionComponent.Insert(actor1); + _collisionComponent.Insert(actor2); + _collisionComponent.Update(_gameTime); Assert.True(Math.Abs(actor1.Position.X - 4.0f) < float.Epsilon); Assert.True(Math.Abs(actor1.Position.Y - 3.0f) < float.Epsilon); } - #endregion + public class Behaviours : CollisionComponentTests + { + [Fact] + public void Actors_is_colliding() + { + var staticBounds = new RectangleF(new Point2(0, 0), new Size2(1, 1)); + var anotherStaticBounds = new RectangleF(new Point2(0, 0), new Size2(1, 1)); + var staticActor = new CollisionIndicatingActor(staticBounds); + var anotherStaticActor = new CollisionIndicatingActor(anotherStaticBounds); + _collisionComponent.Insert(staticActor); + _collisionComponent.Insert(anotherStaticActor); + + _collisionComponent.Update(_gameTime); + + Assert.True(staticActor.IsColliding); + Assert.True(anotherStaticActor.IsColliding); + } + + [Fact] + public void Actors_is_not_colliding_when_dynamic_actor_is_moved_out_of_collision_bounds() + { + var staticBounds = new RectangleF(new Point2(0, 0), new Size2(1, 1)); + var dynamicBounds = new RectangleF(new Point2(0, 0), new Size2(1, 1)); + var staticActor = new CollisionIndicatingActor(staticBounds); + var dynamicActor = new CollisionIndicatingActor(dynamicBounds); + _collisionComponent.Insert(staticActor); + _collisionComponent.Insert(dynamicActor); + dynamicActor.MoveTo(new Point2(2, 2)); + + _collisionComponent.Update(_gameTime); + + Assert.False(staticActor.IsColliding); + Assert.False(dynamicActor.IsColliding); + } + + [Fact] + public void Actors_is_colliding_when_dynamic_actor_is_moved_into_collision_bounds() + { + var staticBounds = new RectangleF(new Point2(0, 0), new Size2(1, 1)); + var dynamicBounds = new RectangleF(new Point2(2, 2), new Size2(1, 1)); + var staticActor = new CollisionIndicatingActor(staticBounds); + var dynamicActor = new CollisionIndicatingActor(dynamicBounds); + _collisionComponent.Insert(staticActor); + _collisionComponent.Insert(dynamicActor); + dynamicActor.MoveTo(new Point2(0, 0)); + + _collisionComponent.Update(_gameTime); + + Assert.True(staticActor.IsColliding); + Assert.True(dynamicActor.IsColliding); + } + + private class CollisionIndicatingActor : ICollisionActor + { + private RectangleF _bounds; + + public CollisionIndicatingActor(RectangleF bounds) + { + _bounds = bounds; + } + + public IShapeF Bounds => _bounds; + + public void OnCollision(CollisionEventArgs collisionInfo) + { + IsColliding = true; + } + + public bool IsColliding { get; private set; } + + public void MoveTo(Point2 position) + { + _bounds = new RectangleF(position, _bounds.Size); + } + } + } } -} \ No newline at end of file +} From a5db880e42860690eef2e32d5784a2f8e3938f77 Mon Sep 17 00:00:00 2001 From: Andreas Torebring Date: Sat, 19 Nov 2022 01:59:51 +0100 Subject: [PATCH 2/5] Cleanup --- .../QuadTree/QuadTreeData.cs | 114 +++++++++--------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTreeData.cs b/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTreeData.cs index 94a706a1..1e6c32e9 100644 --- a/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTreeData.cs +++ b/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTreeData.cs @@ -1,64 +1,64 @@ using System.Collections.Generic; using System.Linq; -namespace MonoGame.Extended.Collisions +namespace MonoGame.Extended.Collisions; + +/// +/// Data structure for the quad tree. +/// Holds the entity and collision data for it. +/// +public class QuadtreeData { - /// - /// Data structure for the quad tree. - /// Holds the entity and collision data for it. - /// - public class QuadtreeData + public QuadtreeData(ICollisionActor target) { - public QuadtreeData(ICollisionActor target) - { - Target = target; - } - - public void RemoveParent(Quadtree parent) - { - Parents.Remove(parent); - } - - public void AddParent(Quadtree parent) - { - Parents.Add(parent); - } - - public void RemoveFromAllParents() - { - foreach (Quadtree parent in Parents.ToList()) - { - parent.Remove(this); - } - Parents.Clear(); - } - - public HashSet Parents = new HashSet(); - - /// - /// Gets or sets the Target for collision. - /// - public ICollisionActor Target { get; } - - /// - /// Gets or sets whether Target has had its collision handled this - /// iteration. - /// - public bool Dirty { get; private set; } - - public void MarkDirty() - { - Dirty = true; - } - - public void MarkClean() - { - Dirty = false; - } - - /// - /// Gets or sets the bounding box for collision detection. - /// - public IShapeF Bounds => Target.Bounds; + Target = target; } + + public void RemoveParent(Quadtree parent) + { + Parents.Remove(parent); + } + + public void AddParent(Quadtree parent) + { + Parents.Add(parent); + } + + public void RemoveFromAllParents() + { + foreach (Quadtree parent in Parents.ToList()) + { + parent.Remove(this); + } + + Parents.Clear(); + } + + public HashSet Parents = new HashSet(); + + /// + /// Gets or sets the Target for collision. + /// + public ICollisionActor Target { get; } + + /// + /// Gets or sets whether Target has had its collision handled this + /// iteration. + /// + public bool Dirty { get; private set; } + + public void MarkDirty() + { + Dirty = true; + } + + public void MarkClean() + { + Dirty = false; + } + + /// + /// Gets or sets the bounding box for collision detection. + /// + public IShapeF Bounds => Target.Bounds; } From 10a55d34f0c406d8541949f71b8cc9f458fcdabe Mon Sep 17 00:00:00 2001 From: Andreas Torebring Date: Sat, 19 Nov 2022 02:10:49 +0100 Subject: [PATCH 3/5] Refactor Encapsulate a public property (Parents). Added xml-comments (to fix some compilation warnings) --- .../QuadTree/CollisionComponent.cs | 14 ++-- .../QuadTree/QuadTree.cs | 80 ++++++++++--------- .../QuadTree/QuadTreeData.cs | 48 ++++++++--- 3 files changed, 82 insertions(+), 60 deletions(-) diff --git a/src/cs/MonoGame.Extended.Collisions/QuadTree/CollisionComponent.cs b/src/cs/MonoGame.Extended.Collisions/QuadTree/CollisionComponent.cs index 26d3d280..1caf96ac 100644 --- a/src/cs/MonoGame.Extended.Collisions/QuadTree/CollisionComponent.cs +++ b/src/cs/MonoGame.Extended.Collisions/QuadTree/CollisionComponent.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using Microsoft.Xna.Framework; namespace MonoGame.Extended.Collisions @@ -12,8 +11,7 @@ namespace MonoGame.Extended.Collisions /// public class CollisionComponent : SimpleGameComponent { - private readonly Dictionary _targetDataDictionary = - new Dictionary(); + private readonly Dictionary _targetDataDictionary = new(); private readonly Quadtree _collisionTree; @@ -47,11 +45,11 @@ namespace MonoGame.Extended.Collisions // Generate list of collision Infos foreach (var other in collisions) { - var collisionInfo = new CollisionEventArgs() - { - Other = other.Target, - PenetrationVector = CalculatePenetrationVector(value.Bounds, other.Bounds) - }; + var collisionInfo = new CollisionEventArgs + { + Other = other.Target, + PenetrationVector = CalculatePenetrationVector(value.Bounds, other.Bounds) + }; target.OnCollision(collisionInfo); } diff --git a/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTree.cs b/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTree.cs index df4df180..9e34d306 100644 --- a/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTree.cs +++ b/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTree.cs @@ -74,9 +74,9 @@ namespace MonoGame.Extended.Collisions } } } - for (var i = 0; i < dirtyItems.Count; i++) + foreach (var quadtreeData in dirtyItems) { - dirtyItems[i].MarkClean(); + quadtreeData.MarkClean(); } return objectCount; } @@ -87,8 +87,8 @@ namespace MonoGame.Extended.Collisions /// Data being inserted. public void Insert(QuadtreeData data) { - var actorBounds = data.Target.Bounds; - + var actorBounds = data.Bounds; + // Object doesn't fit into this node. if (!NodeBounds.Intersects(actorBounds)) { @@ -126,7 +126,7 @@ namespace MonoGame.Extended.Collisions } else { - throw new InvalidOperationException($"Cannot remove from a non leaf {nameof(Quadtree)}"); + throw new InvalidOperationException($"Cannot remove from a non leaf {nameof(Quadtree)}"); } } @@ -135,49 +135,51 @@ namespace MonoGame.Extended.Collisions /// public void Shake() { - if (!IsLeaf) + if (IsLeaf) { - List dirtyItems = new List(); + return; + } - var numObjects = NumTargets(); - if (numObjects == 0) + List dirtyItems = new List(); + + var numObjects = NumTargets(); + if (numObjects == 0) + { + Children.Clear(); + } + else if (numObjects < MaxObjectsPerNode) + { + var process = new Queue(); + process.Enqueue(this); + while (process.Count > 0) { - Children.Clear(); - } - else if (numObjects < MaxObjectsPerNode) - { - var process = new Queue(); - process.Enqueue(this); - while (process.Count > 0) + var processing = process.Dequeue(); + if (!processing.IsLeaf) { - var processing = process.Dequeue(); - if (!processing.IsLeaf) + foreach (var subTree in processing.Children) { - foreach (var subTree in processing.Children) - { - process.Enqueue(subTree); - } + process.Enqueue(subTree); } - else + } + else + { + foreach (var data in processing.Contents) { - foreach (var data in processing.Contents) + if (data.Dirty == false) { - if (data.Dirty == false) - { - AddToLeaf(data); - data.MarkDirty(); - dirtyItems.Add(data); - } + AddToLeaf(data); + data.MarkDirty(); + dirtyItems.Add(data); } } } - Children.Clear(); } + Children.Clear(); + } - for (var i = 0; i < dirtyItems.Count; i++) - { - dirtyItems[i].MarkClean(); - } + foreach (var quadtreeData in dirtyItems) + { + quadtreeData.MarkClean(); } } @@ -241,16 +243,16 @@ namespace MonoGame.Extended.Collisions { var recursiveResult = new List(); QueryWithoutReset(area, recursiveResult); - for (var i = 0; i < recursiveResult.Count; i++) + foreach (var quadtreeData in recursiveResult) { - recursiveResult[i].MarkClean(); + quadtreeData.MarkClean(); } return recursiveResult; } private void QueryWithoutReset(IShapeF area, List recursiveResult) { - if (!NodeBounds.Intersects(area)) + if (!NodeBounds.Intersects(area)) return; if (IsLeaf) @@ -273,4 +275,4 @@ namespace MonoGame.Extended.Collisions } } } -} \ No newline at end of file +} diff --git a/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTreeData.cs b/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTreeData.cs index 1e6c32e9..cb50d3b5 100644 --- a/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTreeData.cs +++ b/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTreeData.cs @@ -9,37 +9,58 @@ namespace MonoGame.Extended.Collisions; /// public class QuadtreeData { + private readonly ICollisionActor _target; + private readonly HashSet _parents = new(); + + /// + /// Initialize a new instance of QuadTreeData. + /// + /// public QuadtreeData(ICollisionActor target) { - Target = target; + _target = target; } + /// + /// Remove a parent node. + /// + /// public void RemoveParent(Quadtree parent) { - Parents.Remove(parent); + _parents.Remove(parent); } + /// + /// Add a parent node. + /// + /// public void AddParent(Quadtree parent) { - Parents.Add(parent); + _parents.Add(parent); } + /// + /// Remove all parent nodes from this node. + /// public void RemoveFromAllParents() { - foreach (Quadtree parent in Parents.ToList()) + foreach (var parent in _parents.ToList()) { parent.Remove(this); } - Parents.Clear(); + _parents.Clear(); } - public HashSet Parents = new HashSet(); + /// + /// Gets the bounding box for collision detection. + /// + public IShapeF Bounds => _target.Bounds; /// - /// Gets or sets the Target for collision. + /// Gets the collision actor target. /// - public ICollisionActor Target { get; } + public ICollisionActor Target => _target; /// /// Gets or sets whether Target has had its collision handled this @@ -47,18 +68,19 @@ public class QuadtreeData /// public bool Dirty { get; private set; } + /// + /// Mark node as dirty. + /// public void MarkDirty() { Dirty = true; } + /// + /// Mark node as clean, i.e. not dirty. + /// public void MarkClean() { Dirty = false; } - - /// - /// Gets or sets the bounding box for collision detection. - /// - public IShapeF Bounds => Target.Bounds; } From 60064df2650a15de0ea05a7cce5700c86bd2cc66 Mon Sep 17 00:00:00 2001 From: Andreas Torebring Date: Sun, 20 Nov 2022 16:54:09 +0100 Subject: [PATCH 4/5] Format comments and fix spelling --- .../QuadTree/QuadTree.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTree.cs b/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTree.cs index 9e34d306..bbb46990 100644 --- a/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTree.cs +++ b/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTree.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; namespace MonoGame.Extended.Collisions { /// - /// Class for doing collision handling with a quad tree. + /// Class for doing collision handling with a quad tree. /// public class Quadtree { @@ -15,7 +15,7 @@ namespace MonoGame.Extended.Collisions protected HashSet Contents = new HashSet(); /// - /// Creates a quad tree with the given bounds. + /// Creates a quad tree with the given bounds. /// /// The bounds of the new quad tree. public Quadtree(RectangleF bounds) @@ -30,17 +30,17 @@ namespace MonoGame.Extended.Collisions protected int MaxObjectsPerNode { get; set; } = DefaultMaxObjectsPerNode; /// - /// Gets the bounds of the area contained in this quad tree. + /// Gets the bounds of the area contained in this quad tree. /// public RectangleF NodeBounds { get; protected set; } /// - /// Gets whether the current node is a leaf node. + /// Gets whether the current node is a leaf node. /// public bool IsLeaf => Children.Count == 0; /// - /// Counts the number of unique targets in the current Quadtree. + /// Counts the number of unique targets in the current Quadtree. /// /// Returns the targets of objects found. public int NumTargets() @@ -82,7 +82,7 @@ namespace MonoGame.Extended.Collisions } /// - /// Inserts the data into the tree. + /// Inserts the data into the tree. /// /// Data being inserted. public void Insert(QuadtreeData data) @@ -114,7 +114,7 @@ namespace MonoGame.Extended.Collisions } /// - /// Removes data from the Quadtree + /// Removes data from the Quadtree /// /// The data to be removed. public void Remove(QuadtreeData data) @@ -131,7 +131,7 @@ namespace MonoGame.Extended.Collisions } /// - /// Removes unneccesary leaf nodes and simplifies the quad tree. + /// Removes unnecessary leaf nodes and simplifies the quad tree. /// public void Shake() { @@ -190,7 +190,7 @@ namespace MonoGame.Extended.Collisions } /// - /// Splits a quadtree into quadrants. + /// Splits a quadtree into quadrants. /// public void Split() { @@ -235,7 +235,7 @@ namespace MonoGame.Extended.Collisions } /// - /// Queries the quadtree for targets that intersect with the given area. + /// Queries the quadtree for targets that intersect with the given area. /// /// The area to query for overlapping targets /// A unique list of targets intersected by area. From 40a2621aa2bcea3e71f79a6934552fb2ae9df259 Mon Sep 17 00:00:00 2001 From: Andreas Torebring Date: Sun, 20 Nov 2022 17:00:01 +0100 Subject: [PATCH 5/5] Add comments for public fields and properties --- .../QuadTree/QuadTree.cs | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTree.cs b/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTree.cs index bbb46990..1bf7bdab 100644 --- a/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTree.cs +++ b/src/cs/MonoGame.Extended.Collisions/QuadTree/QuadTree.cs @@ -8,10 +8,24 @@ namespace MonoGame.Extended.Collisions /// public class Quadtree { + /// + /// The default maximum depth. + /// public const int DefaultMaxDepth = 7; + + /// + /// The default maximum objects per node. + /// public const int DefaultMaxObjectsPerNode = 25; + /// + /// Contains the children of this node. + /// protected List Children = new List(); + + /// + /// Contains the data for this node in the quadtree. + /// protected HashSet Contents = new HashSet(); /// @@ -24,9 +38,17 @@ namespace MonoGame.Extended.Collisions NodeBounds = bounds; } + /// + /// Gets or sets the current depth for this node in the quadtree. + /// protected int CurrentDepth { get; set; } + /// + /// Gets or sets the maximum depth of the quadtree. + /// protected int MaxDepth { get; set; } = DefaultMaxDepth; - + /// + /// Gets or sets the maximum objects per node in this quadtree. + /// protected int MaxObjectsPerNode { get; set; } = DefaultMaxObjectsPerNode; ///