diff --git a/B07_DesignDetail/openwebcad/src/entities/ImageEntity.test.ts b/B07_DesignDetail/openwebcad/src/entities/ImageEntity.test.ts new file mode 100644 index 00000000..63310b39 --- /dev/null +++ b/B07_DesignDetail/openwebcad/src/entities/ImageEntity.test.ts @@ -0,0 +1,40 @@ +import { Point } from '@flatten-js/core'; +import { describe, expect, it } from 'vitest'; +import type { DrawController } from '../drawControllers/DrawController'; +import { ImageEntity } from './ImageEntity'; + +/** drawLine·drawImage 호출만 세는 최소 컨트롤러. */ +function countingController() { + const calls = { lines: 0, images: 0 }; + const controller = { + setLineStyles: () => {}, + drawLine: () => { + calls.lines += 1; + }, + drawImage: () => { + calls.images += 1; + }, + } as unknown as DrawController; + return { controller, calls }; +} + +function entity(): ImageEntity { + const image = { currentSrc: 'data:image/png;base64,AAAA' } as HTMLImageElement; + return new ImageEntity('b08-frame', image, new Point(0, 0), new Point(10, 5)); +} + +describe('ImageEntity.draw', () => { + it('집지 않은 그림은 테두리를 그리지 않는다', () => { + const { controller, calls } = countingController(); + entity().draw(controller, false, false); + expect(calls.lines).toBe(0); + expect(calls.images).toBe(1); + }); + + it('집은 그림만 테두리를 보인다', () => { + const { controller, calls } = countingController(); + entity().draw(controller, false, true); + expect(calls.lines).toBe(4); + expect(calls.images).toBe(1); + }); +}); diff --git a/B07_DesignDetail/openwebcad/src/entities/ImageEntity.ts b/B07_DesignDetail/openwebcad/src/entities/ImageEntity.ts index 058439f4..3476aa8b 100644 --- a/B07_DesignDetail/openwebcad/src/entities/ImageEntity.ts +++ b/B07_DesignDetail/openwebcad/src/entities/ImageEntity.ts @@ -53,15 +53,21 @@ export class ImageEntity implements Entity { parentHighlighted?: boolean, parentSelected?: boolean ): void { + const highlighted = parentHighlighted ?? isEntityHighlighted(this); + const selected = parentSelected ?? isEntitySelected(this); drawController.setLineStyles( - parentHighlighted ?? isEntityHighlighted(this), - parentSelected ?? isEntitySelected(this), + highlighted, + selected, this.lineColor, this.lineWidth, this.lineDash ); - for (const edge of polygonToSegments(this.polygon)) { - drawController.drawLine(edge.start, edge.end); + // 테두리는 **집었을 때만** 그린다. 늘 그리면 도각의 로고·서명 자리에 흰 사각형이 + // 남고, 출력·내보내기가 같은 draw()를 타므로 산출물에도 실린다(2026-09-02). + if (highlighted || selected) { + for (const edge of polygonToSegments(this.polygon)) { + drawController.drawLine(edge.start, edge.end); + } } const width = this.polygon.box.width;