feat: implement debug node
All checks were successful
🚀 Lint & Test & Deploy / release (pull_request) Successful in 3m53s
All checks were successful
🚀 Lint & Test & Deploy / release (pull_request) Successful in 3m53s
Closes #39
This commit is contained in:
19
app/src/lib/result-viewer/Debug.svelte
Normal file
19
app/src/lib/result-viewer/Debug.svelte
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { T } from '@threlte/core';
|
||||||
|
import type { Group } from 'three';
|
||||||
|
import { updateDebugScene } from './debug';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
debugData?: Record<number, { type: string; data: Int32Array }>;
|
||||||
|
};
|
||||||
|
|
||||||
|
let group = $state<Group>(null!);
|
||||||
|
const { debugData }: Props = $props();
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (!group || !debugData) return;
|
||||||
|
updateDebugScene(group, $state.snapshot(debugData));
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<T.Group bind:ref={group} />
|
||||||
@@ -1,33 +1,26 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { colors } from '$lib/graph-interface/graph/colors.svelte';
|
import { colors } from '$lib/graph-interface/graph/colors.svelte';
|
||||||
import { T, useTask, useThrelte } from '@threlte/core';
|
import { T, useTask, useThrelte } from '@threlte/core';
|
||||||
import { Grid, MeshLineGeometry, MeshLineMaterial, Text } from '@threlte/extras';
|
import { Grid } from '@threlte/extras';
|
||||||
import {
|
import { Box3, type BufferGeometry, type Group, Mesh, MeshBasicMaterial, Vector3 } from 'three';
|
||||||
Box3,
|
|
||||||
type BufferGeometry,
|
|
||||||
type Group,
|
|
||||||
Mesh,
|
|
||||||
MeshBasicMaterial,
|
|
||||||
Vector3,
|
|
||||||
type Vector3Tuple
|
|
||||||
} from 'three';
|
|
||||||
import { appSettings } from '../settings/app-settings.svelte';
|
import { appSettings } from '../settings/app-settings.svelte';
|
||||||
import Camera from './Camera.svelte';
|
import Camera from './Camera.svelte';
|
||||||
|
import Debug from './Debug.svelte';
|
||||||
|
|
||||||
const { renderStage, invalidate: _invalidate } = useThrelte();
|
const { renderStage, invalidate: _invalidate } = useThrelte();
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
fps: number[];
|
fps: number[];
|
||||||
lines: Vector3[][];
|
debugData?: Record<number, { type: string; data: Int32Array }>;
|
||||||
scene: Group;
|
scene: Group;
|
||||||
centerCamera: boolean;
|
centerCamera: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
let {
|
let {
|
||||||
lines,
|
|
||||||
centerCamera,
|
centerCamera,
|
||||||
fps = $bindable(),
|
fps = $bindable(),
|
||||||
scene = $bindable()
|
scene = $bindable(),
|
||||||
|
debugData
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
let geometries = $state.raw<BufferGeometry[]>([]);
|
let geometries = $state.raw<BufferGeometry[]>([]);
|
||||||
@@ -91,18 +84,12 @@
|
|||||||
});
|
});
|
||||||
_invalidate();
|
_invalidate();
|
||||||
});
|
});
|
||||||
|
|
||||||
function getPosition(geo: BufferGeometry, i: number) {
|
|
||||||
return [
|
|
||||||
geo.attributes.position.array[i],
|
|
||||||
geo.attributes.position.array[i + 1],
|
|
||||||
geo.attributes.position.array[i + 2]
|
|
||||||
] as Vector3Tuple;
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Camera {center} {centerCamera} />
|
<Camera {center} {centerCamera} />
|
||||||
|
|
||||||
|
<Debug {debugData} />
|
||||||
|
|
||||||
{#if appSettings.value.showGrid}
|
{#if appSettings.value.showGrid}
|
||||||
<Grid
|
<Grid
|
||||||
cellColor={colors['outline']}
|
cellColor={colors['outline']}
|
||||||
@@ -116,35 +103,4 @@
|
|||||||
fadeOrigin={new Vector3(0, 0, 0)}
|
fadeOrigin={new Vector3(0, 0, 0)}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<T.Group>
|
|
||||||
{#if geometries}
|
|
||||||
{#each geometries as geo (geo.id)}
|
|
||||||
{#if appSettings.value.debug.showIndices}
|
|
||||||
{#each geo.attributes.position.array, i (i)}
|
|
||||||
{#if i % 3 === 0}
|
|
||||||
<Text fontSize={0.25} position={getPosition(geo, i)} />
|
|
||||||
{/if}
|
|
||||||
{/each}
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if appSettings.value.debug.showVertices}
|
|
||||||
<T.Points visible={true}>
|
|
||||||
<T is={geo} />
|
|
||||||
<T.PointsMaterial size={0.25} />
|
|
||||||
</T.Points>
|
|
||||||
{/if}
|
|
||||||
{/each}
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<T.Group bind:ref={scene}></T.Group>
|
<T.Group bind:ref={scene}></T.Group>
|
||||||
</T.Group>
|
|
||||||
|
|
||||||
{#if appSettings.value.debug.showStemLines && lines}
|
|
||||||
{#each lines as line (line[0].x + '-' + line[0].y + '-' + '' + line[0].z)}
|
|
||||||
<T.Mesh>
|
|
||||||
<MeshLineGeometry points={line} />
|
|
||||||
<MeshLineMaterial width={0.1} color="red" depthTest={false} />
|
|
||||||
</T.Mesh>
|
|
||||||
{/each}
|
|
||||||
{/if}
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import SmallPerformanceViewer from '$lib/performance/SmallPerformanceViewer.svelte';
|
import SmallPerformanceViewer from '$lib/performance/SmallPerformanceViewer.svelte';
|
||||||
import { appSettings } from '$lib/settings/app-settings.svelte';
|
import { appSettings } from '$lib/settings/app-settings.svelte';
|
||||||
import { decodeFloat, splitNestedArray } from '@nodarium/utils';
|
import { splitNestedArray } from '@nodarium/utils';
|
||||||
import type { PerformanceStore } from '@nodarium/utils';
|
import type { PerformanceStore } from '@nodarium/utils';
|
||||||
import { Canvas } from '@threlte/core';
|
import { Canvas } from '@threlte/core';
|
||||||
import { DoubleSide, Vector3 } from 'three';
|
import { DoubleSide } from 'three';
|
||||||
import { type Group, MeshMatcapMaterial, TextureLoader } from 'three';
|
import { type Group, MeshMatcapMaterial, TextureLoader } from 'three';
|
||||||
import { createGeometryPool, createInstancedGeometryPool } from './geometryPool';
|
import { createGeometryPool, createInstancedGeometryPool } from './geometryPool';
|
||||||
import Scene from './Scene.svelte';
|
import Scene from './Scene.svelte';
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
let geometryPool: ReturnType<typeof createGeometryPool>;
|
let geometryPool: ReturnType<typeof createGeometryPool>;
|
||||||
let instancePool: ReturnType<typeof createInstancedGeometryPool>;
|
let instancePool: ReturnType<typeof createInstancedGeometryPool>;
|
||||||
|
|
||||||
export function updateGeometries(inputs: Int32Array[], group: Group) {
|
export function updateGeometries(inputs: Int32Array[], group: Group) {
|
||||||
geometryPool = geometryPool || createGeometryPool(group, material);
|
geometryPool = geometryPool || createGeometryPool(group, material);
|
||||||
instancePool = instancePool || createInstancedGeometryPool(group, material);
|
instancePool = instancePool || createInstancedGeometryPool(group, material);
|
||||||
@@ -40,44 +41,16 @@
|
|||||||
scene: Group;
|
scene: Group;
|
||||||
centerCamera: boolean;
|
centerCamera: boolean;
|
||||||
perf: PerformanceStore;
|
perf: PerformanceStore;
|
||||||
|
debugData?: Record<number, { type: string; data: Int32Array }>;
|
||||||
};
|
};
|
||||||
|
|
||||||
let { scene = $bindable(), centerCamera, perf }: Props = $props();
|
let { scene = $bindable(), centerCamera, debugData, perf }: Props = $props();
|
||||||
|
|
||||||
let lines = $state<Vector3[][]>([]);
|
|
||||||
|
|
||||||
function createLineGeometryFromEncodedData(encodedData: Int32Array) {
|
|
||||||
const positions: Vector3[] = [];
|
|
||||||
|
|
||||||
const amount = (encodedData.length - 1) / 4;
|
|
||||||
|
|
||||||
for (let i = 0; i < amount; i++) {
|
|
||||||
const x = decodeFloat(encodedData[2 + i * 4 + 0]);
|
|
||||||
const y = decodeFloat(encodedData[2 + i * 4 + 1]);
|
|
||||||
const z = decodeFloat(encodedData[2 + i * 4 + 2]);
|
|
||||||
positions.push(new Vector3(x, y, z));
|
|
||||||
}
|
|
||||||
|
|
||||||
return positions;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const update = function update(result: Int32Array) {
|
export const update = function update(result: Int32Array) {
|
||||||
perf.addPoint('split-result');
|
perf.addPoint('split-result');
|
||||||
const inputs = splitNestedArray(result);
|
const inputs = splitNestedArray(result);
|
||||||
perf.endPoint();
|
perf.endPoint();
|
||||||
|
|
||||||
if (appSettings.value.debug.showStemLines) {
|
|
||||||
perf.addPoint('create-lines');
|
|
||||||
lines = inputs
|
|
||||||
.map((input) => {
|
|
||||||
if (input[0] === 0) {
|
|
||||||
return createLineGeometryFromEncodedData(input);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.filter(Boolean) as Vector3[][];
|
|
||||||
perf.endPoint();
|
|
||||||
}
|
|
||||||
|
|
||||||
perf.addPoint('update-geometries');
|
perf.addPoint('update-geometries');
|
||||||
|
|
||||||
const { totalVertices, totalFaces } = updateGeometries(inputs, scene);
|
const { totalVertices, totalFaces } = updateGeometries(inputs, scene);
|
||||||
@@ -97,8 +70,8 @@
|
|||||||
<Canvas>
|
<Canvas>
|
||||||
<Scene
|
<Scene
|
||||||
bind:this={sceneComponent}
|
bind:this={sceneComponent}
|
||||||
{lines}
|
|
||||||
{centerCamera}
|
{centerCamera}
|
||||||
|
{debugData}
|
||||||
bind:scene
|
bind:scene
|
||||||
bind:fps
|
bind:fps
|
||||||
/>
|
/>
|
||||||
|
|||||||
90
app/src/lib/result-viewer/debug.ts
Normal file
90
app/src/lib/result-viewer/debug.ts
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
import { splitNestedArray } from '@nodarium/utils';
|
||||||
|
import {
|
||||||
|
BufferGeometry,
|
||||||
|
type Group,
|
||||||
|
InstancedMesh,
|
||||||
|
Line,
|
||||||
|
LineBasicMaterial,
|
||||||
|
Matrix4,
|
||||||
|
MeshBasicMaterial,
|
||||||
|
SphereGeometry,
|
||||||
|
Vector3
|
||||||
|
} from 'three';
|
||||||
|
|
||||||
|
function writePath(scene: Group, data: Int32Array): Vector3[] {
|
||||||
|
const positions: Vector3[] = [];
|
||||||
|
const f32 = new Float32Array(data.buffer);
|
||||||
|
|
||||||
|
for (let i = 2; i + 2 < f32.length; i += 4) {
|
||||||
|
const vec = new Vector3(f32[i], f32[i + 1], f32[i + 2]);
|
||||||
|
positions.push(vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Path line
|
||||||
|
if (positions.length >= 2) {
|
||||||
|
const geometry = new BufferGeometry().setFromPoints(positions);
|
||||||
|
const line = new Line(
|
||||||
|
geometry,
|
||||||
|
new LineBasicMaterial({ color: 0xff0000, depthTest: false })
|
||||||
|
);
|
||||||
|
scene.add(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Instanced spheres at points
|
||||||
|
if (positions.length > 0) {
|
||||||
|
const sphereGeometry = new SphereGeometry(0.05, 8, 8); // keep low-poly
|
||||||
|
const sphereMaterial = new MeshBasicMaterial({
|
||||||
|
color: 0xff0000,
|
||||||
|
depthTest: false
|
||||||
|
});
|
||||||
|
|
||||||
|
const spheres = new InstancedMesh(
|
||||||
|
sphereGeometry,
|
||||||
|
sphereMaterial,
|
||||||
|
positions.length
|
||||||
|
);
|
||||||
|
|
||||||
|
const matrix = new Matrix4();
|
||||||
|
for (let i = 0; i < positions.length; i++) {
|
||||||
|
matrix.makeTranslation(
|
||||||
|
positions[i].x,
|
||||||
|
positions[i].y,
|
||||||
|
positions[i].z
|
||||||
|
);
|
||||||
|
spheres.setMatrixAt(i, matrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
spheres.instanceMatrix.needsUpdate = true;
|
||||||
|
scene.add(spheres);
|
||||||
|
}
|
||||||
|
|
||||||
|
return positions;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearGroup(group: Group) {
|
||||||
|
for (let i = group.children.length - 1; i >= 0; i--) {
|
||||||
|
const child = group.children[i];
|
||||||
|
group.remove(child);
|
||||||
|
// optional but correct: free GPU memory
|
||||||
|
// @ts-expect-error three.js runtime fields
|
||||||
|
child.geometry?.dispose?.();
|
||||||
|
// @ts-expect-error three.js runtime fields
|
||||||
|
child.material?.dispose?.();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updateDebugScene(
|
||||||
|
group: Group,
|
||||||
|
data: Record<number, { type: string; data: Int32Array }>
|
||||||
|
) {
|
||||||
|
clearGroup(group);
|
||||||
|
return Object.entries(data || {}).map(([, d]) => {
|
||||||
|
switch (d.type) {
|
||||||
|
case 'path':
|
||||||
|
splitNestedArray(d.data)
|
||||||
|
.forEach(p => writePath(group, p));
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
return (_g: Group) => {};
|
||||||
|
}).flat();
|
||||||
|
}
|
||||||
@@ -59,7 +59,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
|||||||
private definitionMap: Map<string, NodeDefinition> = new Map();
|
private definitionMap: Map<string, NodeDefinition> = new Map();
|
||||||
|
|
||||||
private seed = Math.floor(Math.random() * 100000000);
|
private seed = Math.floor(Math.random() * 100000000);
|
||||||
private debugData: Record<string, Int32Array> = {};
|
private debugData: Record<number, { type: string; data: Int32Array }> = {};
|
||||||
|
|
||||||
perf?: PerformanceStore;
|
perf?: PerformanceStore;
|
||||||
|
|
||||||
@@ -143,8 +143,8 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
|||||||
for (const node of graphNodes) {
|
for (const node of graphNodes) {
|
||||||
if (node.type.endsWith('/debug')) {
|
if (node.type.endsWith('/debug')) {
|
||||||
node.state = node.state || {};
|
node.state = node.state || {};
|
||||||
node.state.depth = Math.min(...node.state.parents.map(s => s.state.depth), 1) - 1;
|
const parent = node.state.parents[0];
|
||||||
nodes.push(node);
|
parent.state.debugNode = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,6 +247,12 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
|||||||
log.log(`Using cached value for ${node_type.id || node.id}`);
|
log.log(`Using cached value for ${node_type.id || node.id}`);
|
||||||
this.perf?.addPoint('cache-hit', 1);
|
this.perf?.addPoint('cache-hit', 1);
|
||||||
results[node.id] = cachedValue as Int32Array;
|
results[node.id] = cachedValue as Int32Array;
|
||||||
|
if (node.state.debugNode && node_type.outputs) {
|
||||||
|
this.debugData[node.id] = {
|
||||||
|
type: node_type.outputs[0],
|
||||||
|
data: cachedValue
|
||||||
|
};
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this.perf?.addPoint('cache-hit', 0);
|
this.perf?.addPoint('cache-hit', 0);
|
||||||
@@ -255,8 +261,11 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
|||||||
log.log(`Inputs:`, inputs);
|
log.log(`Inputs:`, inputs);
|
||||||
a = performance.now();
|
a = performance.now();
|
||||||
results[node.id] = node_type.execute(encoded_inputs);
|
results[node.id] = node_type.execute(encoded_inputs);
|
||||||
if (node_type.id.endsWith('/debug')) {
|
if (node.state.debugNode && node_type.outputs) {
|
||||||
this.debugData[node.id] = results[node.id];
|
this.debugData[node.id] = {
|
||||||
|
type: node_type.outputs[0],
|
||||||
|
data: results[node.id]
|
||||||
|
};
|
||||||
}
|
}
|
||||||
log.log('Executed', node.type, node.id);
|
log.log('Executed', node.type, node.id);
|
||||||
b = performance.now();
|
b = performance.now();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ type RuntimeState = {
|
|||||||
parents: RuntimeNode[];
|
parents: RuntimeNode[];
|
||||||
children: RuntimeNode[];
|
children: RuntimeNode[];
|
||||||
inputNodes: Record<string, RuntimeNode>;
|
inputNodes: Record<string, RuntimeNode>;
|
||||||
|
debugNode?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RuntimeNode = SerializedNode & { state: RuntimeState };
|
export type RuntimeNode = SerializedNode & { state: RuntimeState };
|
||||||
|
|||||||
@@ -6,12 +6,15 @@ export class WorkerRuntimeExecutor implements RuntimeExecutor {
|
|||||||
new URL(`./worker-runtime-executor-backend.ts`, import.meta.url)
|
new URL(`./worker-runtime-executor-backend.ts`, import.meta.url)
|
||||||
);
|
);
|
||||||
|
|
||||||
async execute(graph: Graph, settings: Record<string, unknown>) {
|
execute(graph: Graph, settings: Record<string, unknown>) {
|
||||||
return this.worker.executeGraph(graph, settings);
|
return this.worker.executeGraph(graph, settings);
|
||||||
}
|
}
|
||||||
async getPerformanceData() {
|
getPerformanceData() {
|
||||||
return this.worker.getPerformanceData();
|
return this.worker.getPerformanceData();
|
||||||
}
|
}
|
||||||
|
getDebugData() {
|
||||||
|
return this.worker.getDebugData();
|
||||||
|
}
|
||||||
set useRuntimeCache(useCache: boolean) {
|
set useRuntimeCache(useCache: boolean) {
|
||||||
this.worker.setUseRuntimeCache(useCache);
|
this.worker.setUseRuntimeCache(useCache);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,26 +59,11 @@ export const AppSettingTypes = {
|
|||||||
label: 'Execute in WebWorker',
|
label: 'Execute in WebWorker',
|
||||||
value: true
|
value: true
|
||||||
},
|
},
|
||||||
showIndices: {
|
|
||||||
type: 'boolean',
|
|
||||||
label: 'Show Indices',
|
|
||||||
value: false
|
|
||||||
},
|
|
||||||
advancedMode: {
|
advancedMode: {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
label: 'Advanced Mode',
|
label: 'Advanced Mode',
|
||||||
value: false
|
value: false
|
||||||
},
|
},
|
||||||
showVertices: {
|
|
||||||
type: 'boolean',
|
|
||||||
label: 'Show Vertices',
|
|
||||||
value: false
|
|
||||||
},
|
|
||||||
showStemLines: {
|
|
||||||
type: 'boolean',
|
|
||||||
label: 'Show Stem Lines',
|
|
||||||
value: false
|
|
||||||
},
|
|
||||||
cache: {
|
cache: {
|
||||||
title: 'Cache',
|
title: 'Cache',
|
||||||
useRuntimeCache: {
|
useRuntimeCache: {
|
||||||
|
|||||||
@@ -42,11 +42,13 @@
|
|||||||
const store: Store = {};
|
const store: Store = {};
|
||||||
Object.keys(inputs).forEach((key) => {
|
Object.keys(inputs).forEach((key) => {
|
||||||
if (props) {
|
if (props) {
|
||||||
const value = props[key] || inputs[key].value;
|
const value = props[key] !== undefined ? props[key] : inputs[key].value;
|
||||||
if (Array.isArray(value) || typeof value === 'number') {
|
if (Array.isArray(value) || typeof value === 'number') {
|
||||||
store[key] = value;
|
store[key] = value;
|
||||||
|
} else if (typeof value === 'boolean') {
|
||||||
|
store[key] = value ? 1 : 0;
|
||||||
} else {
|
} else {
|
||||||
console.error('Wrong error');
|
console.error('Wrong error', { value });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -68,6 +68,7 @@
|
|||||||
let sidebarOpen = $state(false);
|
let sidebarOpen = $state(false);
|
||||||
let graphInterface = $state<ReturnType<typeof GraphInterface>>(null!);
|
let graphInterface = $state<ReturnType<typeof GraphInterface>>(null!);
|
||||||
let viewerComponent = $state<ReturnType<typeof Viewer>>();
|
let viewerComponent = $state<ReturnType<typeof Viewer>>();
|
||||||
|
let debugData = $state<Record<number, { type: string; data: Int32Array }>>();
|
||||||
const manager = $derived(graphInterface?.manager);
|
const manager = $derived(graphInterface?.manager);
|
||||||
|
|
||||||
async function randomGenerate() {
|
async function randomGenerate() {
|
||||||
@@ -107,6 +108,7 @@
|
|||||||
|
|
||||||
if (appSettings.value.debug.useWorker) {
|
if (appSettings.value.debug.useWorker) {
|
||||||
let perfData = await runtime.getPerformanceData();
|
let perfData = await runtime.getPerformanceData();
|
||||||
|
debugData = await runtime.getDebugData();
|
||||||
let lastRun = perfData?.at(-1);
|
let lastRun = perfData?.at(-1);
|
||||||
if (lastRun?.total) {
|
if (lastRun?.total) {
|
||||||
lastRun.runtime = lastRun.total;
|
lastRun.runtime = lastRun.total;
|
||||||
@@ -165,6 +167,7 @@
|
|||||||
bind:scene
|
bind:scene
|
||||||
bind:this={viewerComponent}
|
bind:this={viewerComponent}
|
||||||
perf={performanceStore}
|
perf={performanceStore}
|
||||||
|
debugData={debugData}
|
||||||
centerCamera={appSettings.value.centerCamera}
|
centerCamera={appSettings.value.centerCamera}
|
||||||
/>
|
/>
|
||||||
</Grid.Cell>
|
</Grid.Cell>
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
import { expect, test } from 'vitest';
|
import { expect, test } from 'vitest';
|
||||||
import { concatEncodedArrays, decodeNestedArray, encodeNestedArray } from './flatTree';
|
import {
|
||||||
|
concatEncodedArrays,
|
||||||
|
decodeNestedArray,
|
||||||
|
encodeNestedArray,
|
||||||
|
splitNestedArray
|
||||||
|
} from './flatTree';
|
||||||
|
|
||||||
test('it correctly concats nested arrays', () => {
|
test('it correctly concats nested arrays', () => {
|
||||||
const input_a = encodeNestedArray([1, 2, 3]);
|
const input_a = encodeNestedArray([1, 2, 3]);
|
||||||
@@ -82,3 +87,80 @@ test('it correctly handles arrays with mixed data types', () => {
|
|||||||
const decoded = decodeNestedArray(encodeNestedArray(input));
|
const decoded = decodeNestedArray(encodeNestedArray(input));
|
||||||
expect(decoded).toEqual(input);
|
expect(decoded).toEqual(input);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Test splitNestedArray function
|
||||||
|
test('it splits nested array into segments based on structure', () => {
|
||||||
|
const input = [[1, 2], [3, 4]];
|
||||||
|
const encoded = new Int32Array(encodeNestedArray(input));
|
||||||
|
const split = splitNestedArray(encoded);
|
||||||
|
|
||||||
|
// Based on the actual behavior, splitNestedArray returns segments
|
||||||
|
// but the specific behavior needs to match the implementation
|
||||||
|
expect(Array.isArray(split)).toBe(true);
|
||||||
|
expect(split.length).toBe(2);
|
||||||
|
expect(split[0][0]).toBe(1);
|
||||||
|
expect(split[0][1]).toBe(2);
|
||||||
|
expect(split[1][0]).toBe(3);
|
||||||
|
expect(split[1][1]).toBe(4);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Test splitNestedArray function
|
||||||
|
test('it splits nested array into segments based on structure 2', () => {
|
||||||
|
// dprint-ignore
|
||||||
|
const encoded = new Int32Array([
|
||||||
|
0, 1,
|
||||||
|
0, 19,
|
||||||
|
0, 1,
|
||||||
|
0, 0, 0, 1060487823,
|
||||||
|
1067592955, 1079491492, -1086248132, 1056069822,
|
||||||
|
-1078247113, 1086620820, 1073133800, 1047681214,
|
||||||
|
-1068353940, 1094067306, 1078792112, 0,
|
||||||
|
1, 1,
|
||||||
|
0, 19,
|
||||||
|
0, 1,
|
||||||
|
0, 0, 0, 1060487823,
|
||||||
|
-1089446963, 1080524584, 1041006274, 1056069822,
|
||||||
|
-1092176382, 1087031528, -1088851934, 1047681214,
|
||||||
|
1081482392, 1094426140, -1107842261, 0,
|
||||||
|
1, 1,
|
||||||
|
1, 1
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Should be split into two seperate arrays
|
||||||
|
const split = splitNestedArray(encoded);
|
||||||
|
|
||||||
|
// Based on the actual behavior, splitNestedArray returns segments
|
||||||
|
// but the specific behavior needs to match the implementation
|
||||||
|
expect(Array.isArray(split)).toBe(true);
|
||||||
|
expect(split.length).toBe(2);
|
||||||
|
expect(split[0][0]).toBe(0);
|
||||||
|
expect(split[0][1]).toBe(1);
|
||||||
|
expect(split[1][0]).toBe(0);
|
||||||
|
expect(split[1][1]).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Test splitNestedArray function
|
||||||
|
test('it splits nested array into segments based on structure 2', () => {
|
||||||
|
// dprint-ignore
|
||||||
|
const encoded = new Int32Array( [
|
||||||
|
0, 1,
|
||||||
|
0, 27,
|
||||||
|
0, 1,
|
||||||
|
0, 0, 0, 1065353216,
|
||||||
|
0, 1067757391, 0, 1061997773,
|
||||||
|
0, 1076145999, 0, 1058642330,
|
||||||
|
0, 1081542391, 0, 1053609164,
|
||||||
|
0, 1084534607, 0, 1045220556,
|
||||||
|
0, 1087232803, 0, 0,
|
||||||
|
1, 1,
|
||||||
|
1, 1
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Should be split into two seperate arrays
|
||||||
|
const split = splitNestedArray(encoded);
|
||||||
|
|
||||||
|
// Based on the actual behavior, splitNestedArray returns segments
|
||||||
|
// but the specific behavior needs to match the implementation
|
||||||
|
expect(Array.isArray(split)).toBe(true);
|
||||||
|
expect(split.length).toBe(1);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user