파일마다 포맷 폭이 달라(≈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>
127 lines
3.9 KiB
TypeScript
127 lines
3.9 KiB
TypeScript
import { type Circle, Point, type Segment } from '@flatten-js/core';
|
|
import { compact } from 'es-toolkit';
|
|
import { ArcEntity } from '../entities/ArcEntity';
|
|
import type { CircleEntity } from '../entities/CircleEntity';
|
|
import type { Entity } from '../entities/Entity';
|
|
import type { LineEntity } from '../entities/LineEntity';
|
|
import { findNeighboringPointsOnArc } from '../helpers/find-neighboring-points-on-arc';
|
|
import { findNeighboringPointsOnCircle } from '../helpers/find-neighboring-points-on-circle';
|
|
import { findNeighboringPointsOnLine } from '../helpers/find-neighboring-points-on-line';
|
|
import { getAngleWithXAxis } from '../helpers/get-angle-with-x-axis.ts';
|
|
import { isPointEqual } from '../helpers/is-point-equal';
|
|
import { addEntities, deleteEntities, getActiveLayerId } from '../state';
|
|
|
|
export function getAllIntersectionPoints(entity: Entity, entities: Entity[]): Point[] {
|
|
// TODO see if we need to make this list unique
|
|
return compact(
|
|
entities
|
|
.filter((otherEntity) => otherEntity.id !== entity.id)
|
|
.flatMap((otherEntity) => {
|
|
if (entity.id === otherEntity.id) {
|
|
return null;
|
|
}
|
|
return entity.getIntersections(otherEntity);
|
|
})
|
|
);
|
|
}
|
|
|
|
export function eraseLineSegment(
|
|
line: LineEntity,
|
|
clickedPointOnShape: Point,
|
|
intersections: Point[]
|
|
): void {
|
|
const segment = line.getShape() as Segment;
|
|
const [firstCutPoint, secondCutPoint] = findNeighboringPointsOnLine(
|
|
clickedPointOnShape,
|
|
segment.start,
|
|
segment.end,
|
|
intersections
|
|
);
|
|
|
|
const cutLines: Entity[] = line.cutAtPoints([firstCutPoint, secondCutPoint]);
|
|
// Remove the segment that has the clickedPointOnShape point on it
|
|
const remainingLines = cutLines.filter((line) => !line.containsPointOnShape(clickedPointOnShape));
|
|
deleteEntities([line], false);
|
|
|
|
// Helper functions should never trigger an undo state, since they can be called multiple times during one user operation
|
|
addEntities(remainingLines, false);
|
|
}
|
|
|
|
export function eraseCircleSegment(
|
|
circle: CircleEntity,
|
|
clickedPointOnShape: Point,
|
|
intersections: Point[]
|
|
): void {
|
|
if (intersections.length === 0) {
|
|
deleteEntities([circle], false);
|
|
return;
|
|
}
|
|
|
|
const [firstCutPoint, secondCutPoint] = findNeighboringPointsOnCircle(
|
|
clickedPointOnShape,
|
|
circle,
|
|
intersections
|
|
);
|
|
|
|
const circleShape = circle.getShape() as Circle;
|
|
const center = circleShape.center;
|
|
|
|
const angles = [firstCutPoint, secondCutPoint, clickedPointOnShape].map((p) =>
|
|
getAngleWithXAxis(new Point(center.x, center.y), new Point(p.x, p.y))
|
|
);
|
|
|
|
const [startAngle, endAngle] = isAngleBetween(angles[2], angles[0], angles[1])
|
|
? [angles[1], angles[0]]
|
|
: [angles[0], angles[1]];
|
|
|
|
const newArc = new ArcEntity(
|
|
getActiveLayerId(),
|
|
center,
|
|
circleShape.r,
|
|
startAngle,
|
|
endAngle,
|
|
true
|
|
);
|
|
Object.assign(newArc, {
|
|
lineColor: circle.lineColor,
|
|
lineWidth: circle.lineWidth,
|
|
});
|
|
|
|
deleteEntities([circle], false);
|
|
|
|
// Helper functions should never trigger an undo state, since they can be called multiple times during one user operation
|
|
addEntities([newArc], false);
|
|
}
|
|
|
|
function isAngleBetween(angle: number, start: number, end: number): boolean {
|
|
const twoPi = 2 * Math.PI;
|
|
return (angle - start + twoPi) % twoPi <= (end - start + twoPi) % twoPi;
|
|
}
|
|
|
|
export function eraseArcSegment(
|
|
arc: ArcEntity,
|
|
clickedPointOnShape: Point,
|
|
intersections: Point[]
|
|
): void {
|
|
const [first, second] = findNeighboringPointsOnArc(clickedPointOnShape, arc, intersections);
|
|
|
|
if (isPointEqual(first, second)) {
|
|
deleteEntities([arc], true);
|
|
return;
|
|
}
|
|
|
|
const newArcs = arc
|
|
.cutAtPoints([first, second])
|
|
.filter((cutArc) => !cutArc.containsPointOnShape(clickedPointOnShape));
|
|
for (const newArc of newArcs) {
|
|
Object.assign(newArc, {
|
|
lineColor: arc.lineColor,
|
|
lineWidth: arc.lineWidth,
|
|
});
|
|
addEntities([newArc], false);
|
|
}
|
|
|
|
// Helper functions should never trigger an undo state, since they can be called multiple times during one user operation
|
|
deleteEntities([arc], false);
|
|
}
|