UNPKG

automata-metaverse

Version:

Automaton execution engines for self-referential CanvasL/JSONL systems

111 lines 4.2 kB
/** * A₃: Volume Shaper Automaton * * Role: C₃ interface triple/volume management (TopoJSON format) * Uses meta-log-db: r5rs:export-3d, r5rs:topojson-to-geojson */ import { BaseAutomaton } from './types.js'; /** * A₃: Volume Shaper Automaton * * Manages C₃ interface triples/volumes (3-cells) and shapes volumes from faces */ export class A3_VolumeShaper extends BaseAutomaton { constructor(db) { super(); this.db = db; this.id = 3; this.name = 'A₃ Volume Shaper'; this.role = 'C₃ interface triple/volume management (TopoJSON format)'; this.state = { volumes: [], initialized: false }; } async tick(swarm) { if (!this.state.initialized) { await this.initialize(swarm); } // Volume shaping happens based on faces from A₂ const a2 = swarm.get(2); if (a2 && 'getFaces' in a2 && typeof a2.getFaces === 'function') { const faces = a2.getFaces(); await this.shapeVolumes(faces); } } async initialize(swarm) { this.state.initialized = true; console.log('A₃: Volume Shaper initialized'); } async shapeVolumes(faces) { if (!this.db || faces.length < 4) { return; } try { // Create volumes from closed sets of faces // Simple implementation: create a volume from every 4+ face set const newVolumes = []; // Find closed sets of faces (simplified: every 4 consecutive faces form a volume) for (let i = 0; i < faces.length - 3; i++) { const face1 = faces[i]; const face2 = faces[i + 1]; const face3 = faces[i + 2]; const face4 = faces[i + 3]; // Check if faces share edges (form a closed volume) const allEdges = new Set([ ...face1.edges, ...face2.edges, ...face3.edges, ...face4.edges ]); // If faces share edges, they form a volume if (allEdges.size < face1.edges.length + face2.edges.length + face3.edges.length + face4.edges.length) { const volumeId = `volume-${face1.id}-${face2.id}-${face3.id}-${face4.id}`; if (!this.state.volumes.find(v => v.id === volumeId)) { newVolumes.push({ id: volumeId, faces: [face1.id, face2.id, face3.id, face4.id] }); } } } if (newVolumes.length === 0) { return; } // Create C₃ cells (volumes) using meta-log-db const cells = await Promise.all(newVolumes.map(volume => this.db.executeR5RS('r5rs:create-cell', [ 3, // dimension (3-cell) volume.id, volume.faces, // boundary: faces that form the volume { faces: volume.faces, type: 'volume' } ]))); // Build chain complex with volumes const complex = await this.db.executeR5RS('r5rs:build-chain-complex', [cells]); // Export to 3D (TopoJSON) const topojson = await this.db.executeR5RS('r5rs:export-3d', [complex]); const topo = JSON.parse(topojson); // Update state this.state.volumes.push(...newVolumes.map((v, i) => ({ id: v.id, faces: v.faces, data: topo.objects[Object.keys(topo.objects)[i]] || {} }))); console.log(`A₃: Shaped ${newVolumes.length} new volumes`); } catch (error) { console.error('A₃: Error shaping volumes:', error); } } async receive(from, message) { if (message.type === 'request-volumes') { // Could send volumes back to requester } } /** * Get all volumes */ getVolumes() { return this.state.volumes; } } //# sourceMappingURL=a3-volume-shaper.js.map