Files
Aislo/B07_DesignDetail/openwebcad/src/tools/draw/fill-tools.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

110 lines
3.4 KiB
TypeScript

/** 해치·그라데이션·경계·영역 — 선택한 객체가 이루는 닫힌 경계를 채우거나 뽑는다 */
import type { Point } from '@flatten-js/core';
import { toast } from 'react-toastify';
import {
autoHatchSpacing,
getHatchAngle,
getHatchSpacing,
getHatchStyle,
} from '../../commands/draw-settings';
import { entitiesToLoop } from '../../helpers/geometry/entity-loop';
import { addEntities, getActiveLineColor, setSelectedEntityIds } from '../../state';
import { Tool } from '../../tools';
import { hatchEntity, polyLineEntity } from '../factories/entity-factory';
import { createSequenceTool, type SequenceInput } from '../factories/sequence-tool';
/** 선택 객체에서 닫힌 경계를 얻는다. 못 얻으면 안내 후 빈 배열 */
function loopFromSelection(input: SequenceInput): Point[] {
const loop = entitiesToLoop(input.entities(0));
if (loop.length < 3) {
toast.warn('닫힌 경계를 만들 객체를 선택하십시오.');
return [];
}
return loop;
}
function boundingSize(points: Point[]): { width: number; height: number } {
const xs = points.map((point) => point.x);
const ys = points.map((point) => point.y);
return { width: Math.max(...xs) - Math.min(...xs), height: Math.max(...ys) - Math.min(...ys) };
}
export const hatchToolStateMachine = createSequenceTool({
tool: Tool.HATCH,
helpers: false,
steps: [
{ kind: 'selection', instructions: '해치를 채울 경계 객체를 선택한 뒤 ENTER를 누르십시오.' },
],
commit: (input) => {
const loop = loopFromSelection(input);
if (!loop.length) return;
const { width, height } = boundingSize(loop);
addEntities(
[
hatchEntity(loop, {
style: getHatchStyle(),
color: getActiveLineColor(),
spacing: getHatchSpacing() ?? autoHatchSpacing(width, height),
angle: getHatchAngle(),
}),
],
true
);
setSelectedEntityIds([]);
},
});
export const gradientToolStateMachine = createSequenceTool({
tool: Tool.GRADIENT,
helpers: false,
steps: [{ kind: 'selection', instructions: '그라데이션을 넣을 경계 객체를 선택한 뒤 ENTER.' }],
commit: (input) => {
const loop = loopFromSelection(input);
if (!loop.length) return;
addEntities(
[
hatchEntity(loop, {
style: 'gradient',
color: getActiveLineColor(),
color2: '#000000',
}),
],
true
);
setSelectedEntityIds([]);
},
});
export const boundaryToolStateMachine = createSequenceTool({
tool: Tool.BOUNDARY,
helpers: false,
steps: [{ kind: 'selection', instructions: '경계를 뽑을 객체를 선택한 뒤 ENTER를 누르십시오.' }],
commit: (input) => {
const loop = loopFromSelection(input);
if (!loop.length) return;
const boundary = polyLineEntity(loop);
if (boundary) {
addEntities([boundary], true);
toast.success('닫힌 폴리선 경계를 만들었습니다.');
}
setSelectedEntityIds([]);
},
});
export const regionToolStateMachine = createSequenceTool({
tool: Tool.REGION,
helpers: false,
steps: [{ kind: 'selection', instructions: '영역으로 만들 객체를 선택한 뒤 ENTER.' }],
commit: (input) => {
const loop = loopFromSelection(input);
if (!loop.length) return;
const region = polyLineEntity(loop);
if (region) {
addEntities([region], true);
// 2D 웹 CAD에는 별도 영역 객체가 없다 — 닫힌 폴리선이 같은 역할을 한다
toast.info('영역은 닫힌 폴리선으로 작성했습니다.');
}
setSelectedEntityIds([]);
},
});