Files
Aislo/B07_DesignDetail/openwebcad/src/helpers/get-point-from-event.ts
T
eomsangdonandClaude Opus 5.5 8e96880880 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
2026-10-15 12:33:28 +09:00

56 lines
2.3 KiB
TypeScript

import { type Point, Vector } from '@flatten-js/core';
import { getAngleLock, pointAtLock, projectOnLock } from '../inputController/input-angle-lock.ts';
import {
type AbsolutePointInputEvent,
ActorEvent,
type DrawEvent,
type MouseClickEvent,
type NumberInputEvent,
type PointInputEvent,
type RelativePointInputEvent,
} from '../tools/tool.types.ts';
/**
* Various tools need to convert user input into a point
* This function handles mouse click event, number events and in the future absoluteCoordinates and relativeCoordinate events
* 각도 고정(`<30`) 중이면 커서 · 클릭 · 숫자를 기준점에서 고정 방향으로.
* @param startPoint
* @param event
*/
export function getPointFromEvent(startPoint: Point | null, event: PointInputEvent): Point {
const locked = startPoint !== null && getAngleLock() !== null;
if (event.type === ActorEvent.DRAW) {
const mouse = (event as DrawEvent).drawController.getWorldMouseLocation();
return locked ? projectOnLock(startPoint, mouse) : mouse;
}
if (event.type === ActorEvent.MOUSE_CLICK) {
const click = (event as MouseClickEvent).worldMouseLocation;
return locked ? projectOnLock(startPoint, click) : click;
}
if (event.type === ActorEvent.NUMBER_INPUT) {
if (!startPoint) {
throw new Error('Cannot get relative point by distance if no start point is provided');
}
const distance = (event as NumberInputEvent).value;
if (locked) return pointAtLock(startPoint, distance);
// Direction indicated by the startPoint and the mouse location
const direction = new Vector(
event.worldMouseLocation.x - startPoint.x,
event.worldMouseLocation.y - startPoint.y
);
const unitDirection = direction.normalize();
return startPoint.translate(unitDirection.multiply(distance));
}
if (event.type === ActorEvent.ABSOLUTE_POINT_INPUT) {
return (event as AbsolutePointInputEvent).value;
}
if (event.type === ActorEvent.RELATIVE_POINT_INPUT) {
if (!startPoint) {
throw new Error('Cannot get relative point by coordinates if no start point is provided');
}
const relativeCoordinates = (event as RelativePointInputEvent).value;
return startPoint.clone().translate(relativeCoordinates.x, relativeCoordinates.y);
}
throw new Error('Received unexpected event type in DRAW_FINAL_LINE of LineEntity');
}