BitMap
Boolean matrix.
BitMap.swift:11class BitMap
A two-dimensional array of boolean values, can be used to efficiently store a binary matrix (every matrix element takes only one bit) and query the values using natural cartesian coordinates.
Superclasses
class Resource
Base class for serializable objects.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Type members
Instance members
func convertToImage(
) -> Image? Returns an image of the same size as the bitmap and with a
Image.Format
of typel8
.true
bits of the bitmap are being converted into white pixels, andfalse
bits into black.func create(size: Vector2i
) Creates a bitmap with the specified size, filled with
false
.func createFromImageAlpha(image: Image?, threshold: Double
) Creates a bitmap that matches the given image dimensions, every element of the bitmap is set to
false
if the alpha value of the image at that position is equal tothreshold
or less, andtrue
in other case.func getBit(x: Int32, y: Int32
) -> Bool Returns bitmap’s value at the specified position.
func getBitv(position: Vector2i
) -> Bool Returns bitmap’s value at the specified position.
func getSize(
) -> Vector2i Returns bitmap’s dimensions.
func getTrueBitCount(
) -> Int32 Returns the number of bitmap elements that are set to
true
.func growMask(pixels: Int32, rect: Rect2i
) Applies morphological dilation or erosion to the bitmap. If
pixels
is positive, dilation is applied to the bitmap. Ifpixels
is negative, erosion is applied to the bitmap.rect
defines the area where the morphological operation is applied. Pixels located outside therect
are unaffected bygrowMask(pixels:rect:)
.func opaqueToPolygons(rect: Rect2i, epsilon: Double
) -> VariantCollection<PackedVector2Array> Creates an
GArray
of polygons covering a rectangular portion of the bitmap. It uses a marching squares algorithm, followed by Ramer-Douglas-Peucker (RDP) reduction of the number of vertices. Each polygon is described as aPackedVector2Array
of its vertices.func resize(newSize: Vector2i
) Resizes the image to
newSize
.func setBit(x: Int32, y: Int32, bit: Bool
) Sets the bitmap’s element at the specified position, to the specified value.
func setBitRect(Rect2i, bit: Bool
) Sets a rectangular portion of the bitmap to the specified value.
func setBitv(position: Vector2i, bit: Bool
) Sets the bitmap’s element at the specified position, to the specified value.