Some improvements for SpatiallyPartitioned.

- Tweak the Update and Remove methods to reduce the number of dictionary lookups required.
- Change the Update method to an indexer, this allows simplifying callers who wanted to AddOrUpdate a value.
- Implement IDictionary<T, Rectangle>, since the class already implements these semantics by providing a backing store of the bounds for each item.
- Clean up some naming to use the generic `item` instead of `actor`.
- Make the MutateBins action methods static.
This commit is contained in:
RoosterDragon
2025-02-18 20:32:09 +00:00
committed by Gustas Kažukauskas
parent 1b2c119b58
commit ce3ad6fbb3
4 changed files with 60 additions and 52 deletions

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Test
Assert.That(partition.At(new int2(3, 2)), Does.Not.Contain(b), "b is present in the wrong location");
Assert.That(partition.At(new int2(3, 3)), Does.Not.Contain(b), "b is present in the wrong location");
partition.Update(b, new Rectangle(4, 4, 1, 1));
partition[b] = new Rectangle(4, 4, 1, 1);
Assert.That(partition.At(new int2(0, 0)), Does.Contain(a), "a wrongly changed location when b was updated");
Assert.That(partition.At(new int2(4, 4)), Does.Contain(b), "b is not present at the new location in the extreme corner of the partition");
Assert.That(partition.At(new int2(1, 1)), Does.Not.Contain(b), "b is still present at the old location after update");
@@ -79,7 +79,7 @@ namespace OpenRA.Test
Assert.That(new[] { a, b }, Is.EquivalentTo(partition.InBox(new Rectangle(-10, -10, 25, 25))),
"Searching an area larger than the partition did not return all items");
partition.Update(b, new Rectangle(4, 4, 1, 1));
partition[b] = new Rectangle(4, 4, 1, 1);
Assert.That(partition.InBox(new Rectangle(0, 0, 1, 1)), Does.Contain(a), "a wrongly changed location when b was updated");
Assert.That(partition.InBox(new Rectangle(4, 4, 1, 1)), Does.Contain(b), "b is not present at the new location in the extreme corner of the partition");
Assert.That(partition.InBox(new Rectangle(1, 1, 1, 1)), Does.Not.Contain(b), "b is still present at the old location after update");