Code cleanup

This commit is contained in:
Stone_Red
2026-05-05 19:46:12 +02:00
parent ceadce08bb
commit 9dfbf06ec3
+18 -18
View File
@@ -231,8 +231,8 @@ public class GridFiller
if (changed) if (changed)
{ {
// Capture zones and rectangles before recalculation // Capture zones and rectangles before recalculation
HashSet<int> zonesBefore = new(PlacedRectangles.Keys); HashSet<int> zonesBefore = [.. PlacedRectangles.Keys];
var rectBefore = new Dictionary<int, Rectangle>(PlacedRectangles); Dictionary<int, Rectangle> rectBefore = new Dictionary<int, Rectangle>(PlacedRectangles);
RecalculateAroundArea(minX, minY, maxX, maxY, recalculate, () => RecalculateAroundArea(minX, minY, maxX, maxY, recalculate, () =>
{ {
@@ -256,20 +256,20 @@ public class GridFiller
}); });
// Capture zones after recalculation // Capture zones after recalculation
HashSet<int> zonesAfter = new(PlacedRectangles.Keys); HashSet<int> zonesAfter = [.. PlacedRectangles.Keys];
Debug.WriteLine("Placed obstacle"); Debug.WriteLine("Placed obstacle");
// Return zones that changed (added, removed, or had their rectangle modified) // Return zones that changed (added, removed, or had their rectangle modified)
HashSet<int> affected = new(zonesBefore); HashSet<int> affected = [.. zonesBefore];
affected.SymmetricExceptWith(zonesAfter); // zones removed OR added affected.SymmetricExceptWith(zonesAfter); // zones removed OR added
// Also include zones whose rectangles changed // Also include zones whose rectangles changed
foreach (int zoneId in zonesBefore.Where(z => zonesAfter.Contains(z))) foreach (int zoneId in zonesBefore.Where(zonesAfter.Contains))
{ {
if (PlacedRectangles[zoneId] != rectBefore[zoneId]) if (PlacedRectangles[zoneId] != rectBefore[zoneId])
{ {
affected.Add(zoneId); _ = affected.Add(zoneId);
} }
} }
@@ -332,8 +332,8 @@ public class GridFiller
if (changed) if (changed)
{ {
// Capture zones and rectangles before recalculation // Capture zones and rectangles before recalculation
HashSet<int> zonesBefore = new(PlacedRectangles.Keys); HashSet<int> zonesBefore = [.. PlacedRectangles.Keys];
var rectBefore = new Dictionary<int, Rectangle>(PlacedRectangles); Dictionary<int, Rectangle> rectBefore = new Dictionary<int, Rectangle>(PlacedRectangles);
RecalculateAroundArea(minX, minY, maxX, maxY, recalculate, () => RecalculateAroundArea(minX, minY, maxX, maxY, recalculate, () =>
{ {
@@ -355,19 +355,19 @@ public class GridFiller
}); });
// Capture zones after recalculation // Capture zones after recalculation
HashSet<int> zonesAfter = new(PlacedRectangles.Keys); HashSet<int> zonesAfter = [.. PlacedRectangles.Keys];
Debug.WriteLine("Removed obstacle"); Debug.WriteLine("Removed obstacle");
// Return zones that changed (added, removed, or had their rectangle modified) // Return zones that changed (added, removed, or had their rectangle modified)
HashSet<int> affected = new(zonesBefore); HashSet<int> affected = [.. zonesBefore];
affected.SymmetricExceptWith(zonesAfter); affected.SymmetricExceptWith(zonesAfter);
foreach (int zoneId in zonesBefore.Where(z => zonesAfter.Contains(z))) foreach (int zoneId in zonesBefore.Where(zonesAfter.Contains))
{ {
if (PlacedRectangles[zoneId] != rectBefore[zoneId]) if (PlacedRectangles[zoneId] != rectBefore[zoneId])
{ {
affected.Add(zoneId); _ = affected.Add(zoneId);
} }
} }
@@ -421,8 +421,8 @@ public class GridFiller
if (changed) if (changed)
{ {
// Capture zones and rectangles before recalculation // Capture zones and rectangles before recalculation
HashSet<int> zonesBefore = new(PlacedRectangles.Keys); HashSet<int> zonesBefore = [.. PlacedRectangles.Keys];
var rectBefore = new Dictionary<int, Rectangle>(PlacedRectangles); Dictionary<int, Rectangle> rectBefore = new Dictionary<int, Rectangle>(PlacedRectangles);
RecalculateAroundArea(minX, minY, maxX, maxY, recalculate, () => RecalculateAroundArea(minX, minY, maxX, maxY, recalculate, () =>
{ {
@@ -438,17 +438,17 @@ public class GridFiller
}); });
// Capture zones after recalculation // Capture zones after recalculation
HashSet<int> zonesAfter = new(PlacedRectangles.Keys); HashSet<int> zonesAfter = [.. PlacedRectangles.Keys];
// Return zones that changed (added, removed, or had their rectangle modified) // Return zones that changed (added, removed, or had their rectangle modified)
HashSet<int> affected = new(zonesBefore); HashSet<int> affected = [.. zonesBefore];
affected.SymmetricExceptWith(zonesAfter); affected.SymmetricExceptWith(zonesAfter);
foreach (int zoneId in zonesBefore.Where(z => zonesAfter.Contains(z))) foreach (int zoneId in zonesBefore.Where(zonesAfter.Contains))
{ {
if (PlacedRectangles[zoneId] != rectBefore[zoneId]) if (PlacedRectangles[zoneId] != rectBefore[zoneId])
{ {
affected.Add(zoneId); _ = affected.Add(zoneId);
} }
} }