Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Not method to bitmap2 #52

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions spatial/Bitmap2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ public Bitmap2(bool[,] input)
}
}
}

public Bitmap2(BitArray bits, Vector2i dimensions)
{
if (dimensions.x * dimensions.y != bits.Length)
{
throw new ArgumentException(
$"Bit array length {bits.Length} differs from provided dimensions {dimensions}");
}

_dimensions = dimensions;
_bits = bits;
}

public AxisAlignedBox2i GridBounds => new AxisAlignedBox2i(Vector2i.Zero, Dimensions);

Expand Down Expand Up @@ -164,6 +176,8 @@ public IEnumerable<Vector2i> NonZeros()
}
}

public Bitmap2 Not() => new Bitmap2(((BitArray)_bits.Clone()).Not(), _dimensions);

public bool Equals(Bitmap2 other)
{
if (ReferenceEquals(null, other)) return false;
Expand Down
Loading