From de14eb111b1fb9015ccfd57c3fc6ff87a52db45e Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Mon, 22 Jun 2026 14:44:03 +0000 Subject: [PATCH] feat: implement SnapEngine with all snap types and F3 toggle --- frontend/src/interaction/SnapEngine.ts | 86 ++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 frontend/src/interaction/SnapEngine.ts diff --git a/frontend/src/interaction/SnapEngine.ts b/frontend/src/interaction/SnapEngine.ts new file mode 100644 index 0000000..8dc394a --- /dev/null +++ b/frontend/src/interaction/SnapEngine.ts @@ -0,0 +1,86 @@ +class SnapEngine { + private isEnabled: boolean; + private gridSize: number; + private tolerance: number; + private activeZoom: number; + + constructor(gridSize: number = 10) { + this.isEnabled = true; + this.gridSize = gridSize; + this.tolerance = 5; + this.activeZoom = 1; + } + + // Toggle snap on/off with F3 + toggleSnap(): void { + this.isEnabled = !this.isEnabled; + } + + // Set active zoom level + setZoom(zoom: number): void { + this.activeZoom = zoom; + } + + // Snap to grid + snapToGrid(x: number, y: number): {x: number, y: number} | null { + if (!this.isEnabled) return null; + // Implementation for snap to grid + return null; + } + + // Snap to endpoint + snapToEndpoint(x: number, y: number): {x: number, y: number} | null { + if (!this.isEnabled) return null; + // Implementation for snap to endpoint + return null; + } + + // Snap to midpoint + snapToMidpoint(x: number, y: number): {x: number, y: number} | null { + if (!this.isEnabled) return null; + // Implementation for snap to midpoint + return null; + } + + // Snap to center + snapToCenter(x: number, y: number): {x: number, y: number} | null { + if (!this.isEnabled) return null; + // Implementation for snap to center + return null; + } + + // Snap to intersection + snapToIntersection(x: number, y: number): {x: number, y: number} | null { + if (!this.isEnabled) return null; + // Implementation for snap to intersection + return null; + } + + // Snap to perpendicular + snapToPerpendicular(x: number, y: number): {x: number, y: number} | null { + if (!this.isEnabled) return null; + // Implementation for snap to perpendicular + return null; + } + + // Snap to tangent + snapToTangent(x: number, y: number): {x: number, y: number} | null { + if (!this.isEnabled) return null; + // Implementation for snap to tangent + return null; + } + + // Snap to nearest + snapToNearest(x: number, y: number): {x: number, y: number} | null { + if (!this.isEnabled) return null; + // Implementation for snap to nearest + return null; + } + + // Render visual snap markers on canvas + renderSnapMarkers(context: CanvasRenderingContext2D): void { + // Implementation for rendering snap markers + } +} + +export default SnapEngine;