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:
@@ -0,0 +1,150 @@
|
||||
/**
|
||||
* CAD 키보드 연속 명령(PLAN 331 · 요구 224-7) — 오토캐드 방식.
|
||||
* 각도 고정 `<30` → 길이 · 시퀀스 첫 점 숫자 · 이동 · 복사 · 회전 키보드 값 · 선 중 C · U · 한 번 스냅 · 동적 입력 Tab.
|
||||
* 시험 쪽 flatten-js 는 다른 사본(「Illegal Parameters」) — 점은 앱 코드로만 만들고 숫자로 판정.
|
||||
* 실행: cd B07_DesignDetail/openwebcad && npx vitest run --dir ../../resources/tester/cad keyboard-chain
|
||||
*/
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("react-toastify", () => ({
|
||||
toast: Object.assign(vi.fn(), { error: vi.fn(), info: vi.fn(), warn: vi.fn(), success: vi.fn() }),
|
||||
}));
|
||||
|
||||
import { toast } from "react-toastify";
|
||||
import { InputController } from "../../../B07_DesignDetail/openwebcad/src/inputController/input-controller";
|
||||
import { getAngleLock } from "../../../B07_DesignDetail/openwebcad/src/inputController/input-angle-lock";
|
||||
import {
|
||||
getActiveToolActor,
|
||||
getEntities,
|
||||
setEntities,
|
||||
setSelectedEntityIds,
|
||||
} from "../../../B07_DesignDetail/openwebcad/src/state";
|
||||
import { runCommandInput } from "../../../B07_DesignDetail/openwebcad/src/commands/run-command";
|
||||
import { initApplication } from "../../../B07_DesignDetail/openwebcad/test/helpers/init-application";
|
||||
import { CANVAS_HEIGHT } from "../../../B07_DesignDetail/openwebcad/test/helpers/tests.consts";
|
||||
|
||||
type Xy = { x: number; y: number };
|
||||
type Seg = { start: Xy; end: Xy };
|
||||
|
||||
const key = (controller: InputController, k: string) =>
|
||||
controller.handleKeyStroke({
|
||||
key: k,
|
||||
code: "",
|
||||
keyCode: 0,
|
||||
isComposing: false,
|
||||
shiftKey: false,
|
||||
ctrlKey: false,
|
||||
altKey: false,
|
||||
metaKey: false,
|
||||
repeat: false,
|
||||
target: null,
|
||||
preventDefault: vi.fn(),
|
||||
stopPropagation: vi.fn(),
|
||||
} as unknown as KeyboardEvent);
|
||||
|
||||
/** 글자를 치고 Space(= Enter) */
|
||||
const type = (controller: InputController, text: string) => {
|
||||
for (const ch of text) key(controller, ch);
|
||||
key(controller, " ");
|
||||
};
|
||||
|
||||
/** 세계 좌표 (x, y) 로 커서 이동 — 시험 캔버스는 축척 1 · y 위 + */
|
||||
const move = (controller: InputController, x: number, y: number) =>
|
||||
controller.handleMouseMove({ clientX: x, clientY: CANVAS_HEIGHT - y } as MouseEvent);
|
||||
|
||||
const clickAt = (controller: InputController, x: number, y: number) => {
|
||||
move(controller, x, y);
|
||||
controller.handleMouseUp({
|
||||
button: 0,
|
||||
clientX: x,
|
||||
clientY: CANVAS_HEIGHT - y,
|
||||
target: null,
|
||||
preventDefault: () => {},
|
||||
stopPropagation: () => {},
|
||||
} as unknown as MouseEvent);
|
||||
};
|
||||
|
||||
const lines = () =>
|
||||
getEntities()
|
||||
.filter((entity) => entity.getType() === "Line")
|
||||
.map((entity) => (entity as unknown as { segment: Seg }).segment);
|
||||
|
||||
const expectXy = (point: Xy, x: number, y: number) => {
|
||||
expect(point.x).toBeCloseTo(x, 3);
|
||||
expect(point.y).toBeCloseTo(y, 3);
|
||||
};
|
||||
|
||||
let controller: InputController;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.mocked(toast.error).mockClear();
|
||||
controller = initApplication();
|
||||
setEntities([], true);
|
||||
setSelectedEntityIds([]);
|
||||
});
|
||||
|
||||
describe("331-1 각도 고정 → 길이", () => {
|
||||
it("L · 0,0 · <30 · 100 → (86.603, 50) · <90 · 50 → (86.603, 100)", () => {
|
||||
type(controller, "l");
|
||||
type(controller, "0,0");
|
||||
move(controller, 500, 500); // 커서 방향과 무관하게 고정 각도로
|
||||
type(controller, "<30");
|
||||
expect(getAngleLock()).toBe(30);
|
||||
type(controller, "100");
|
||||
expect(getAngleLock()).toBeNull(); // 한 점만
|
||||
type(controller, "<90");
|
||||
type(controller, "50");
|
||||
const drawn = lines();
|
||||
expect(drawn).toHaveLength(2);
|
||||
expectXy(drawn[0].start, 0, 0);
|
||||
expectXy(drawn[0].end, 86.603, 50);
|
||||
expectXy(drawn[1].end, 86.603, 100);
|
||||
});
|
||||
|
||||
it("고정 없이 숫자 = 마우스 방향", () => {
|
||||
type(controller, "l");
|
||||
type(controller, "0,0");
|
||||
move(controller, 0, 300);
|
||||
type(controller, "100");
|
||||
expectXy(lines()[0].end, 0, 100);
|
||||
});
|
||||
|
||||
it("고정 중 클릭 = 고정 방향 위로 내림 · Esc · 새 명령이면 풂", () => {
|
||||
type(controller, "l");
|
||||
type(controller, "0,0");
|
||||
type(controller, "<0");
|
||||
clickAt(controller, 60, 25); // 가이드에서 먼 자리(스냅 안 붙게)
|
||||
expectXy(lines()[0].end, 60, 0);
|
||||
type(controller, "<45");
|
||||
key(controller, "Escape");
|
||||
expect(getAngleLock()).toBeNull();
|
||||
type(controller, "<45");
|
||||
runCommandInput("CIRCLE");
|
||||
expect(getAngleLock()).toBeNull();
|
||||
});
|
||||
|
||||
it("음수 · .5 숫자 · 음수 각도", () => {
|
||||
type(controller, "l");
|
||||
type(controller, "0,0");
|
||||
type(controller, "<-90");
|
||||
type(controller, ".5");
|
||||
expectXy(lines()[0].end, 0, -0.5);
|
||||
type(controller, "<0");
|
||||
type(controller, "-10");
|
||||
expectXy(lines()[1].end, -10, -0.5);
|
||||
});
|
||||
|
||||
it("PLINE 첫 점에 숫자 · @x,y → 무시 · 도구 살아 있음 · 알림 0", () => {
|
||||
type(controller, "pline");
|
||||
type(controller, "100");
|
||||
type(controller, "@10,0");
|
||||
const snapshot = getActiveToolActor()?.getSnapshot();
|
||||
expect(snapshot?.status).toBe("active");
|
||||
expect(snapshot?.value).toBe("STEP_0");
|
||||
expect(toast.error).not.toHaveBeenCalled();
|
||||
type(controller, "0,0");
|
||||
type(controller, "<0");
|
||||
type(controller, "100");
|
||||
expect(getActiveToolActor()?.getSnapshot()?.context.values).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user