Files
landing-builder/lib/wysiwyg/snap.ts

17 lines
685 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 8px 격자 스냅: 주어진 값 v를 가장 가까운 8의 배수로 반올림
export function snap8(v: number): number {
return Math.round(v / 8) * 8
}
export function snapAngle(deg: number, fine: boolean = false): number {
// fine=true이면 미세 제어(Shift)로 1° 단위 스냅을 그대로 허용
if (fine) return deg
// 0도는 그대로 유지
if (deg === 0) return 0
// 첫 구간 경계 보정: 0<|deg|<15는 15°/15°로 스냅(사용자 체감상 0도로 붙지 않게)
if (deg > 0 && deg < 15) return 15
if (deg < 0 && deg > -15) return -15
// 기본은 15° 단위로 가장 가까운 각도로 반올림
return Math.round(deg / 15) * 15
}