dcre-native 0.1.0

High-performance Rust core for DCRE Mesh
Documentation

let imports = {};
imports['__wbindgen_placeholder__'] = module.exports;

function getStringFromWasm0(ptr, len) {
    ptr = ptr >>> 0;
    return decodeText(ptr, len);
}

let cachedUint8ArrayMemory0 = null;
function getUint8ArrayMemory0() {
    if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
        cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
    }
    return cachedUint8ArrayMemory0;
}

let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
cachedTextDecoder.decode();
function decodeText(ptr, len) {
    return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}

const LatticeFinalization = (typeof FinalizationRegistry === 'undefined')
    ? { register: () => {}, unregister: () => {} }
    : new FinalizationRegistry(ptr => wasm.__wbg_lattice_free(ptr >>> 0, 1));

class Lattice {
    __destroy_into_raw() {
        const ptr = this.__wbg_ptr;
        this.__wbg_ptr = 0;
        LatticeFinalization.unregister(this);
        return ptr;
    }
    free() {
        const ptr = this.__destroy_into_raw();
        wasm.__wbg_lattice_free(ptr, 0);
    }
    /**
     * @param {number} row
     * @param {number} col
     * @returns {number}
     */
    get(row, col) {
        const ret = wasm.lattice_get(this.__wbg_ptr, row, col);
        return ret;
    }
    /**
     * @param {number} width
     * @param {number} height
     * @param {number} modulus
     */
    constructor(width, height, modulus) {
        const ret = wasm.lattice_new(width, height, modulus);
        this.__wbg_ptr = ret >>> 0;
        LatticeFinalization.register(this, this.__wbg_ptr, this);
        return this;
    }
    /**
     * @param {number} row
     * @param {number} col
     * @param {number} value
     */
    set(row, col, value) {
        wasm.lattice_set(this.__wbg_ptr, row, col, value);
    }
    /**
     * @returns {number}
     */
    width() {
        const ret = wasm.lattice_width(this.__wbg_ptr);
        return ret >>> 0;
    }
    /**
     * Optimized Lattice Evolution
     *
     * Applies the DCRE matrix [[2, 1], [1, 1]] to 2x2 blocks in a checkerboard pattern.
     * This implementation is single-threaded O(N^2) but allocation-free.
     */
    evolve() {
        wasm.lattice_evolve(this.__wbg_ptr);
    }
    /**
     * @returns {number}
     */
    height() {
        const ret = wasm.lattice_height(this.__wbg_ptr);
        return ret >>> 0;
    }
    /**
     * @returns {number}
     */
    modulus() {
        const ret = wasm.lattice_modulus(this.__wbg_ptr);
        return ret;
    }
    /**
     * Access memory directly from JS for zero-copy
     * @returns {number}
     */
    cells_ptr() {
        const ret = wasm.lattice_cells_ptr(this.__wbg_ptr);
        return ret >>> 0;
    }
}
if (Symbol.dispose) Lattice.prototype[Symbol.dispose] = Lattice.prototype.free;
exports.Lattice = Lattice;

exports.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
    throw new Error(getStringFromWasm0(arg0, arg1));
};

exports.__wbindgen_init_externref_table = function() {
    const table = wasm.__wbindgen_externrefs;
    const offset = table.grow(4);
    table.set(0, undefined);
    table.set(offset + 0, undefined);
    table.set(offset + 1, null);
    table.set(offset + 2, true);
    table.set(offset + 3, false);
};

const wasmPath = `${__dirname}/dcre_native_bg.wasm`;
const wasmBytes = require('fs').readFileSync(wasmPath);
const wasmModule = new WebAssembly.Module(wasmBytes);
const wasm = exports.__wasm = new WebAssembly.Instance(wasmModule, imports).exports;

wasm.__wbindgen_start();