Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 21, 2025

Overview

Implements grid snapping functionality for the SVG Path Editor. Points now automatically snap to the grid when placing or moving them, making it easier to create precise, aligned paths. The feature can be toggled on/off via a new toolbar button and is enabled by default.

Changes

Grid Snapping Logic

  • Added snapPoint() method that rounds coordinates to the nearest grid intersection
  • Snaps to 10px intervals (half of the 20px grid size, aligning with visible grid dots)
  • Applied to both:
    • Creating new anchor points (onCreatePathDown)
    • Moving existing points and handles (onPointerMove)

UI Toggle Button

  • New toolbar button with grid icon (4-square pattern) next to the Pen Mode button
  • Visual feedback: Active state shows black background, inactive shows white with border
  • Tooltip: "Snap to Grid"
  • Default state: ON (as requested in the issue)

Technical Details

The snapping algorithm uses Math.round(coordinate / 10) * 10 to snap coordinates:

  • Grid size: 20px (matches existing visual grid pattern)
  • Snap interval: 10px (centers of grid cells where dots appear)
  • Performance: O(1) operation with no performance impact

Benefits

  • ✅ Precise alignment with visible grid
  • ✅ Easier to create symmetric and aligned shapes
  • ✅ Better control over point placement
  • ✅ Can be toggled off for free-form drawing when needed
  • ✅ Minimal code changes (26 lines) - surgical implementation
  • ✅ No breaking changes to existing functionality

Screenshots

New toggle button in toolbar (default active state):
Snap to Grid button active

Toggle button inactive (snap OFF):
Snap to Grid button inactive

Point snapped to grid alignment:
Point aligned to grid

Testing

  • ✅ TypeScript compilation successful
  • ✅ Production build successful
  • ✅ Manual testing: Snap ON correctly aligns points to grid
  • ✅ Manual testing: Snap OFF allows free placement
  • ✅ Manual testing: Toggle button works correctly with visual feedback
  • ✅ Manual testing: Default state verified as ON

Fixes the requirement: グリッド・サブグリッドにスナップできるようにする。デフォルトON

Original prompt

グリッド・サブグリッドにスナップできるようにする。デフォルトON


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits October 21, 2025 04:30
Co-authored-by: hashrock <3132889+hashrock@users.noreply.github.com>
Co-authored-by: hashrock <3132889+hashrock@users.noreply.github.com>
Copilot AI changed the title [WIP] Add grid and subgrid snapping functionality Add grid snapping feature with toggle button (default ON) Oct 21, 2025
Copilot AI requested a review from hashrock October 21, 2025 04:39
@hashrock hashrock marked this pull request as ready for review October 21, 2025 04:56
@hashrock hashrock merged commit ab36155 into main Oct 25, 2025
0 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants