Code cleanup

This commit is contained in:
Stone_Red
2026-05-05 19:46:12 +02:00
parent ceadce08bb
commit 9dfbf06ec3
+25 -25
View File
@@ -231,8 +231,8 @@ public class GridFiller
if (changed)
{
// Capture zones and rectangles before recalculation
HashSet<int> zonesBefore = new(PlacedRectangles.Keys);
var rectBefore = new Dictionary<int, Rectangle>(PlacedRectangles);
HashSet<int> zonesBefore = [.. PlacedRectangles.Keys];
Dictionary<int, Rectangle> rectBefore = new Dictionary<int, Rectangle>(PlacedRectangles);
RecalculateAroundArea(minX, minY, maxX, maxY, recalculate, () =>
{
@@ -256,23 +256,23 @@ public class GridFiller
});
// Capture zones after recalculation
HashSet<int> zonesAfter = new(PlacedRectangles.Keys);
HashSet<int> zonesAfter = [.. PlacedRectangles.Keys];
Debug.WriteLine("Placed obstacle");
// 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
// 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])
{
affected.Add(zoneId);
_ = affected.Add(zoneId);
}
}
return affected;
}
@@ -332,8 +332,8 @@ public class GridFiller
if (changed)
{
// Capture zones and rectangles before recalculation
HashSet<int> zonesBefore = new(PlacedRectangles.Keys);
var rectBefore = new Dictionary<int, Rectangle>(PlacedRectangles);
HashSet<int> zonesBefore = [.. PlacedRectangles.Keys];
Dictionary<int, Rectangle> rectBefore = new Dictionary<int, Rectangle>(PlacedRectangles);
RecalculateAroundArea(minX, minY, maxX, maxY, recalculate, () =>
{
@@ -355,22 +355,22 @@ public class GridFiller
});
// Capture zones after recalculation
HashSet<int> zonesAfter = new(PlacedRectangles.Keys);
HashSet<int> zonesAfter = [.. PlacedRectangles.Keys];
Debug.WriteLine("Removed obstacle");
// Return zones that changed (added, removed, or had their rectangle modified)
HashSet<int> affected = new(zonesBefore);
HashSet<int> affected = [.. zonesBefore];
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])
{
affected.Add(zoneId);
_ = affected.Add(zoneId);
}
}
return affected;
}
@@ -421,8 +421,8 @@ public class GridFiller
if (changed)
{
// Capture zones and rectangles before recalculation
HashSet<int> zonesBefore = new(PlacedRectangles.Keys);
var rectBefore = new Dictionary<int, Rectangle>(PlacedRectangles);
HashSet<int> zonesBefore = [.. PlacedRectangles.Keys];
Dictionary<int, Rectangle> rectBefore = new Dictionary<int, Rectangle>(PlacedRectangles);
RecalculateAroundArea(minX, minY, maxX, maxY, recalculate, () =>
{
@@ -438,20 +438,20 @@ public class GridFiller
});
// 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)
HashSet<int> affected = new(zonesBefore);
HashSet<int> affected = [.. zonesBefore];
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])
{
affected.Add(zoneId);
_ = affected.Add(zoneId);
}
}
return affected;
}
@@ -715,4 +715,4 @@ public class GridFiller
{
return GetStretchFactor(width, height);
}
}
}