From a7c3b30fc8b4be3eb68b041bdd8b53356348f0b8 Mon Sep 17 00:00:00 2001 From: Dmitry Bubelnik Date: Fri, 25 Oct 2024 11:39:58 +0300 Subject: [PATCH] implement boolean logic in bitmap2 --- spatial/Bitmap2.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/spatial/Bitmap2.cs b/spatial/Bitmap2.cs index 8226c24e..735cb6b6 100644 --- a/spatial/Bitmap2.cs +++ b/spatial/Bitmap2.cs @@ -68,6 +68,8 @@ public Bitmap2(BitArray bits, Vector2i dimensions) public AxisAlignedBox2i GridBounds => new AxisAlignedBox2i(Vector2i.Zero, Dimensions); + public BitArray BitsCopy => (BitArray)_bits.Clone(); + public bool this[int i] { get { return _bits[i]; } @@ -176,7 +178,13 @@ public IEnumerable NonZeros() } } - public Bitmap2 Not() => new Bitmap2(((BitArray)_bits.Clone()).Not(), _dimensions); + public Bitmap2 Not() => new Bitmap2(BitsCopy.Not(), _dimensions); + + public Bitmap2 Or(Bitmap2 other) => new Bitmap2(BitsCopy.Or(other._bits), _dimensions); + + public Bitmap2 Xor(Bitmap2 other) => new Bitmap2(BitsCopy.Xor(other._bits), _dimensions); + + public Bitmap2 And(Bitmap2 other) => new Bitmap2(BitsCopy.And(other._bits), _dimensions); public bool Equals(Bitmap2 other) {