Files
Aislo/B07_DesignDetail/openwebcad/src/helpers/get-draw-guides.ts
T
eomsangdonandClaude Opus 5 4cb9b15939 style: 저장소 전체 포맷터 일괄 적용 (prettier·biome·ruff)
파일마다 포맷 폭이 달라(≈80 대 100) 한 줄만 고쳐도 포맷터가 무관한 줄을 대량
재포맷했음. 사용자 지시로 전체를 한 번에 맞춤. 코드 동작 변경 없음 — 포맷만.

- 프론트엔드 `.ts/.css/.html` → 저장소 prettier (`.prettierrc`, printWidth 100)
- `B07_DesignDetail/openwebcad/**` → 자체 biome (tab 들여쓰기·single quote·lineWidth 100).
  `biome format` 만 사용 — `biome lint --write` 는 포맷 아닌 코드 수정까지 하므로 제외
- 파이썬 → `ruff format` (엔진 코드는 이미 정합, resources·scratch 스크립트 24개만 변경)

두 포맷터가 서로 되돌리지 않도록 `.prettierignore` 신규 — openwebcad 와 빌드·산출물
폴더를 prettier 대상에서 뺌. `.prettierrc` 에 `endOfLine: "auto"` 추가 — 기본값 `lf` 가
`core.autocrlf=true` 로 받은 CRLF 파일을 매번 전부 다시 써서 `--list-different` 가
실제 포맷 차이를 가리고 있었음.

검증: `tsc --noEmit` 통과(루트·openwebcad 둘 다), pytest 349 passed / 17 skipped /
0 failed, CAD vitest 87건 중 81 passed / 6 failed(laptop-sub 기준선과 동일, 회귀 없음).
포맷터 재실행 시 prettier·biome 모두 변경 0건.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 07:08:24 +09:00

92 lines
3.0 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
*/
export function getDrawHelpers(
entities: Entity[],
anglePoints: Point[],
worldMouseLocation: Point,
angleStep: number,
maxSnapDistance: number
): {
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 < SNAP_ANGLE_DISTANCE) {
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 };
}