Files
Aislo/B07_DesignDetail/openwebcad/src/helpers/get-draw-guides.ts
T
eomsangdonandClaude Opus 5.5 db8462c6d4 feat(B07 CAD): 337-2 마-1 오토캐드 마우스 — 누름 더함 · Shift 뺌 · 상자 더함/뺌 · 명령 중 끌기 상자 · 스침 · 그립 누르고-옮기고-누르기 · 그립 숫자 · 보기 전용 문 · 직교 강제 · Shift 임시 직교 · 휠 기본 밂 · 휠 두 번 범위
- 고르기: 누름 = 더함 · Shift = 뺌 · Ctrl = 넣고 빼기 · 상자 = 앞 고름 ∪ 상자 · Shift 상자 = 뺌(H4 · H5) · 명령 안 고르기 단계도 누를 때 첫 점 · 스침 강조(ic/selecting.ts)
- 그립: 쉴 때만 집음(N7) · 누르고 떼면 대기 → 다음 누름에 놓음 · 끌어 놓기(H3) · 거리 숫자(N8) · 확정 · 읽기 전용 도면은 그립 · Delete 막음(H2)
- 직교: F8 = 기준점에서 가로 · 세로 강제 · Shift 누른 동안 뒤집음 · 객체 스냅 점 · 좌표 · 각도 잠금은 안 덮음 · 클릭 사건 snapped 채움(ic/ortho.ts · H8) · 가이드는 F3 와 뗌 · 가이드 잡는 거리 = 화면 픽셀(H9)
- 휠: 기본 밂(앞으로 굴리면 확대 · 오토캐드 · 모든 화면 · ☰ 설정 뒤집기 그대로) · 가운데 단추 두 번 = 범위 줌 · ZOOM · ⛶ 앞 화면 기억(ic/zoom-prompt.ts)
- 시험: mouse-acad 새로 · 휠 방향 시험 손질(input-wheel · input-prefs-cad · input_prefs · app_settings · 164 · 220_1 · 221_1 · 244_8 기대값 뒤집음 · 266 pull 박음)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Se7ytqbohmBQnfYpwYFnYf
2026-10-15 23:41:46 +09:00

94 lines
3.2 KiB
TypeScript

import type { Point } from '@flatten-js/core';
import { compact } from 'es-toolkit';
import { SNAP_ANGLE_DISTANCE } from '../App.consts';
import { type SnapPoint, SnapPointType } from '../App.types';
import type { Entity } from '../entities/Entity';
import type { LineEntity } from '../entities/LineEntity';
import { findClosestEntity } from './find-closest-entity';
import { getAngleGuideLines } from './get-angle-guide-lines';
import { getClosestSnapPointWithinRadius } from './get-closest-snap-point';
import { getIntersectionPoints } from './get-intersection-points';
/**
* Gets the angle guides from the angle point to the mouse if the mouse is close to one of the angle steps and also returns the closest snap point
* @param entities entities that are drawn on the canvas
* @param anglePoints the points that should get angle guides
* @param worldMouseLocation the current mouse location
* @param angleStep the angle in degrees at which the angle guides should be drawn
* @param maxSnapDistance The distance that the mouse can snap to a snap point or angle guide
* @param angleSnapDistance 가이드를 잡는 거리(도면 단위) — 화면 픽셀 / 배율로 넘김(H9)
*/
export function getDrawHelpers(
entities: Entity[],
anglePoints: Point[],
worldMouseLocation: Point,
angleStep: number,
maxSnapDistance: number,
angleSnapDistance: number = SNAP_ANGLE_DISTANCE
): {
angleGuides: LineEntity[];
entitySnapPoint: SnapPoint | null;
angleSnapPoint: SnapPoint | null;
} {
let entitySnapPoint: SnapPoint | null = null;
let angleSnapPoint: SnapPoint | null = null;
const nearestAngleSnapPoints: SnapPoint[] = [];
const angleGuides: LineEntity[] = [];
// draw angle guide — angleStep 0은 직교·극좌표 추적을 모두 끈 상태다
for (const anglePoint of angleStep > 0 ? anglePoints : []) {
const angleGuideLines = getAngleGuideLines(anglePoint, angleStep);
const closestLineInfo = findClosestEntity<LineEntity>(worldMouseLocation, angleGuideLines);
if (closestLineInfo.distance < angleSnapDistance) {
angleGuides.push(closestLineInfo.entity);
nearestAngleSnapPoints.push({
point: closestLineInfo.segment.start,
type: SnapPointType.AngleGuide,
});
}
}
// Calculate snap points
const entitySnapPoints = [
...entities.flatMap((entity) => {
return entity.getSnapPoints();
}),
...getIntersectionPoints(compact(entities)).map((point) => ({
point,
type: SnapPointType.Intersection,
})),
];
const closestSnapPoint = getClosestSnapPointWithinRadius(
entitySnapPoints,
worldMouseLocation,
maxSnapDistance
);
if (closestSnapPoint) {
entitySnapPoint = closestSnapPoint;
}
const angleSnapPoints = [
...nearestAngleSnapPoints,
// TODO only search for intersections between angle guides and other angle guides and between angle guides and entities, but not between entities
...getIntersectionPoints([...compact(entities), ...angleGuides]).map((point) => ({
point,
type: SnapPointType.Intersection,
})),
];
const closestAngleSnapPoint = getClosestSnapPointWithinRadius(
angleSnapPoints,
worldMouseLocation,
maxSnapDistance
);
if (closestAngleSnapPoint) {
angleSnapPoint = closestAngleSnapPoint;
}
return { angleGuides, entitySnapPoint, angleSnapPoint };
}