feat(CAD): 331-1 각도 고정 <각도 → 길이 · 시퀀스 첫 점 숫자 무시

- 새 input-angle-lock — 다음 한 점만 고정 방향(동쪽 0° 반시계) · 커서 · 클릭은 고정 직선 위로 · 숫자는 그 방향 길이 · 한 점 · Esc · 새 명령이면 풂 · 커서 옆 안내 「각도 30° 고정 — 길이 입력」
- input-patterns — 숫자 음수 · .5 허용 · 각도 고정 꼴 · 점 글 해석 한 곳(parsePointText)
- Enter 해석 차례 — 자유 글 단계만 원문 먼저 → 각도 고정 → 점 · 거리 → 단계 선택지 → 명령 이름
- 선 · 시퀀스 미리보기도 고정 방향 · 시퀀스 첫 점의 거리 · 상대 좌표는 무시(도구 멈춤 · 「Error in tool actor」 없앰)
- 시험 resources/tester/cad/keyboard-chain.test.ts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013QyNXY2TUKXCFMwAca2APG
This commit is contained in:
2026-10-15 12:33:28 +09:00
co-authored by Claude Opus 5.5
parent b5b6264016
commit 8e96880880
8 changed files with 299 additions and 119 deletions
@@ -1,17 +1,65 @@
/** 명령 입력 해석 — 숫자 · 좌표 · 극좌표 꼴 */
/** 명령 입력 해석 — 숫자 · 좌표 · 극좌표 · 각도 고정 꼴 */
import { Point } from '@flatten-js/core';
import {
type AbsolutePointInputEvent,
ActorEvent,
type NumberInputEvent,
type RelativePointInputEvent,
} from '../tools/tool.types.ts';
export const NUMBER_REGEXP = /^[0-9]+([.][0-9]+)?$/;
/** 부호 있는 실수 한 개 (좌표는 음수가 될 수 있다) */
const SIGNED = '(-?[0-9]+(?:[.][0-9]+)?)';
/** 부호 있는 실수 한 개 — `-5` · `.5` · `1.5` */
const SIGNED = '(-?(?:[0-9]+(?:[.][0-9]+)?|[.][0-9]+))';
export const NUMBER_REGEXP = new RegExp(`^${SIGNED}$`);
export const ABSOLUTE_POINT_REGEXP = new RegExp(`^${SIGNED}[ ]*,[ ]*${SIGNED}$`);
export const RELATIVE_POINT_REGEXP = new RegExp(`^@${SIGNED}[ ]*,[ ]*${SIGNED}$`);
/** 극좌표 — 거리<각도(도). `@`가 붙으면 직전 점 기준 */
export const ABSOLUTE_POLAR_REGEXP = new RegExp(`^${SIGNED}[ ]*<[ ]*${SIGNED}$`);
export const RELATIVE_POLAR_REGEXP = new RegExp(`^@${SIGNED}[ ]*<[ ]*${SIGNED}$`);
/** 각도 고정 — `<30` (다음 한 점만 그 방향) */
export const ANGLE_LOCK_REGEXP = new RegExp(`^<[ ]*${SIGNED}$`);
/** 거리·각도(도)를 x·y 변위로 바꾼다 */
/** 거리·각도(도)를 x·y 변위로 바꾼다 — 각도 = 동쪽 0° 반시계 + */
export function polarToPoint(distance: number, degrees: number): Point {
const radians = (degrees * Math.PI) / 180;
return new Point(distance * Math.cos(radians), distance * Math.sin(radians));
}
export type PointTextEvent = NumberInputEvent | AbsolutePointInputEvent | RelativePointInputEvent;
/** 친 글 → 점 · 거리 사건(숫자 · `x,y` · `@x,y` · `@d<a` · `d<a`) · 아니면 null · 커서는 숫자일 때만 읽음 */
export function parsePointText(text: string, cursor: () => Point): PointTextEvent | null {
const num = (value: string) => Number.parseFloat(value);
let match = NUMBER_REGEXP.exec(text);
if (match) {
return { type: ActorEvent.NUMBER_INPUT, value: num(match[1]), worldMouseLocation: cursor() };
}
match = ABSOLUTE_POINT_REGEXP.exec(text);
if (match) {
return {
type: ActorEvent.ABSOLUTE_POINT_INPUT,
value: new Point(num(match[1]), num(match[2])),
};
}
match = RELATIVE_POINT_REGEXP.exec(text);
if (match) {
return {
type: ActorEvent.RELATIVE_POINT_INPUT,
value: new Point(num(match[1]), num(match[2])),
};
}
match = RELATIVE_POLAR_REGEXP.exec(text);
if (match) {
return {
type: ActorEvent.RELATIVE_POINT_INPUT,
value: polarToPoint(num(match[1]), num(match[2])),
};
}
match = ABSOLUTE_POLAR_REGEXP.exec(text);
if (match) {
return {
type: ActorEvent.ABSOLUTE_POINT_INPUT,
value: polarToPoint(num(match[1]), num(match[2])),
};
}
return null;
}