@flighthq/quadbatch 0.3.0-edge.1458.0c01b63
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/dist/contract.d.ts +2 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +2 -0
- package/dist/contract.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/quadBatch.d.ts +118 -0
- package/dist/quadBatch.d.ts.map +1 -0
- package/dist/quadBatch.js +582 -0
- package/dist/quadBatch.js.map +1 -0
- package/package.json +50 -0
- package/src/quadBatch.test.ts +906 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
package/dist/contract.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { appendQuadBatchInstance, clearQuadBatch, cloneQuadBatch, compactQuadBatch, computeQuadBatchLocalBoundsRectangle, createQuadBatch, enableQuadBatchSignals, getQuadBatchCapacity, getQuadBatchInstanceId, getQuadBatchInstanceTransform, getQuadBatchSignals, getQuadBatchTransformStride, hitTestQuadBatchPoint, hitTestQuadBatchPointExact, hitTestQuadBatchPointExactXY, hitTestQuadBatchPointXY, iterateQuadBatchInstances, removeQuadBatchInstance, reserveQuadBatch, resizeQuadBatch, setQuadBatchInstance, setQuadBatchInstanceMatrix, setQuadBatchInstanceRange, setQuadBatchInstanceTint, setQuadBatchLocalBoundsRectangle, setQuadBatchTransformType, } from './contract';
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,oCAAoC,EACpC,eAAe,EACf,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACtB,6BAA6B,EAC7B,mBAAmB,EACnB,2BAA2B,EAC3B,qBAAqB,EACrB,0BAA0B,EAC1B,4BAA4B,EAC5B,uBAAuB,EACvB,yBAAyB,EACzB,uBAAuB,EACvB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EACxB,gCAAgC,EAChC,yBAAyB,GAC1B,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { appendQuadBatchInstance, clearQuadBatch, cloneQuadBatch, compactQuadBatch, computeQuadBatchLocalBoundsRectangle, createQuadBatch, enableQuadBatchSignals, getQuadBatchCapacity, getQuadBatchInstanceId, getQuadBatchInstanceTransform, getQuadBatchSignals, getQuadBatchTransformStride, hitTestQuadBatchPoint, hitTestQuadBatchPointExact, hitTestQuadBatchPointExactXY, hitTestQuadBatchPointXY, iterateQuadBatchInstances, removeQuadBatchInstance, reserveQuadBatch, resizeQuadBatch, setQuadBatchInstance, setQuadBatchInstanceMatrix, setQuadBatchInstanceRange, setQuadBatchInstanceTint, setQuadBatchLocalBoundsRectangle, setQuadBatchTransformType, } from './contract';
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,oCAAoC,EACpC,eAAe,EACf,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACtB,6BAA6B,EAC7B,mBAAmB,EACnB,2BAA2B,EAC3B,qBAAqB,EACrB,0BAA0B,EAC1B,4BAA4B,EAC5B,uBAAuB,EACvB,yBAAyB,EACzB,uBAAuB,EACvB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EACxB,gCAAgC,EAChC,yBAAyB,GAC1B,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { PartialNode, QuadBatch, QuadBatchData, QuadBatchRuntime, QuadBatchSignals, QuadTransformType, Rectangle, Vector2Like } from '@flighthq/types/contract';
|
|
2
|
+
export declare const QUAD_BATCH_DELETED_ID = 65535;
|
|
3
|
+
/**
|
|
4
|
+
* Appends a new instance at the end of `target` using vector2 (translation-only) transform,
|
|
5
|
+
* auto-growing capacity via `resizeQuadBatch`. Returns the new instance index.
|
|
6
|
+
* The materialData slot for the appended instance is not set — leave it null or assign after.
|
|
7
|
+
* Fires `onInstanceAppended` when signals are enabled.
|
|
8
|
+
*/
|
|
9
|
+
export declare function appendQuadBatchInstance(target: QuadBatch, id: number, x: number, y: number): number;
|
|
10
|
+
/** Sets `target.data.instanceCount = 0`, keeping allocated capacity. Fires `onCleared` when signals are enabled. */
|
|
11
|
+
export declare function clearQuadBatch(target: QuadBatch): void;
|
|
12
|
+
/**
|
|
13
|
+
* Deep-copies `source` into a new `QuadBatch` with independent typed arrays and a fresh runtime.
|
|
14
|
+
* The new batch has the same `atlas`, `instanceCount`, `transformType`, and `materialData` (shallow copy),
|
|
15
|
+
* but its `ids` and `transforms` are cloned typed arrays.
|
|
16
|
+
*/
|
|
17
|
+
export declare function cloneQuadBatch(source: Readonly<QuadBatch>): QuadBatch;
|
|
18
|
+
/**
|
|
19
|
+
* Removes swap-remove holes by compacting all live instances (`[0, instanceCount)`) to the
|
|
20
|
+
* front of the buffer in index order, skipping entries that have been logically deleted.
|
|
21
|
+
* This is not needed for swap-remove–only callers, but is useful when stable iteration order
|
|
22
|
+
* must be restored after a batch of removals. After compaction, `instanceCount` equals the
|
|
23
|
+
* number of entries whose id is `>= 0`.
|
|
24
|
+
*
|
|
25
|
+
* Note: this function does NOT filter by id; it simply copies all `instanceCount` entries to a
|
|
26
|
+
* fresh contiguous layout. To remove specific entries, call `removeQuadBatchInstance` first, then
|
|
27
|
+
* compact if needed.
|
|
28
|
+
*/
|
|
29
|
+
export declare function compactQuadBatch(target: QuadBatch): void;
|
|
30
|
+
export declare function computeQuadBatchLocalBoundsRectangle(out: Rectangle, source: Readonly<QuadBatch>): void;
|
|
31
|
+
export declare function createQuadBatch(obj?: Readonly<PartialNode<QuadBatch>>): QuadBatch;
|
|
32
|
+
export declare function createQuadBatchData(data?: Readonly<Partial<QuadBatchData>>): QuadBatchData;
|
|
33
|
+
export declare function createQuadBatchRuntime(): QuadBatchRuntime;
|
|
34
|
+
export declare function createQuadBatchSignals(): QuadBatchSignals;
|
|
35
|
+
/**
|
|
36
|
+
* Opt-in signals for a `QuadBatch` node. Returns the {@link QuadBatchSignals} group attached to
|
|
37
|
+
* `target`, creating it on the first call. Zero cost until enabled — honors the `enable*` convention.
|
|
38
|
+
* Use `getQuadBatchSignals` to read without creating.
|
|
39
|
+
*/
|
|
40
|
+
export declare function enableQuadBatchSignals(target: QuadBatch): QuadBatchSignals;
|
|
41
|
+
export declare function getQuadBatchCapacity(source: Readonly<QuadBatch>): number;
|
|
42
|
+
/**
|
|
43
|
+
* Returns the region id stored at `index`, or -1 when `index` is out of range.
|
|
44
|
+
* Bounds-checked against `instanceCount`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getQuadBatchInstanceId(source: Readonly<QuadBatch>, index: number): number;
|
|
47
|
+
/**
|
|
48
|
+
* Writes the transform of instance `index` into `out`.
|
|
49
|
+
* For vector2 batches, writes `out.x = tx, out.y = ty` (matrix fields left unchanged).
|
|
50
|
+
* For matrix3x2 batches, writes `out.a/b/c/d/tx/ty`.
|
|
51
|
+
* Returns false and writes nothing when `index` is out of range.
|
|
52
|
+
*/
|
|
53
|
+
export declare function getQuadBatchInstanceTransform(out: Vector2Like, source: Readonly<QuadBatch>, index: number): boolean;
|
|
54
|
+
export declare function getQuadBatchRuntime(source: Readonly<QuadBatch>): Readonly<QuadBatchRuntime>;
|
|
55
|
+
/** Returns the {@link QuadBatchSignals} attached to `source`, or `null` if not yet enabled. */
|
|
56
|
+
export declare function getQuadBatchSignals(source: Readonly<QuadBatch>): QuadBatchSignals | null;
|
|
57
|
+
export declare function getQuadBatchTransformStride(transformType: QuadTransformType): number;
|
|
58
|
+
export declare function hitTestQuadBatchPoint(source: Readonly<QuadBatch>, point: Readonly<Vector2Like>): number;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the topmost instance index whose quad polygon contains `(x, y)`, or -1 for a miss.
|
|
61
|
+
*
|
|
62
|
+
* For `vector2` batches this is equivalent to `hitTestQuadBatchPointXY` (axis-aligned quads have
|
|
63
|
+
* no rotation; AABB = exact polygon). For `matrix3x2` batches this performs a true point-in-quad
|
|
64
|
+
* test via the cross-product winding rule, while `hitTestQuadBatchPointXY` uses the AABB of the
|
|
65
|
+
* transformed quad (which over-reports for rotated quads). Use this variant when rotation accuracy
|
|
66
|
+
* matters; it is slightly more expensive than the AABB version.
|
|
67
|
+
*/
|
|
68
|
+
export declare function hitTestQuadBatchPointExact(source: Readonly<QuadBatch>, point: Readonly<Vector2Like>): number;
|
|
69
|
+
/**
|
|
70
|
+
* XY variant of `hitTestQuadBatchPointExact`. See that function for details.
|
|
71
|
+
*/
|
|
72
|
+
export declare function hitTestQuadBatchPointExactXY(source: Readonly<QuadBatch>, x: number, y: number): number;
|
|
73
|
+
export declare function hitTestQuadBatchPointXY(source: Readonly<QuadBatch>, x: number, y: number): number;
|
|
74
|
+
/**
|
|
75
|
+
* Calls `visitor(index, id, transforms)` for each live instance in order. The `transforms`
|
|
76
|
+
* argument is a `Float32Array` subarray view beginning at instance `index`'s offset with
|
|
77
|
+
* length equal to the transform stride. Allocation-free: no per-call object is created.
|
|
78
|
+
*/
|
|
79
|
+
export declare function iterateQuadBatchInstances(source: Readonly<QuadBatch>, visitor: (index: number, id: number, transforms: Float32Array) => void): void;
|
|
80
|
+
/**
|
|
81
|
+
* Swap-removes instance `index` with the last instance (O(1)), decrementing `instanceCount`.
|
|
82
|
+
* Does not preserve order — the instance that was at `instanceCount-1` moves to `index`.
|
|
83
|
+
* No-ops when `index` is out of range.
|
|
84
|
+
* Fires `onInstanceRemoved` when signals are enabled.
|
|
85
|
+
*/
|
|
86
|
+
export declare function removeQuadBatchInstance(target: QuadBatch, index: number): void;
|
|
87
|
+
export declare function reserveQuadBatch(target: QuadBatch, capacity: number): void;
|
|
88
|
+
export declare function resizeQuadBatch(target: QuadBatch, instanceCount: number): void;
|
|
89
|
+
/**
|
|
90
|
+
* Writes the vector2 (translation-only) transform and id for instance `index`.
|
|
91
|
+
* No-ops when `index` is out of range (`[0, instanceCount)`).
|
|
92
|
+
* Target must use `transformType === 'vector2'`.
|
|
93
|
+
*/
|
|
94
|
+
export declare function setQuadBatchInstance(target: QuadBatch, index: number, id: number, x: number, y: number): void;
|
|
95
|
+
/**
|
|
96
|
+
* Writes a full 2D affine (matrix3x2) transform and id for instance `index`.
|
|
97
|
+
* No-ops when `index` is out of range (`[0, instanceCount)`).
|
|
98
|
+
* Target must use `transformType === 'matrix3x2'`.
|
|
99
|
+
* Layout: `[a, b, c, d, tx, ty]` — standard column-major 2D affine.
|
|
100
|
+
*/
|
|
101
|
+
export declare function setQuadBatchInstanceMatrix(target: QuadBatch, index: number, id: number, a: number, b: number, c: number, d: number, tx: number, ty: number): void;
|
|
102
|
+
/**
|
|
103
|
+
* Writes `count` contiguous transform entries from `source` into the batch starting at `startIndex`.
|
|
104
|
+
* Reads `count * stride` floats from `source` (where stride = `getQuadBatchTransformStride(target.data.transformType)`).
|
|
105
|
+
* No-ops when `startIndex + count` exceeds `instanceCount`.
|
|
106
|
+
* This is the bulk variant of `setQuadBatchInstance`/`setQuadBatchInstanceMatrix`.
|
|
107
|
+
*/
|
|
108
|
+
export declare function setQuadBatchInstanceRange(target: QuadBatch, startIndex: number, count: number, source: Readonly<Float32Array>): void;
|
|
109
|
+
export declare function setQuadBatchInstanceTint(target: QuadBatch, index: number, rgba: number): void;
|
|
110
|
+
export declare function setQuadBatchLocalBoundsRectangle(target: QuadBatch, rect: Readonly<Rectangle>): void;
|
|
111
|
+
/**
|
|
112
|
+
* Switches `target`'s `transformType`, re-striding the `transforms` buffer in place.
|
|
113
|
+
* - `'vector2' → 'matrix3x2'`: each existing (x, y) pair is expanded to `[1, 0, 0, 1, x, y]` (identity + translation).
|
|
114
|
+
* - `'matrix3x2' → 'vector2'`: each matrix is collapsed to its `(tx, ty)` translation, discarding scale/rotation.
|
|
115
|
+
* Does nothing when `newType` matches the current `transformType`.
|
|
116
|
+
*/
|
|
117
|
+
export declare function setQuadBatchTransformType(target: QuadBatch, newType: QuadTransformType): void;
|
|
118
|
+
//# sourceMappingURL=quadBatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quadBatch.d.ts","sourceRoot":"","sources":["../src/quadBatch.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAGV,WAAW,EACX,SAAS,EACT,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,WAAW,EACZ,MAAM,0BAA0B,CAAC;AASlC,eAAO,MAAM,qBAAqB,QAAS,CAAC;AAE5C;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAUnG;AAED,oHAAoH;AACpH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAItD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,SAAS,CAYrE;AAOD;;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