파일마다 포맷 폭이 달라(≈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>
160 lines
5.7 KiB
TypeScript
160 lines
5.7 KiB
TypeScript
/** 그리기 명령 — 폴리선·호·다각형·타원·스플라인·점 (조사표 1절) */
|
|
import { CircleEntity } from '../../entities/CircleEntity';
|
|
import type { Entity } from '../../entities/Entity';
|
|
import {
|
|
arcThroughThreePoints,
|
|
ellipsePoints,
|
|
regularPolygonPoints,
|
|
splinePoints,
|
|
} from '../../helpers/geometry/shape-points';
|
|
import { addEntities, getActiveLayerId } from '../../state';
|
|
import { Tool } from '../../tools';
|
|
import {
|
|
arcEntity,
|
|
lineEntity,
|
|
pointEntity,
|
|
polyLineEntity,
|
|
styled,
|
|
} from '../factories/entity-factory';
|
|
import { createSequenceTool } from '../factories/sequence-tool';
|
|
|
|
export const plineToolStateMachine = createSequenceTool({
|
|
tool: Tool.PLINE,
|
|
steps: [
|
|
{ kind: 'point', instructions: '폴리선의 시작점을 지정하십시오.' },
|
|
{ kind: 'point', instructions: '다음 점을 지정하십시오. ENTER로 종료합니다.' },
|
|
],
|
|
repeatLastStep: true,
|
|
preview: (input) => {
|
|
const preview = polyLineEntity([...input.points(), input.cursor]);
|
|
return preview ? [preview] : [];
|
|
},
|
|
commit: (input) => {
|
|
const polyline = polyLineEntity(input.points());
|
|
if (polyline) addEntities([polyline], true);
|
|
},
|
|
});
|
|
|
|
export const arcToolStateMachine = createSequenceTool({
|
|
tool: Tool.ARC,
|
|
steps: [
|
|
{ kind: 'point', instructions: '호의 시작점을 지정하십시오.' },
|
|
{ kind: 'point', instructions: '호가 지나갈 두 번째 점을 지정하십시오.' },
|
|
{ kind: 'point', instructions: '호의 끝점을 지정하십시오.' },
|
|
],
|
|
preview: (input) => {
|
|
const points = input.points();
|
|
if (points.length === 1) return [lineEntity(points[0], input.cursor)];
|
|
if (points.length === 2) {
|
|
const definition = arcThroughThreePoints(points[0], points[1], input.cursor);
|
|
return definition ? [arcEntity(definition)] : [lineEntity(points[0], input.cursor)];
|
|
}
|
|
return [];
|
|
},
|
|
commit: (input) => {
|
|
const [start, through, end] = input.points();
|
|
const definition = arcThroughThreePoints(start, through, end);
|
|
// 세 점이 일직선이면 호가 성립하지 않으므로 선으로 대체한다
|
|
addEntities([definition ? arcEntity(definition) : lineEntity(start, end)], true);
|
|
},
|
|
});
|
|
|
|
export const polygonToolStateMachine = createSequenceTool({
|
|
tool: Tool.POLYGON,
|
|
steps: [
|
|
{ kind: 'number', instructions: '면의 수를 입력하십시오 <6>.', defaultValue: 6 },
|
|
{ kind: 'point', instructions: '다각형의 중심을 지정하십시오.' },
|
|
{ kind: 'point', instructions: '꼭짓점을 지정하십시오 (중심에서의 반지름).' },
|
|
],
|
|
preview: (input) => {
|
|
const points = input.points();
|
|
if (points.length !== 1) return [];
|
|
const polygon = polyLineEntity(regularPolygonPoints(points[0], input.cursor, input.number(0)));
|
|
return polygon ? [polygon] : [];
|
|
},
|
|
commit: (input) => {
|
|
const [center, vertex] = input.points();
|
|
const polygon = polyLineEntity(regularPolygonPoints(center, vertex, input.number(0)));
|
|
if (polygon) addEntities([polygon], true);
|
|
},
|
|
});
|
|
|
|
export const ellipseToolStateMachine = createSequenceTool({
|
|
tool: Tool.ELLIPSE,
|
|
steps: [
|
|
{ kind: 'point', instructions: '타원의 중심을 지정하십시오.' },
|
|
{ kind: 'point', instructions: '장축의 끝점을 지정하십시오.' },
|
|
{ kind: 'point', instructions: '단축 거리를 지정하십시오.' },
|
|
],
|
|
preview: (input) => {
|
|
const points = input.points();
|
|
if (points.length === 1) return [lineEntity(points[0], input.cursor)];
|
|
if (points.length === 2) {
|
|
const minor = points[0].distanceTo(input.cursor)[0];
|
|
const ellipse = polyLineEntity(ellipsePoints(points[0], points[1], minor));
|
|
return ellipse ? [ellipse] : [];
|
|
}
|
|
return [];
|
|
},
|
|
commit: (input) => {
|
|
const [center, majorPoint, minorPoint] = input.points();
|
|
const minorRadius = center.distanceTo(minorPoint)[0];
|
|
const ellipse = polyLineEntity(ellipsePoints(center, majorPoint, minorRadius));
|
|
if (ellipse) addEntities([ellipse], true);
|
|
},
|
|
});
|
|
|
|
export const splineToolStateMachine = createSequenceTool({
|
|
tool: Tool.SPLINE,
|
|
steps: [
|
|
{ kind: 'point', instructions: '스플라인의 첫 점을 지정하십시오.' },
|
|
{ kind: 'point', instructions: '다음 점을 지정하십시오. ENTER로 종료합니다.' },
|
|
],
|
|
repeatLastStep: true,
|
|
preview: (input) => {
|
|
const preview = polyLineEntity(splinePoints([...input.points(), input.cursor]));
|
|
return preview ? [preview] : [];
|
|
},
|
|
commit: (input) => {
|
|
const spline = polyLineEntity(splinePoints(input.points()));
|
|
if (spline) addEntities([spline], true);
|
|
},
|
|
});
|
|
|
|
export const pointToolStateMachine = createSequenceTool({
|
|
tool: Tool.POINT,
|
|
steps: [{ kind: 'point', instructions: '점의 위치를 지정하십시오.' }],
|
|
preview: (input) => [pointEntity(input.cursor)],
|
|
commit: (input) => {
|
|
addEntities([pointEntity(input.point(0))], true);
|
|
},
|
|
});
|
|
|
|
/** 도넛 — 안쪽·바깥쪽 지름을 받아 동심원 두 개를 놓는다 */
|
|
export const donutToolStateMachine = createSequenceTool({
|
|
tool: Tool.DONUT,
|
|
steps: [
|
|
{ kind: 'number', instructions: '도넛의 내부 지름을 입력하십시오 <1>.', defaultValue: 1 },
|
|
{ kind: 'number', instructions: '도넛의 외부 지름을 입력하십시오 <2>.', defaultValue: 2 },
|
|
{ kind: 'point', instructions: '도넛의 중심을 지정하십시오.' },
|
|
],
|
|
preview: (input) => donutEntities(input.number(0), input.number(1), input.cursor),
|
|
commit: (input) => {
|
|
addEntities(donutEntities(input.number(0), input.number(1), input.point(2)), true);
|
|
},
|
|
});
|
|
|
|
function donutEntities(
|
|
innerDiameter: number,
|
|
outerDiameter: number,
|
|
center: Parameters<typeof pointEntity>[0]
|
|
): Entity[] {
|
|
const circles: Entity[] = [];
|
|
for (const diameter of [innerDiameter, outerDiameter]) {
|
|
if (diameter > 0) {
|
|
circles.push(styled(new CircleEntity(getActiveLayerId(), center, diameter / 2)));
|
|
}
|
|
}
|
|
return circles;
|
|
}
|