snapToAngle = (x1, y1, x2, y2) => {
  const snap = Math.PI / 4 // 45 degrees
  const dx = x2 - x1
  const dy = y2 - y1
  const angle = Math.atan2(dy, dx)
  const dist = Math.hypot(dx, dy)
  const snapAngle = Math.round(angle / snap) * snap

  return {
    x: x1 + dist * Math.cos(snapAngle),
    y: y1 + dist * Math.sin(snapAngle),
    a: snapAngle
  }
}
Returns a coordinate snapped to the nearest 45-degree angle.
@function snapToAngle
@param {number} x1 - First point's x
@param {number} y1 - First point's y
@param {number} x2 - Second point's x
@param {number} y2 - Second point's y
@returns {AngleCoord45} The angle-snapped coordinates and angle