- 복제 함수 cloneKeepingLook 한 곳(move-tool.helpers) — 옮기기 · 크기 · 회전은 id · 묶음까지 그대로 · 복사 · 배열은 새 id - LineEntity · ArcEntity clone 이 색 · 층 · 선 꼴 유지(폴리선 자식 포함) - 복사가 누를 때마다 원본을 한 벌씩 더 쌓던 흠 고침 - ArcEntity mirror 가 축 각도 따름(α → 2θ − α) · 그리기 끝각 = 시작각 ± 쓸어간 각(끝각 0 → 2π 온 원 흠) - DXF 내보내기 시계방향 호는 시작 · 끝 바꿔 같은 작은 호 - 시험: ArcEntity.test.ts 10 · resources/tester/cad/clone-keeps-look.test.ts 7 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UoSr2sqvYtBf1dtQdus88s
62 lines
2.6 KiB
TypeScript
62 lines
2.6 KiB
TypeScript
/**
|
|
* 옮기기 · 크기 · 회전 · 복사 · 배열 복제가 색 · 층 · 선 꼴을 지키는지(84-3).
|
|
* 실행: cd B07_DesignDetail/openwebcad && npx vitest run --config <include 를 이 파일로 바꾼 vitest.tmp.config.ts>
|
|
*/
|
|
import { Point } from "@flatten-js/core";
|
|
import { describe, expect, it } from "vitest";
|
|
import { LineEntity } from "../../../B07_DesignDetail/openwebcad/src/entities/LineEntity";
|
|
import { PointEntity } from "../../../B07_DesignDetail/openwebcad/src/entities/PointEntity";
|
|
import { PolyLineEntity } from "../../../B07_DesignDetail/openwebcad/src/entities/PolyLineEntity";
|
|
import { TextEntity } from "../../../B07_DesignDetail/openwebcad/src/entities/TextEntity";
|
|
import { cloneKeepingLook } from "../../../B07_DesignDetail/openwebcad/src/tools/move-tool.helpers";
|
|
import type { Entity } from "../../../B07_DesignDetail/openwebcad/src/entities/Entity";
|
|
|
|
const styled = <T extends Entity>(entity: T): T => {
|
|
entity.lineColor = "#ff0000";
|
|
entity.lineWidth = 2;
|
|
entity.lineDash = [4, 2];
|
|
entity.opacity = 0.5;
|
|
entity.groupId = "g1";
|
|
return entity;
|
|
};
|
|
const look = (entity: Entity) => [
|
|
entity.layerId,
|
|
entity.lineColor,
|
|
entity.lineWidth,
|
|
entity.lineDash,
|
|
entity.opacity,
|
|
];
|
|
const LOOK = ["구조물", "#ff0000", 2, [4, 2], 0.5];
|
|
|
|
describe("cloneKeepingLook", () => {
|
|
const samples: [string, () => Entity][] = [
|
|
["선", () => styled(new LineEntity("구조물", new Point(0, 0), new Point(1, 0)))],
|
|
["점", () => styled(new PointEntity("구조물", new Point(1, 1)))],
|
|
["글", () => styled(new TextEntity("구조물", "배수관", new Point(0, 0)))],
|
|
];
|
|
for (const [name, make] of samples) {
|
|
it(`${name} — 옮기기(inPlace) 는 id · 묶음 · 색 · 층 그대로`, () => {
|
|
const source = make();
|
|
const copy = cloneKeepingLook(source, true);
|
|
copy.move(5, 5);
|
|
expect(look(copy)).toEqual(LOOK);
|
|
expect([copy.id, copy.groupId]).toEqual([source.id, "g1"]);
|
|
});
|
|
it(`${name} — 복사는 새 id · 색 · 층 그대로`, () => {
|
|
const source = make();
|
|
const copy = cloneKeepingLook(source);
|
|
expect(look(copy)).toEqual(LOOK);
|
|
expect(copy.id).not.toBe(source.id);
|
|
});
|
|
}
|
|
|
|
it("폴리선 — 자식 선까지 색 · 층 그대로(크기 바꿈 뒤)", () => {
|
|
const child = styled(new LineEntity("구조물", new Point(0, 0), new Point(1, 0)));
|
|
const polyline = styled(new PolyLineEntity("구조물", [child]));
|
|
const copy = cloneKeepingLook(polyline, true) as PolyLineEntity;
|
|
copy.scale(new Point(0, 0), 2);
|
|
expect(look(copy)).toEqual(LOOK);
|
|
expect(look(copy.getEntities()[0])).toEqual(LOOK);
|
|
});
|
|
});
|