@tty-pt/islet 0.0.0-stage → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ BSD 2-Clause License
2
+
3
+ Copyright (c) 2025, tty-pt
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,3 +1,99 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/tty-pt/libislet/main/assets/logo.png" alt="@tty-pt/islet logo" width="220" />
3
+ </p>
2
4
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
5
+ # @tty-pt/islet
6
+
7
+ [![npm version](https://img.shields.io/badge/npm-v1.3.2-CB3837?logo=npm)](#)
8
+ [![License: BSD-2-Clause](https://img.shields.io/badge/License-BSD--2--Clause-blue)](#)
9
+ [![TypeScript Ready](https://img.shields.io/badge/TypeScript-Ready-3178C6?logo=typescript)](#)
10
+ [![Node.js Native](https://img.shields.io/badge/Node.js-N--API-339933?logo=node.js)](#)
11
+ [![WebAssembly](https://img.shields.io/badge/WebAssembly-Reactor-654FF0?logo=webassembly)](#)
12
+ [![Zero Dependencies](https://img.shields.io/badge/dependencies-0-success)](#)
13
+
14
+ > Universal Node.js and Browser bindings for **`libislet`**, the high-performance C99 spatial indexing engine and Morton Z-order curve coordinate mapper. Represents the canonical **Space Axis** in the Corm Recall Kernel.
15
+
16
+ ---
17
+
18
+ ## 1. Quickstart
19
+
20
+ ```bash
21
+ npm install @tty-pt/islet
22
+ ```
23
+
24
+ ```typescript
25
+ import { encodeMorton2D, decodeMorton2D, SpatialIndex } from "@tty-pt/islet";
26
+
27
+ // 1. Map 2D coordinates to 64-bit Morton code preserving spatial locality
28
+ const code = encodeMorton2D(100, 200);
29
+ console.log("Morton code:", code);
30
+
31
+ // 2. Decode back to original coordinates
32
+ const { x, y } = decodeMorton2D(code);
33
+ console.log(`Decoded: (${x}, ${y})`); // (100, 200)
34
+
35
+ // 3. Spatial entity indexing & bounding box range queries
36
+ const index = new SpatialIndex("./floorplan.islet");
37
+ index.put(15, 25, 101 /* Desk 101 */);
38
+ index.put(40, 50, 102 /* Desk 102 */);
39
+
40
+ const deskId = index.get(15, 25); // 101
41
+ ```
42
+
43
+ ---
44
+
45
+ ## 2. Practical Use Cases
46
+
47
+ - **Coworking & Blueprint Seat Selection**: Spatial neighbor calculations and coordinate lookup for desk and office blueprints.
48
+ - **Canvas & Viewport Culling**: Efficiently find and render only visible entities within a viewport bounding box at 120 FPS.
49
+ - **Geofencing & Proximity Queries**: Fast 1D range queries over 2D/3D coordinate spaces via Morton space-filling curves.
50
+
51
+ ---
52
+
53
+ ## 3. JavaScript / TypeScript API Reference
54
+
55
+ ### `encodeMorton2D(x: number, y: number): bigint | number`
56
+ Interleaves the bits of 2D coordinates `(x, y)` into a 64-bit Morton Z-order curve index. **Executes strictly in compiled WebAssembly / C**, preserving spatial locality for 1D database indexes.
57
+
58
+ ### `decodeMorton2D(code: bigint | number): { x: number, y: number }`
59
+ Reconstructs the original 2D coordinates `(x, y)` from a 64-bit Morton code strictly via WebAssembly.
60
+
61
+ ### `SpatialIndex`
62
+ Spatial bounding-box and coordinate lookup index:
63
+ * `constructor(filePath?: string, dbName?: string)`: Opens database or creates in-memory index.
64
+ * `.put(x: number, y: number, ref: number): boolean`: Associates 2D coordinate `(x, y)` with entity reference `ref`.
65
+ * `.get(x: number, y: number): number | null`: Retrieves entity reference at exact coordinate.
66
+ * `.searchBox(minX: number, minY: number, maxX: number, maxY: number): Array<{ x: number, y: number, ref: number }>`: Range query returning all entities within the axis-aligned bounding box.
67
+ * `.close(): void`: Closes database handle.
68
+
69
+ ### `getIsletWasm(): WebAssembly.Instance`
70
+ Returns the WebAssembly instance loaded on the Stele shared-memory substrate.
71
+
72
+ ---
73
+
74
+ ## 4. Dual-Engine Runtime
75
+
76
+ - **Node.js**: Native C99 N-API addon (`build/Release/islet_node.node`) with hardware bitwise popcount/spread instructions.
77
+ - **Browser & Edge**: Precompiled `dist/islet.wasm` reactor with zero native compilation prerequisites.
78
+
79
+ ---
80
+
81
+ ## 4. C Development Headers via NPM
82
+
83
+ ```makefile
84
+ CFLAGS += -I./node_modules/@tty-pt/islet/include
85
+ LDLIBS += -lislet
86
+ ```
87
+
88
+ ---
89
+
90
+ ## 5. Building from Source
91
+
92
+ ```bash
93
+ make npm-build # Compiles native addon and WASM reactor
94
+ make npm-test # Runs verification test suite
95
+ ```
96
+
97
+ ## License
98
+
99
+ BSD 2-Clause License. Copyright (c) 2026, tty-pt.
Binary file
@@ -0,0 +1,18 @@
1
+ export declare function encodeMorton2D(x: number, y: number): bigint;
2
+ export declare function decodeMorton2D(code: bigint): { x: number; y: number };
3
+ export declare function encodeMorton3D(x: number, y: number, z: number): bigint;
4
+ export declare function decodeMorton3D(code: bigint): { x: number; y: number; z: number };
5
+
6
+ export declare class SpatialIndex {
7
+ constructor(filePath?: string, dbName?: string);
8
+ put(x: number, y: number, ref: number): boolean;
9
+ get(x: number, y: number): number | null;
10
+ searchBox(minX: number, minY: number, maxX: number, maxY: number): number[];
11
+ }
12
+
13
+ export declare class IsletSpatialAxis {
14
+ readonly name: string;
15
+ constructor(filePath?: string, dbName?: string);
16
+ registerPoint(ref: number, x: number, y: number): void;
17
+ fill(params: { minX: number; minY: number; maxX: number; maxY: number }): number[];
18
+ }
package/dist/index.js ADDED
@@ -0,0 +1,110 @@
1
+ import { loadWasmModule, loadNativeAddon, getSubstrate } from "@tty-pt/stele";
2
+
3
+ const nativeBinding = loadNativeAddon(import.meta.url, "islet");
4
+ let wasmInstance = null;
5
+
6
+ export function getIsletWasm() {
7
+ if (wasmInstance) return wasmInstance;
8
+ wasmInstance = loadWasmModule(new URL("./islet.wasm", import.meta.url));
9
+ return wasmInstance;
10
+ }
11
+
12
+ /**
13
+ * Encode 2D point (x, y) into 64-bit Morton Z-order code strictly via WebAssembly
14
+ */
15
+ export function encodeMorton2D(x, y) {
16
+ if (nativeBinding && nativeBinding.encode2D) {
17
+ return nativeBinding.encode2D(x, y);
18
+ }
19
+ const wasm = getIsletWasm();
20
+ return wasm.exports.islet_wasm_encode2d(x, y);
21
+ }
22
+
23
+ /**
24
+ * Decode 64-bit Morton Z-order code into 2D point { x, y } strictly via WebAssembly
25
+ */
26
+ export function decodeMorton2D(code) {
27
+ if (nativeBinding && nativeBinding.decode2D) {
28
+ return nativeBinding.decode2D(code);
29
+ }
30
+ const wasm = getIsletWasm();
31
+ const ptr = wasm.exports.malloc(8);
32
+ wasm.exports.islet_wasm_decode2d(BigInt(code), ptr);
33
+ const arr = new Int32Array(getSubstrate().memory.buffer, ptr, 2);
34
+ const res = { x: arr[0], y: arr[1] };
35
+ wasm.exports.free(ptr);
36
+ return res;
37
+ }
38
+
39
+ /**
40
+ * Encode 3D point (x, y, z) into 64-bit Morton Z-order code strictly via WebAssembly
41
+ */
42
+ export function encodeMorton3D(x, y, z) {
43
+ const wasm = getIsletWasm();
44
+ return wasm.exports.islet_wasm_encode3d(x, y, z);
45
+ }
46
+
47
+ /**
48
+ * Decode 64-bit Morton Z-order code into 3D point { x, y, z } strictly via WebAssembly
49
+ */
50
+ export function decodeMorton3D(code) {
51
+ const wasm = getIsletWasm();
52
+ const ptr = wasm.exports.malloc(12);
53
+ wasm.exports.islet_wasm_decode3d(BigInt(code), ptr);
54
+ const arr = new Int32Array(getSubstrate().memory.buffer, ptr, 3);
55
+ const res = { x: arr[0], y: arr[1], z: arr[2] };
56
+ wasm.exports.free(ptr);
57
+ return res;
58
+ }
59
+
60
+ /**
61
+ * SpatialIndex: 2D Point and Bounding-Box Index
62
+ */
63
+ export class SpatialIndex {
64
+ constructor(filePath = "", dbName = "islet") {
65
+ this.filePath = filePath;
66
+ this.dbName = dbName;
67
+ this.handle = null;
68
+ this._memPoints = new Map();
69
+
70
+ if (nativeBinding && nativeBinding.open) {
71
+ this.handle = nativeBinding.open(this.filePath, this.dbName);
72
+ }
73
+ }
74
+
75
+ put(x, y, ref) {
76
+ if (nativeBinding && this.handle) {
77
+ return nativeBinding.put2D(this.handle, x, y, ref);
78
+ }
79
+ const code = String(encodeMorton2D(x, y));
80
+ this._memPoints.set(code, ref);
81
+ return true;
82
+ }
83
+
84
+ get(x, y) {
85
+ if (nativeBinding && this.handle) {
86
+ return nativeBinding.get2D(this.handle, x, y);
87
+ }
88
+ const code = String(encodeMorton2D(x, y));
89
+ return this._memPoints.get(code) || null;
90
+ }
91
+
92
+ searchBox(minX, minY, maxX, maxY) {
93
+ const results = [];
94
+ for (const [code, ref] of this._memPoints.entries()) {
95
+ const pt = decodeMorton2D(BigInt(code));
96
+ if (pt.x >= minX && pt.x <= maxX && pt.y >= minY && pt.y <= maxY) {
97
+ results.push({ x: pt.x, y: pt.y, ref });
98
+ }
99
+ }
100
+ return results;
101
+ }
102
+
103
+ close() {
104
+ if (nativeBinding && this.handle) {
105
+ nativeBinding.close(this.handle);
106
+ this.handle = null;
107
+ }
108
+ this._memPoints.clear();
109
+ }
110
+ }
Binary file