Files
Aislo/B07_DesignDetail/openwebcad/src/tools/scale-tool.test.ts
T
eomsangdonandClaude Opus 5.5 d35bdfa69d feat(CAD): 337-5 라 옮기기 무리 1 단계 — MOVE · ROTATE · SCALE 오토캐드 물음 차례
- MOVE: 기준점 [변위(D)] <변위> · 두 번째 점 <첫 번째 점을 변위로 사용> · 변위 기억(MOVE.DISP) · 한 번 뒤 끝 · Esc 제자리 끝
- ROTATE · SCALE: 공용 틀(pivot-tool) — 누름 한 번 = 값 · 복사(C) · 참조(R) → 새 값 [점(P)] · 각 · 비율 기억 · 0 이하 축척 거절
- 공용 고르기 상태(transform.helpers) — PICKFIRST · 빈 고르기 Enter = 끝 · OPTION.* 넘김 · 원본은 확정까지 도면에 그대로(N1 · N2)
- 시험 transform-acad(15) · scale-tool 단위 시험 새 상태 이름

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TteK8mfYZetk5P3bEZkyVZ
2026-10-16 00:17:16 +09:00

90 lines
3.0 KiB
TypeScript

import { Point } from '@flatten-js/core';
import { beforeEach, describe, expect, it } from 'vitest';
import { createActor } from 'xstate';
import { LineEntity } from '../entities/LineEntity.ts';
import {
getEntities,
resetUndoBaseline,
setEntities,
setSelectedEntityIds,
undo,
} from '../state.ts';
import { ScaleState, scaleToolStateMachine } from './scale-tool.ts';
import { ActorEvent } from './tool.types.ts';
const ends = (index: number) => {
const line = getEntities()[index] as LineEntity;
const a = line.getStartPoint();
const b = line.getEndPoint();
return [a.x, a.y, b.x, b.y];
};
/** 기준점 (2,0) 클릭까지 — 선 A(0,0)-(10,0) 고름 · 선 B(0,5)-(4,5) 는 그대로 둘 것 */
function startAtBasePoint() {
const a = new LineEntity('layer1', new Point(0, 0), new Point(10, 0));
const b = new LineEntity('layer1', new Point(0, 5), new Point(4, 5));
setEntities([a, b]);
resetUndoBaseline();
setSelectedEntityIds([a.id]);
const actor = createActor(scaleToolStateMachine).start();
expect(actor.getSnapshot().value).toBe(ScaleState.WAITING_FOR_BASE_POINT);
actor.send({
type: ActorEvent.MOUSE_CLICK,
worldMouseLocation: new Point(2, 0),
screenMouseLocation: new Point(0, 0),
holdingCtrl: false,
holdingShift: false,
});
expect(actor.getSnapshot().value).toBe(ScaleState.WAITING_FOR_VALUE);
return { actor, a, b };
}
const typeNumber = (actor: ReturnType<typeof startAtBasePoint>['actor'], value: number) =>
actor.send({ type: ActorEvent.NUMBER_INPUT, value, worldMouseLocation: new Point(99, 99) });
describe('축척 — 기준점 + 숫자 배율 (226-1)', () => {
beforeEach(() => setSelectedEntityIds([]));
it('배율 2 = 기준점 고정 두 배 · 다른 객체 · 순서 그대로', () => {
const { actor, a, b } = startAtBasePoint();
typeNumber(actor, 2);
// (0,0)→(-2,0) · (10,0)→(18,0) — 기준점 (2,0) 은 그대로
expect(ends(0)).toEqual([-2, 0, 18, 0]);
expect(getEntities()[0].id).toBe(a.id);
expect(getEntities()[1]).toBe(b);
expect(ends(1)).toEqual([0, 5, 4, 5]);
// 한 번 뒤 끝(오토캐드) — 쉬는 상태로
expect(actor.getSnapshot().status).toBe('done');
});
it('배율 0.5 = 절반', () => {
const { actor } = startAtBasePoint();
typeNumber(actor, 0.5);
expect(ends(0)).toEqual([1, 0, 6, 0]);
});
it('되돌리기 한 번에 원래 자리', () => {
const { actor } = startAtBasePoint();
typeNumber(actor, 2);
undo();
expect(ends(0)).toEqual([0, 0, 10, 0]);
expect(getEntities()).toHaveLength(2);
});
it('Esc = 취소 — 객체 그대로', () => {
const { actor, a, b } = startAtBasePoint();
actor.send({ type: ActorEvent.ESC });
expect(getEntities()).toEqual([a, b]);
expect(ends(0)).toEqual([0, 0, 10, 0]);
typeNumber(actor, 2);
expect(ends(0)).toEqual([0, 0, 10, 0]);
});
it('배율 0 은 받지 않음', () => {
const { actor } = startAtBasePoint();
typeNumber(actor, 0);
expect(ends(0)).toEqual([0, 0, 10, 0]);
expect(actor.getSnapshot().value).toBe(ScaleState.WAITING_FOR_VALUE);
});
});