Files
Aislo/B07_DesignDetail/openwebcad/src/tools/eraser-tool.helpers.ts
T
eomsangdonandClaude Fable 5 6e195afb69 feat(B07,B08): 워크플로 순서 교환 — 상세설계를 수량산출 앞으로
횡단설계(B06) 다음을 상세설계 → 수량산출 → 설계도서 순으로 재배열하고,
폴더 번호가 흐름과 일치하도록 이름을 맞바꾼다.

- B08_DesignDetail → B07_DesignDetail, B07_Quantity → B08_Quantity
  (파일 접두어·식별자·라우트·locale 키 전량 스왑)
- STAGE_KEYS 4=DESIGN_DETAIL, 5=QUANTITY 스왑 + 라우터 stage 리터럴 교체
- CAD 마운트 /b08-cad → /b07-cad (main.py·vite proxy·iframe URL),
  openwebcad Toolbar 라벨 B07로 수정 후 재빌드
- 유지: openwebcad postMessage 프로토콜 aislo:b08:*·패키지명(내부 식별자)
- 기존 프로젝트 storage 폴더 rename + project_manifest 갱신,
  DB project_workflow_stages stage_no 4↔5 행 스왑 완료

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-29 16:16:46 +09:00

127 lines
3.8 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);
}