Skip to content

Commit

Permalink
Remove more LINQ
Browse files Browse the repository at this point in the history
  • Loading branch information
joelverhagen committed Jan 13, 2024
1 parent de1f99b commit adfc542
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/FactorioTools/OilField/Steps/AddElectricPoles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,33 @@ private static void RemoveExtraElectricPoles(Context context, List<ProviderRecip
{
(var poleCenterToCoveredCenters, var coveredCenterToPoleCenters) = GetElectricPoleCoverage(context, poweredEntities, electricPoles.Keys);

var removeCandidates = coveredCenterToPoleCenters
.EnumeratePairs()
.Where(p => p.Value.Count > 2) // Consider electric poles covering pumpjacks that are covered by at least one other electric pole.
.SelectMany(p => p.Value.EnumerateItems())
.Concat(poleCenterToCoveredCenters.EnumeratePairs().Where(p => p.Value.Count == 0).Select(p => p.Key)) // Consider electric poles not covering any pumpjack.
.ExceptSet(coveredCenterToPoleCenters.EnumeratePairs().Where(p => p.Value.Count == 1).SelectMany(p => p.Value.EnumerateItems()), context, allowEnumerate: true); // Exclude electric poles covering pumpjacks that are only covered by one pole.
var removeCandidates = context.GetLocationSet(allowEnumerate: true);

foreach (var p in coveredCenterToPoleCenters.EnumeratePairs())
{
// Consider electric poles covering pumpjacks that are covered by at least one other electric pole.
if (p.Value.Count > 2)
{
removeCandidates.UnionWith(p.Value);
}
}

foreach (var pair in poleCenterToCoveredCenters.EnumeratePairs())
{
if (pair.Value.Count == 0)
{
removeCandidates.Add(pair.Key);
}
}

foreach (var p in coveredCenterToPoleCenters.EnumeratePairs())
{
// Consider electric poles covering pumpjacks that are covered by at least one other electric pole.
if (p.Value.Count == 1)
{
removeCandidates.ExceptWith(p.Value);
}
}

while (removeCandidates.Count > 0)
{
Expand Down

0 comments on commit adfc542

Please sign in to comment.