Skip to content
This repository was archived by the owner on Aug 24, 2024. It is now read-only.

Commit 66d40ba

Browse files
committed
Speed up property checking
1 parent ab38e12 commit 66d40ba

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/ffi.mjs

+10
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,13 @@ export function ensurePixelExists(imageData, x, y, callback) {
104104

105105
return callback(imageData, x, y);
106106
}
107+
108+
/**
109+
* Returns whether a given pixel value has a given property.
110+
* @param {number} pixelVal - The pixel value.
111+
* @param {number} property - The property.
112+
* @returns {bool} - Whether the pixel value has the property.
113+
*/
114+
export function hasProperty(pixelVal, property) {
115+
return !!(pixelVal & property);
116+
}

src/properties.gleam

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import gleam/int
2-
31
// 00000000 00000001 00000000 00000000
42
pub const grows = 0x00010000
53

@@ -12,6 +10,5 @@ pub const floats = 0x00000100
1210
// 00000000 00000000 00000000 00000001
1311
pub const experiences_gravity = 0x00000001
1412

15-
pub fn has_property(pixel_val: Int, property: Int) -> Bool {
16-
int.bitwise_and(pixel_val, property) != 0
17-
}
13+
@external(javascript, "./ffi.mjs", "hasProperty")
14+
pub fn has_property(pixel_val: Int, property: Int) -> Bool

0 commit comments

Comments
 (0)