Skip to content

Commit

Permalink
Fix bug in LocationIntSet.Except
Browse files Browse the repository at this point in the history
  • Loading branch information
joelverhagen committed Jan 17, 2024
1 parent fde2377 commit eee8dcf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/FactorioTools/OilField/Containers/LocationIntSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,17 @@ public void UnionWith(ILocationSet other)

public void ExceptWith(ILocationSet other)
{
var otherSet = ValidateSameDimensions(other);
_set.ExceptWith(otherSet._set);
if (other.Count == 0)
{
return;
}
else
{
foreach (var item in other.EnumerateItems())
{
_set.Remove(GetIndex(item));
}
}
}

public bool SetEquals(ILocationSet other)
Expand Down
15 changes: 13 additions & 2 deletions src/lua/FactorioTools/LocationIntSet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,19 @@ System.namespace("Knapcode.FactorioTools.OilField", function (namespace)
end
end
ExceptWith = function (this, other)
local otherSet = ValidateSameDimensions(this, other)
this._set:ExceptWith(otherSet._set)
if other:getCount() == 0 then
return
else
for _, item in System.each(other:EnumerateItems()) do
-- inline Knapcode.FactorioTools.OilField.LocationIntSet.GetIndex(Knapcode.FactorioTools.OilField.Location)
local default
do
local location = item
default = location.Y * this._width + location.X
end
this._set:Remove(default)
end
end
end
SetEquals = function (this, other)
local otherSet = ValidateSameDimensions(this, other)
Expand Down

0 comments on commit eee8dcf

Please sign in to comment.