From e072fd662f8e7c0ce8545f19b32de1219fb45b69 Mon Sep 17 00:00:00 2001 From: Dmitry Bubelnik <74250088+DmitryBubelnikSoftSmile@users.noreply.github.com> Date: Fri, 25 Oct 2024 12:22:16 +0300 Subject: [PATCH] implement boolean logic in bitmap2 (#53) --- 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) {