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

implement boolean logic in bitmap2 #53

Merged
merged 1 commit into from
Oct 25, 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
10 changes: 9 additions & 1 deletion spatial/Bitmap2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public Bitmap2(BitArray bits, Vector2i dimensions)

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

public BitArray BitsCopy => (BitArray)_bits.Clone();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

property_Get воспринимается программистами как бесплатный с вычислительной точки зрения ресурс. а в данном случае за пропертёй скрывается клонирование (выделение памяти). давай оформим это в виде Метода с соответствующим названием (типа MakeBitArrayCopy())


public bool this[int i]
{
get { return _bits[i]; }
Expand Down Expand Up @@ -176,7 +178,13 @@ public IEnumerable<Vector2i> 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)
{
Expand Down
Loading