@buley/hexgrid-3d 3.1.0 → 3.2.1
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/HexGridEnhanced.d.ts +15 -0
- package/dist/HexGridEnhanced.d.ts.map +1 -0
- package/dist/HexGridEnhanced.js +1 -0
- package/dist/Snapshot.d.ts +594 -0
- package/dist/Snapshot.d.ts.map +1 -0
- package/dist/Snapshot.js +757 -0
- package/dist/adapters/DashAdapter.d.ts +18 -0
- package/dist/adapters/DashAdapter.d.ts.map +1 -0
- package/dist/adapters/DashAdapter.js +42 -0
- package/dist/adapters.d.ts +53 -0
- package/dist/adapters.d.ts.map +1 -0
- package/dist/adapters.js +14 -0
- package/dist/algorithms/AdvancedStatistics.d.ts +52 -0
- package/dist/algorithms/AdvancedStatistics.d.ts.map +1 -0
- package/dist/algorithms/AdvancedStatistics.js +307 -0
- package/dist/algorithms/BayesianStatistics.d.ts +86 -0
- package/dist/algorithms/BayesianStatistics.d.ts.map +1 -0
- package/dist/algorithms/BayesianStatistics.js +263 -0
- package/dist/algorithms/FlowField.d.ts +55 -0
- package/dist/algorithms/FlowField.d.ts.map +1 -0
- package/dist/algorithms/FlowField.js +80 -0
- package/dist/algorithms/FlowField3D.d.ts +166 -0
- package/dist/algorithms/FlowField3D.d.ts.map +1 -0
- package/dist/algorithms/FlowField3D.js +327 -0
- package/dist/algorithms/FluidEngineFactory.d.ts +15 -0
- package/dist/algorithms/FluidEngineFactory.d.ts.map +1 -0
- package/dist/algorithms/FluidEngineFactory.js +41 -0
- package/dist/algorithms/FluidSimulation.d.ts +41 -0
- package/dist/algorithms/FluidSimulation.d.ts.map +1 -0
- package/dist/algorithms/FluidSimulation.js +74 -0
- package/dist/algorithms/FluidSimulation3D.d.ts +137 -0
- package/dist/algorithms/FluidSimulation3D.d.ts.map +1 -0
- package/dist/algorithms/FluidSimulation3D.js +464 -0
- package/dist/algorithms/FluidSimulation3DGPU.d.ts +41 -0
- package/dist/algorithms/FluidSimulation3DGPU.d.ts.map +1 -0
- package/dist/algorithms/FluidSimulation3DGPU.js +468 -0
- package/dist/algorithms/FluidSimulationWebNN.d.ts +56 -0
- package/dist/algorithms/FluidSimulationWebNN.d.ts.map +1 -0
- package/dist/algorithms/FluidSimulationWebNN.js +84 -0
- package/dist/algorithms/GraphAlgorithms.d.ts +48 -0
- package/dist/algorithms/GraphAlgorithms.d.ts.map +1 -0
- package/dist/algorithms/GraphAlgorithms.js +122 -0
- package/dist/algorithms/OutlierDetection.d.ts +49 -0
- package/dist/algorithms/OutlierDetection.d.ts.map +1 -0
- package/dist/algorithms/OutlierDetection.js +284 -0
- package/dist/algorithms/ParticleSystem.d.ts +36 -0
- package/dist/algorithms/ParticleSystem.d.ts.map +1 -0
- package/dist/algorithms/ParticleSystem.js +59 -0
- package/dist/algorithms/ParticleSystem3D.d.ts +206 -0
- package/dist/algorithms/ParticleSystem3D.d.ts.map +1 -0
- package/dist/algorithms/ParticleSystem3D.js +371 -0
- package/dist/algorithms/index.d.ts +19 -0
- package/dist/algorithms/index.d.ts.map +1 -0
- package/{src/algorithms/index.ts → dist/algorithms/index.js} +4 -2
- package/dist/compat.d.ts +24 -0
- package/dist/compat.d.ts.map +1 -0
- package/dist/compat.js +88 -0
- package/dist/components/HexGrid.d.ts +5 -0
- package/dist/components/HexGrid.d.ts.map +1 -0
- package/dist/components/HexGrid.js +39 -0
- package/dist/components/NarrationOverlay.d.ts +16 -0
- package/dist/components/NarrationOverlay.d.ts.map +1 -0
- package/dist/components/NarrationOverlay.js +132 -0
- package/{src/components/index.ts → dist/components/index.d.ts} +1 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +1 -0
- package/dist/features.d.ts +54 -0
- package/dist/features.d.ts.map +1 -0
- package/dist/features.js +74 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/{src/index.ts → dist/index.js} +0 -9
- package/dist/lib/narration.d.ts +12 -0
- package/dist/lib/narration.d.ts.map +1 -0
- package/dist/lib/narration.js +8 -0
- package/dist/lib/stats-tracker.d.ts +7 -0
- package/dist/lib/stats-tracker.d.ts.map +1 -0
- package/dist/lib/stats-tracker.js +22 -0
- package/dist/lib/theme-colors.d.ts +7 -0
- package/dist/lib/theme-colors.d.ts.map +1 -0
- package/dist/lib/theme-colors.js +10 -0
- package/dist/math/HexCoordinates.d.ts +140 -0
- package/dist/math/HexCoordinates.d.ts.map +1 -0
- package/dist/math/HexCoordinates.js +741 -0
- package/dist/math/Matrix4.d.ts +9 -0
- package/dist/math/Matrix4.d.ts.map +1 -0
- package/dist/math/Matrix4.js +19 -0
- package/dist/math/Quaternion.d.ts +11 -0
- package/dist/math/Quaternion.d.ts.map +1 -0
- package/dist/math/Quaternion.js +23 -0
- package/dist/math/SpatialIndex.d.ts +34 -0
- package/dist/math/SpatialIndex.d.ts.map +1 -0
- package/dist/math/SpatialIndex.js +75 -0
- package/dist/math/Vector3.d.ts +110 -0
- package/dist/math/Vector3.d.ts.map +1 -0
- package/dist/math/Vector3.js +426 -0
- package/dist/math/index.d.ts +11 -0
- package/dist/math/index.d.ts.map +1 -0
- package/{src/math/index.ts → dist/math/index.js} +0 -1
- package/dist/note-adapter.d.ts +44 -0
- package/dist/note-adapter.d.ts.map +1 -0
- package/dist/note-adapter.js +86 -0
- package/dist/ontology-adapter.d.ts +13 -0
- package/dist/ontology-adapter.d.ts.map +1 -0
- package/dist/ontology-adapter.js +65 -0
- package/dist/stores/index.d.ts +2 -0
- package/dist/stores/index.d.ts.map +1 -0
- package/dist/stores/uiStore.d.ts +18 -0
- package/dist/stores/uiStore.d.ts.map +1 -0
- package/dist/stores/uiStore.js +77 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types.d.ts +126 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/utils/image-utils.d.ts +13 -0
- package/dist/utils/image-utils.d.ts.map +1 -0
- package/dist/utils/image-utils.js +23 -0
- package/dist/wasm/HexGridWasmWrapper.d.ts +131 -0
- package/dist/wasm/HexGridWasmWrapper.d.ts.map +1 -0
- package/dist/wasm/HexGridWasmWrapper.js +610 -0
- package/dist/wasm/index.d.ts +7 -0
- package/dist/wasm/index.d.ts.map +1 -0
- package/{src/wasm/index.ts → dist/wasm/index.js} +0 -1
- package/dist/webgpu/WebGPUContext.d.ts +20 -0
- package/dist/webgpu/WebGPUContext.d.ts.map +1 -0
- package/dist/webgpu/WebGPUContext.js +60 -0
- package/dist/webnn/WebNNContext.d.ts +38 -0
- package/dist/webnn/WebNNContext.d.ts.map +1 -0
- package/dist/webnn/WebNNContext.js +66 -0
- package/dist/workers/hexgrid-math.d.ts +79 -0
- package/dist/workers/hexgrid-math.d.ts.map +1 -0
- package/dist/workers/hexgrid-math.js +136 -0
- package/dist/workers/hexgrid-worker.worker.d.ts +35 -0
- package/dist/workers/hexgrid-worker.worker.d.ts.map +1 -0
- package/dist/workers/hexgrid-worker.worker.js +2014 -0
- package/package.json +24 -7
- package/.eslintrc.json +0 -28
- package/build_log.txt +0 -500
- package/build_src_log.txt +0 -8
- package/examples/basic-usage.tsx +0 -52
- package/public/hexgrid-worker.js +0 -2475
- package/rust/Cargo.toml +0 -41
- package/rust/src/lib.rs +0 -740
- package/rust/src/math.rs +0 -574
- package/rust/src/spatial.rs +0 -245
- package/rust/src/statistics.rs +0 -496
- package/site/.eslintrc.json +0 -3
- package/site/DEPLOYMENT.md +0 -196
- package/site/INDEX.md +0 -127
- package/site/QUICK_START.md +0 -86
- package/site/README.md +0 -85
- package/site/SITE_SUMMARY.md +0 -180
- package/site/next.config.js +0 -12
- package/site/package.json +0 -26
- package/site/src/app/docs/page.tsx +0 -272
- package/site/src/app/examples/page.tsx +0 -151
- package/site/src/app/globals.css +0 -160
- package/site/src/app/layout.tsx +0 -39
- package/site/src/app/page.tsx +0 -235
- package/site/tsconfig.json +0 -29
- package/site/vercel.json +0 -6
- package/src/HexGridEnhanced.ts +0 -16
- package/src/Snapshot.ts +0 -1607
- package/src/adapters/DashAdapter.ts +0 -57
- package/src/adapters.ts +0 -63
- package/src/algorithms/AdvancedStatistics.ts +0 -362
- package/src/algorithms/BayesianStatistics.ts +0 -348
- package/src/algorithms/FlowField.ts +0 -150
- package/src/algorithms/FlowField3D.ts +0 -573
- package/src/algorithms/FluidEngineFactory.ts +0 -44
- package/src/algorithms/FluidSimulation.ts +0 -115
- package/src/algorithms/FluidSimulation3D.ts +0 -664
- package/src/algorithms/FluidSimulation3DGPU.ts +0 -408
- package/src/algorithms/FluidSimulationWebNN.ts +0 -141
- package/src/algorithms/GraphAlgorithms.ts +0 -191
- package/src/algorithms/OutlierDetection.ts +0 -425
- package/src/algorithms/ParticleSystem.ts +0 -95
- package/src/algorithms/ParticleSystem3D.ts +0 -567
- package/src/compat.ts +0 -96
- package/src/components/HexGrid.tsx +0 -61
- package/src/components/NarrationOverlay.tsx +0 -309
- package/src/features.ts +0 -125
- package/src/lib/narration.ts +0 -17
- package/src/lib/stats-tracker.ts +0 -25
- package/src/lib/theme-colors.ts +0 -12
- package/src/math/HexCoordinates.ts +0 -863
- package/src/math/Matrix4.ts +0 -25
- package/src/math/Quaternion.ts +0 -37
- package/src/math/SpatialIndex.ts +0 -114
- package/src/math/Vector3.ts +0 -540
- package/src/note-adapter.ts +0 -132
- package/src/ontology-adapter.ts +0 -84
- package/src/stores/uiStore.ts +0 -85
- package/src/types/index.ts +0 -3
- package/src/types/shared-utils.d.ts +0 -10
- package/src/types/wgsl.d.ts +0 -4
- package/src/types.ts +0 -164
- package/src/utils/image-utils.ts +0 -28
- package/src/wasm/HexGridWasmWrapper.ts +0 -801
- package/src/webgpu/WebGPUContext.ts +0 -71
- package/src/webgpu/shaders/fluid_sim.wgsl +0 -140
- package/src/webnn/WebNNContext.ts +0 -99
- package/src/workers/hexgrid-math.ts +0 -182
- package/src/workers/hexgrid-worker.worker.ts +0 -2781
- package/tsconfig.json +0 -26
- /package/{src/stores/index.ts → dist/stores/index.js} +0 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebGPU Context Manager
|
|
3
|
+
* Handles the creation and management of the WebGPU Device and Adapter.
|
|
4
|
+
*/
|
|
5
|
+
export class WebGPUContext {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.adapter = null;
|
|
8
|
+
this.device = null;
|
|
9
|
+
this.isSupported = false;
|
|
10
|
+
}
|
|
11
|
+
static getInstance() {
|
|
12
|
+
if (!WebGPUContext.instance) {
|
|
13
|
+
WebGPUContext.instance = new WebGPUContext();
|
|
14
|
+
}
|
|
15
|
+
return WebGPUContext.instance;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Initialize WebGPU context.
|
|
19
|
+
*/
|
|
20
|
+
async initialize() {
|
|
21
|
+
if (typeof navigator === 'undefined' || !navigator.gpu) {
|
|
22
|
+
console.warn('WebGPU is not supported in this environment.');
|
|
23
|
+
this.isSupported = false;
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
this.adapter = await navigator.gpu.requestAdapter({
|
|
28
|
+
powerPreference: 'high-performance'
|
|
29
|
+
});
|
|
30
|
+
if (!this.adapter) {
|
|
31
|
+
console.warn('No WebGPU adapter found.');
|
|
32
|
+
this.isSupported = false;
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
this.device = await this.adapter.requestDevice();
|
|
36
|
+
this.device.lost.then((info) => {
|
|
37
|
+
console.error(`WebGPU device lost: ${info.message}`);
|
|
38
|
+
this.device = null;
|
|
39
|
+
this.isSupported = false;
|
|
40
|
+
});
|
|
41
|
+
this.isSupported = true;
|
|
42
|
+
console.log('WebGPU initialized successfully.');
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
console.error('Failed to initialize WebGPU:', e);
|
|
47
|
+
this.isSupported = false;
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
getDevice() {
|
|
52
|
+
return this.device;
|
|
53
|
+
}
|
|
54
|
+
getAdapter() {
|
|
55
|
+
return this.adapter;
|
|
56
|
+
}
|
|
57
|
+
isAvailable() {
|
|
58
|
+
return this.isSupported && this.device !== null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebNN Context Manager
|
|
3
|
+
* Handles the creation and management of the WebNN MLContext.
|
|
4
|
+
* Prioritizes NPU -> GPU -> CPU.
|
|
5
|
+
*/
|
|
6
|
+
export type WebNNDeviceType = 'cpu' | 'gpu' | 'npu';
|
|
7
|
+
export declare class WebNNContext {
|
|
8
|
+
private static instance;
|
|
9
|
+
private context;
|
|
10
|
+
private deviceType;
|
|
11
|
+
private isSupported;
|
|
12
|
+
private constructor();
|
|
13
|
+
static getInstance(): WebNNContext;
|
|
14
|
+
/**
|
|
15
|
+
* Initialize WebNN context with preferred device type.
|
|
16
|
+
*/
|
|
17
|
+
initialize(preference?: WebNNDeviceType): Promise<boolean>;
|
|
18
|
+
getContext(): MLContext | null;
|
|
19
|
+
getDeviceType(): WebNNDeviceType;
|
|
20
|
+
isAvailable(): boolean;
|
|
21
|
+
}
|
|
22
|
+
declare global {
|
|
23
|
+
interface Navigator {
|
|
24
|
+
ml: {
|
|
25
|
+
createContext(options?: {
|
|
26
|
+
deviceType?: string;
|
|
27
|
+
}): Promise<MLContext>;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
interface MLContext {
|
|
31
|
+
compute(graph: MLGraph, inputs: Record<string, ArrayBufferView>, outputs: Record<string, ArrayBufferView>): Promise<MLComputeResult>;
|
|
32
|
+
}
|
|
33
|
+
interface MLGraph {
|
|
34
|
+
}
|
|
35
|
+
interface MLComputeResult {
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=WebNNContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebNNContext.d.ts","sourceRoot":"","sources":["../../src/webnn/WebNNContext.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAEpD,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAe;IACtC,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,UAAU,CAA0B;IAC5C,OAAO,CAAC,WAAW,CAAkB;IAErC,OAAO;IAEP,MAAM,CAAC,WAAW,IAAI,YAAY;IAOlC;;OAEG;IACG,UAAU,CAAC,UAAU,GAAE,eAAuB,GAAG,OAAO,CAAC,OAAO,CAAC;IAuCvE,UAAU,IAAI,SAAS,GAAG,IAAI;IAI9B,aAAa,IAAI,eAAe;IAIhC,WAAW,IAAI,OAAO;CAGvB;AAGD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,SAAS;QACjB,EAAE,EAAE;YACF,aAAa,CAAC,OAAO,CAAC,EAAE;gBAAE,UAAU,CAAC,EAAE,MAAM,CAAA;aAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;SACtE,CAAC;KACH;IAED,UAAU,SAAS;QAEjB,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;KACtI;IAED,UAAU,OAAO;KAEhB;IAED,UAAU,eAAe;KAExB;CACF"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebNN Context Manager
|
|
3
|
+
* Handles the creation and management of the WebNN MLContext.
|
|
4
|
+
* Prioritizes NPU -> GPU -> CPU.
|
|
5
|
+
*/
|
|
6
|
+
export class WebNNContext {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.context = null;
|
|
9
|
+
this.deviceType = 'cpu';
|
|
10
|
+
this.isSupported = false;
|
|
11
|
+
}
|
|
12
|
+
static getInstance() {
|
|
13
|
+
if (!WebNNContext.instance) {
|
|
14
|
+
WebNNContext.instance = new WebNNContext();
|
|
15
|
+
}
|
|
16
|
+
return WebNNContext.instance;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Initialize WebNN context with preferred device type.
|
|
20
|
+
*/
|
|
21
|
+
async initialize(preference = 'npu') {
|
|
22
|
+
if (typeof navigator === 'undefined' || !navigator.ml) {
|
|
23
|
+
console.warn('WebNN is not supported in this environment.');
|
|
24
|
+
this.isSupported = false;
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
// Try preferred device first
|
|
29
|
+
this.context = await navigator.ml.createContext({ deviceType: preference });
|
|
30
|
+
this.deviceType = preference;
|
|
31
|
+
this.isSupported = true;
|
|
32
|
+
console.log(`WebNN initialized successfully on ${preference}`);
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
console.warn(`Failed to initialize WebNN on ${preference}, trying fallback chain...`, e);
|
|
37
|
+
// Fallback chain: NPU -> GPU -> CPU
|
|
38
|
+
const chain = ['npu', 'gpu', 'cpu'];
|
|
39
|
+
const startIndex = chain.indexOf(preference) + 1;
|
|
40
|
+
for (let i = startIndex; i < chain.length; i++) {
|
|
41
|
+
const fallback = chain[i];
|
|
42
|
+
try {
|
|
43
|
+
this.context = await navigator.ml.createContext({ deviceType: fallback });
|
|
44
|
+
this.deviceType = fallback;
|
|
45
|
+
this.isSupported = true;
|
|
46
|
+
console.log(`WebNN initialized successfully on fallback ${fallback}`);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
console.warn(`Failed to initialize WebNN on fallback ${fallback}`, err);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
this.isSupported = false;
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
getContext() {
|
|
58
|
+
return this.context;
|
|
59
|
+
}
|
|
60
|
+
getDeviceType() {
|
|
61
|
+
return this.deviceType;
|
|
62
|
+
}
|
|
63
|
+
isAvailable() {
|
|
64
|
+
return this.isSupported && this.context !== null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure mathematical functions for hexgrid calculations.
|
|
3
|
+
* These functions have NO side effects, NO logging, and NO mutable state access.
|
|
4
|
+
* They are deterministic and testable in isolation.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Calculate the bounding box of a set of 2D/3D positions.
|
|
8
|
+
* @pure - No side effects, deterministic
|
|
9
|
+
* @param positions Array of [x, y, z] coordinates
|
|
10
|
+
* @returns Object with min/max bounds and dimensions
|
|
11
|
+
*/
|
|
12
|
+
export declare function getGridBounds(positions: [number, number, number][]): {
|
|
13
|
+
minX: number;
|
|
14
|
+
maxX: number;
|
|
15
|
+
minY: number;
|
|
16
|
+
maxY: number;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Calculate Euclidean distance between two 3D points with optional spherical wrapping.
|
|
22
|
+
* @pure - No side effects, deterministic
|
|
23
|
+
* @param a First point [x, y, z]
|
|
24
|
+
* @param b Second point [x, y, z]
|
|
25
|
+
* @param bounds Grid bounds for spherical calculation
|
|
26
|
+
* @param isSpherical Whether to apply spherical wrapping (toroidal distance)
|
|
27
|
+
* @returns Euclidean distance
|
|
28
|
+
*/
|
|
29
|
+
export declare function distanceBetween(a: [number, number, number], b: [number, number, number], bounds: {
|
|
30
|
+
width: number;
|
|
31
|
+
height: number;
|
|
32
|
+
}, isSpherical: boolean): number;
|
|
33
|
+
/**
|
|
34
|
+
* Calculate UV texture coordinates for a tile based on its grid position.
|
|
35
|
+
* @pure - No side effects, deterministic
|
|
36
|
+
* @param gridCol Column index (0-based)
|
|
37
|
+
* @param gridRow Row index (0-based)
|
|
38
|
+
* @param tilesX Total number of columns in texture grid
|
|
39
|
+
* @param tilesY Total number of rows in texture grid
|
|
40
|
+
* @returns [minU, minV, maxU, maxV] in range [0, 1]
|
|
41
|
+
*
|
|
42
|
+
* Note: V=1.0 represents the top of the texture.
|
|
43
|
+
* Row 0 maps to top, so maxV=1 and minV=1-1/tilesY.
|
|
44
|
+
*/
|
|
45
|
+
export declare function calculateUvBoundsFromGridPosition(gridCol: number, gridRow: number, tilesX: number, tilesY: number): [number, number, number, number];
|
|
46
|
+
/**
|
|
47
|
+
* Calculate contiguity score between indices (internal connectivity).
|
|
48
|
+
* Higher score means more indices in the set are neighbors with each other.
|
|
49
|
+
* @pure - No side effects, deterministic
|
|
50
|
+
* @param indices Set of position indices to measure
|
|
51
|
+
* @param positions Array of all positions
|
|
52
|
+
* @param hexRadius Radius for neighbor detection
|
|
53
|
+
* @param getNeighbors Function to get neighbors for an index (dependency injection)
|
|
54
|
+
* @returns Sum of neighbor connections within the set
|
|
55
|
+
*/
|
|
56
|
+
export declare function calculateContiguity(indices: number[], positions: [number, number, number][], hexRadius: number, getNeighbors: (index: number) => number[]): number;
|
|
57
|
+
/**
|
|
58
|
+
* Calculate contiguity score for a photo's indices.
|
|
59
|
+
* @pure - No side effects, deterministic
|
|
60
|
+
* @param indices Indices belonging to a photo
|
|
61
|
+
* @param positions Array of all positions
|
|
62
|
+
* @param hexRadius Radius for neighbor detection
|
|
63
|
+
* @param getNeighbors Function to get neighbors for an index
|
|
64
|
+
* @returns Total contiguity score
|
|
65
|
+
*/
|
|
66
|
+
export declare function calculatePhotoContiguity(indices: number[], positions: [number, number, number][], hexRadius: number, getNeighbors: (index: number) => number[]): number;
|
|
67
|
+
/**
|
|
68
|
+
* Calculate contiguity after a hypothetical swap of two indices.
|
|
69
|
+
* @pure - No side effects, deterministic
|
|
70
|
+
* @param indices Current indices
|
|
71
|
+
* @param positions Array of all positions
|
|
72
|
+
* @param hexRadius Radius for neighbor detection
|
|
73
|
+
* @param fromIndex Index to swap from
|
|
74
|
+
* @param toIndex Index to swap to
|
|
75
|
+
* @param getNeighbors Function to get neighbors for an index
|
|
76
|
+
* @returns Contiguity score after swap
|
|
77
|
+
*/
|
|
78
|
+
export declare function calculateSwappedContiguity(indices: number[], positions: [number, number, number][], hexRadius: number, fromIndex: number, toIndex: number, getNeighbors: (index: number) => number[]): number;
|
|
79
|
+
//# sourceMappingURL=hexgrid-math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hexgrid-math.d.ts","sourceRoot":"","sources":["../../src/workers/hexgrid-math.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;;;;;;;EAmBlE;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAC3B,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAC3B,MAAM,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EACzC,WAAW,EAAE,OAAO,GACnB,MAAM,CAeR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iCAAiC,CAC/C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAalC;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EAAE,EACjB,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EACrC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EAAE,GACxC,MAAM,CAgBR;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,EAAE,EACjB,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EACrC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EAAE,GACxC,MAAM,CAER;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,MAAM,EAAE,EACjB,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EACrC,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EAAE,GACxC,MAAM,CAgBR"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure mathematical functions for hexgrid calculations.
|
|
3
|
+
* These functions have NO side effects, NO logging, and NO mutable state access.
|
|
4
|
+
* They are deterministic and testable in isolation.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Calculate the bounding box of a set of 2D/3D positions.
|
|
8
|
+
* @pure - No side effects, deterministic
|
|
9
|
+
* @param positions Array of [x, y, z] coordinates
|
|
10
|
+
* @returns Object with min/max bounds and dimensions
|
|
11
|
+
*/
|
|
12
|
+
export function getGridBounds(positions) {
|
|
13
|
+
if (!positions || positions.length === 0) {
|
|
14
|
+
return { minX: 0, maxX: 0, minY: 0, maxY: 0, width: 0, height: 0 };
|
|
15
|
+
}
|
|
16
|
+
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
|
|
17
|
+
for (const p of positions) {
|
|
18
|
+
if (!p)
|
|
19
|
+
continue;
|
|
20
|
+
minX = Math.min(minX, p[0]);
|
|
21
|
+
maxX = Math.max(maxX, p[0]);
|
|
22
|
+
minY = Math.min(minY, p[1]);
|
|
23
|
+
maxY = Math.max(maxY, p[1]);
|
|
24
|
+
}
|
|
25
|
+
return { minX, maxX, minY, maxY, width: maxX - minX, height: maxY - minY };
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Calculate Euclidean distance between two 3D points with optional spherical wrapping.
|
|
29
|
+
* @pure - No side effects, deterministic
|
|
30
|
+
* @param a First point [x, y, z]
|
|
31
|
+
* @param b Second point [x, y, z]
|
|
32
|
+
* @param bounds Grid bounds for spherical calculation
|
|
33
|
+
* @param isSpherical Whether to apply spherical wrapping (toroidal distance)
|
|
34
|
+
* @returns Euclidean distance
|
|
35
|
+
*/
|
|
36
|
+
export function distanceBetween(a, b, bounds, isSpherical) {
|
|
37
|
+
let dx = b[0] - a[0];
|
|
38
|
+
let dy = b[1] - a[1];
|
|
39
|
+
if (isSpherical && bounds.width > 0 && bounds.height > 0) {
|
|
40
|
+
// Apply toroidal wrapping: shortest distance considering wraparound
|
|
41
|
+
if (Math.abs(dx) > bounds.width / 2) {
|
|
42
|
+
dx = dx > 0 ? dx - bounds.width : dx + bounds.width;
|
|
43
|
+
}
|
|
44
|
+
if (Math.abs(dy) > bounds.height / 2) {
|
|
45
|
+
dy = dy > 0 ? dy - bounds.height : dy + bounds.height;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Calculate UV texture coordinates for a tile based on its grid position.
|
|
52
|
+
* @pure - No side effects, deterministic
|
|
53
|
+
* @param gridCol Column index (0-based)
|
|
54
|
+
* @param gridRow Row index (0-based)
|
|
55
|
+
* @param tilesX Total number of columns in texture grid
|
|
56
|
+
* @param tilesY Total number of rows in texture grid
|
|
57
|
+
* @returns [minU, minV, maxU, maxV] in range [0, 1]
|
|
58
|
+
*
|
|
59
|
+
* Note: V=1.0 represents the top of the texture.
|
|
60
|
+
* Row 0 maps to top, so maxV=1 and minV=1-1/tilesY.
|
|
61
|
+
*/
|
|
62
|
+
export function calculateUvBoundsFromGridPosition(gridCol, gridRow, tilesX, tilesY) {
|
|
63
|
+
// Guard against invalid grid dimensions
|
|
64
|
+
if (tilesX <= 0 || tilesY <= 0) {
|
|
65
|
+
return [0, 0, 1, 1];
|
|
66
|
+
}
|
|
67
|
+
const minU = gridCol / tilesX;
|
|
68
|
+
const maxU = (gridCol + 1) / tilesX;
|
|
69
|
+
// V=1 is top, so row 0 maps to top (maxV=1, minV=1-1/tilesY)
|
|
70
|
+
const minV = 1 - (gridRow + 1) / tilesY;
|
|
71
|
+
const maxV = 1 - gridRow / tilesY;
|
|
72
|
+
return [minU, minV, maxU, maxV];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Calculate contiguity score between indices (internal connectivity).
|
|
76
|
+
* Higher score means more indices in the set are neighbors with each other.
|
|
77
|
+
* @pure - No side effects, deterministic
|
|
78
|
+
* @param indices Set of position indices to measure
|
|
79
|
+
* @param positions Array of all positions
|
|
80
|
+
* @param hexRadius Radius for neighbor detection
|
|
81
|
+
* @param getNeighbors Function to get neighbors for an index (dependency injection)
|
|
82
|
+
* @returns Sum of neighbor connections within the set
|
|
83
|
+
*/
|
|
84
|
+
export function calculateContiguity(indices, positions, hexRadius, getNeighbors) {
|
|
85
|
+
if (!indices || indices.length === 0)
|
|
86
|
+
return 0;
|
|
87
|
+
if (!positions || positions.length === 0)
|
|
88
|
+
return 0;
|
|
89
|
+
if (hexRadius <= 0)
|
|
90
|
+
return 0;
|
|
91
|
+
const set = new Set(indices);
|
|
92
|
+
let total = 0;
|
|
93
|
+
for (const idx of indices) {
|
|
94
|
+
const neighbors = getNeighbors(idx);
|
|
95
|
+
for (const n of neighbors) {
|
|
96
|
+
if (set.has(n))
|
|
97
|
+
total++;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return total;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Calculate contiguity score for a photo's indices.
|
|
104
|
+
* @pure - No side effects, deterministic
|
|
105
|
+
* @param indices Indices belonging to a photo
|
|
106
|
+
* @param positions Array of all positions
|
|
107
|
+
* @param hexRadius Radius for neighbor detection
|
|
108
|
+
* @param getNeighbors Function to get neighbors for an index
|
|
109
|
+
* @returns Total contiguity score
|
|
110
|
+
*/
|
|
111
|
+
export function calculatePhotoContiguity(indices, positions, hexRadius, getNeighbors) {
|
|
112
|
+
return calculateContiguity(indices, positions, hexRadius, getNeighbors);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Calculate contiguity after a hypothetical swap of two indices.
|
|
116
|
+
* @pure - No side effects, deterministic
|
|
117
|
+
* @param indices Current indices
|
|
118
|
+
* @param positions Array of all positions
|
|
119
|
+
* @param hexRadius Radius for neighbor detection
|
|
120
|
+
* @param fromIndex Index to swap from
|
|
121
|
+
* @param toIndex Index to swap to
|
|
122
|
+
* @param getNeighbors Function to get neighbors for an index
|
|
123
|
+
* @returns Contiguity score after swap
|
|
124
|
+
*/
|
|
125
|
+
export function calculateSwappedContiguity(indices, positions, hexRadius, fromIndex, toIndex, getNeighbors) {
|
|
126
|
+
if (!indices || indices.length === 0)
|
|
127
|
+
return 0;
|
|
128
|
+
const tempIndices = [...indices];
|
|
129
|
+
const fromPos = tempIndices.indexOf(fromIndex);
|
|
130
|
+
const toPos = tempIndices.indexOf(toIndex);
|
|
131
|
+
if (fromPos !== -1)
|
|
132
|
+
tempIndices[fromPos] = toIndex;
|
|
133
|
+
if (toPos !== -1)
|
|
134
|
+
tempIndices[toPos] = fromIndex;
|
|
135
|
+
return calculatePhotoContiguity(tempIndices, positions, hexRadius, getNeighbors);
|
|
136
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface Photo {
|
|
2
|
+
id: string;
|
|
3
|
+
title?: string;
|
|
4
|
+
alt?: string;
|
|
5
|
+
imageUrl?: string;
|
|
6
|
+
velocity?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface Infection {
|
|
9
|
+
photo: Photo;
|
|
10
|
+
gridPosition: [number, number];
|
|
11
|
+
infectionTime: number;
|
|
12
|
+
generation: number;
|
|
13
|
+
uvBounds: [number, number, number, number];
|
|
14
|
+
scale: number;
|
|
15
|
+
growthRate?: number;
|
|
16
|
+
tilesX?: number;
|
|
17
|
+
tilesY?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface InfectionSystemState {
|
|
20
|
+
infections: Map<number, Infection>;
|
|
21
|
+
availableIndices: number[];
|
|
22
|
+
lastEvolutionTime: number;
|
|
23
|
+
generation: number;
|
|
24
|
+
tileCenters?: Array<{
|
|
25
|
+
photoId: string;
|
|
26
|
+
clusterIndex: number;
|
|
27
|
+
centers: Array<{
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
col: number;
|
|
31
|
+
row: number;
|
|
32
|
+
}>;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=hexgrid-worker.worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hexgrid-worker.worker.d.ts","sourceRoot":"","sources":["../../src/workers/hexgrid-worker.worker.ts"],"names":[],"mappings":"AAiBA,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AACD,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,KAAK,CAAC;IACb,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AACD,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACnC,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,KAAK,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,OAAO,EAAE,KAAK,CAAC;YAAE,CAAC,EAAE,MAAM,CAAC;YAAC,CAAC,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KACpE,CAAC,CAAC;CACJ"}
|