- 기준점 있는 점 단계에서만 Tab 가로챔(그 밖은 브라우저 초점 이동) · 숫자 넣고 Tab = 그 칸 잠금 + 다음 칸 · 빈 Tab = 칸만 바꿈 - 각도 칸 잠금 = 각도 고정 · 길이 잠근 채 Enter = 그 길이 · `100` Tab `30` Enter → (86.603, 50) - 커서 옆 줄 `▸[길이 100 🔒] [각도 30_]` — 잠금 🔒 · 지금 칸 ▸ · 나머지는 기준점→커서 실측 - 한 점 · Esc · 새 명령이면 각도 고정 · 길이 잠금 모두 풂(releaseOnePoint) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013QyNXY2TUKXCFMwAca2APG
53 lines
2.3 KiB
TypeScript
53 lines
2.3 KiB
TypeScript
/**
|
|
* 각도 고정 `<각도` — 오토캐드 각도 재지정. 다음 한 점만 기준점에서 그 방향(동쪽 0° 반시계 +).
|
|
* 커서 · 클릭은 고정 방향 직선 위로 내리고 · 숫자는 그 방향 길이. 점 하나 쓰면 · Esc · 새 명령이면 풂.
|
|
* 동적 입력(커서 옆 길이 · 각도 두 칸) — 값 넣고 Tab = 그 칸 잠금 + 다음 칸 · 각도 칸 잠금 = 각도 고정.
|
|
*/
|
|
import { Point } from '@flatten-js/core';
|
|
import { polarToPoint } from './input-patterns.ts';
|
|
|
|
let lockedDegrees: number | null = null;
|
|
/** 동적 입력 — 지금 칸 · 잠근 길이 */
|
|
let dynamicField: 'length' | 'angle' = 'length';
|
|
let lockedLength: number | null = null;
|
|
|
|
export const getAngleLock = (): number | null => lockedDegrees;
|
|
|
|
export const setAngleLock = (degrees: number | null) => {
|
|
lockedDegrees = degrees;
|
|
};
|
|
|
|
export const getDynamicField = () => dynamicField;
|
|
export const getLockedLength = () => lockedLength;
|
|
|
|
/** 한 점을 쓴 뒤 · Esc · 새 명령 — 각도 고정 · 동적 입력 잠금을 모두 풂 */
|
|
export function releaseOnePoint() {
|
|
lockedDegrees = null;
|
|
lockedLength = null;
|
|
dynamicField = 'length';
|
|
}
|
|
|
|
/** Tab — 친 숫자를 지금 칸에 잠그고 다음 칸으로(빈 Tab 은 칸만 바꿈) · 숫자 아니면 그대로 둠 */
|
|
export function tabDynamicInput(value: number | null) {
|
|
if (value !== null && dynamicField === 'length') lockedLength = value;
|
|
if (value !== null && dynamicField === 'angle') lockedDegrees = value;
|
|
dynamicField = dynamicField === 'length' ? 'angle' : 'length';
|
|
}
|
|
|
|
/** 커서 옆 안내 줄 */
|
|
export const angleLockHint = (): string | null =>
|
|
lockedDegrees === null ? null : `각도 ${lockedDegrees}° 고정 — 길이 입력`;
|
|
|
|
/** 기준점에서 고정 방향으로 거리만큼 간 점 */
|
|
export function pointAtLock(base: Point, distance: number): Point {
|
|
const offset = polarToPoint(distance, lockedDegrees ?? 0);
|
|
return new Point(base.x + offset.x, base.y + offset.y);
|
|
}
|
|
|
|
/** 점을 기준점 · 고정 방향 직선 위로 내림(커서 · 클릭) */
|
|
export function projectOnLock(base: Point, point: Point): Point {
|
|
const unit = polarToPoint(1, lockedDegrees ?? 0);
|
|
const along = (point.x - base.x) * unit.x + (point.y - base.y) * unit.y;
|
|
return new Point(base.x + unit.x * along, base.y + unit.y * along);
|
|
}
|