diff --git a/src/components/fabric/QPolygon.js b/src/components/fabric/QPolygon.js index bfc133e4..512149f3 100644 --- a/src/components/fabric/QPolygon.js +++ b/src/components/fabric/QPolygon.js @@ -199,6 +199,32 @@ export default class QPolygon extends fabric.Group { this.canvas.renderAll() } + /** + * this.lines의 direction이 top 인 line의 모든 합이 bottom 인 line의 모든 합과 같은지 확인 + * this.lines의 direction이 left 인 line의 모든 합이 right 인 line의 모든 합과 같은지 확인 + * return {boolean} + */ + isValid() { + const leftLinesLengthSum = this.lines + .filter((line) => line.direction === 'left') + .reduce((sum, line) => sum + line.length, 0) + const rightLinesLengthSum = this.lines + .filter((line) => line.direction === 'right') + .reduce((sum, line) => sum + line.length, 0) + + const topLinesLengthSum = this.lines + .filter((line) => line.direction === 'top') + .reduce((sum, line) => sum + line.length, 0) + const bottomLinesLengthSum = this.lines + .filter((line) => line.direction === 'bottom') + .reduce((sum, line) => sum + line.length, 0) + + return ( + leftLinesLengthSum === rightLinesLengthSum && + topLinesLengthSum === bottomLinesLengthSum + ) + } + inPolygon(point) { const vertices = this.getCurrentPoints() let intersects = 0 @@ -302,6 +328,10 @@ export default class QPolygon extends fabric.Group { // 보조선 그리기 사각형에서만 drawHelpLine(chon = 4) { + if (!this.isValid()) { + return + } + if (this.lines.length === 4) { this.#drawHelpLineInRect(chon) } else if (this.lines.length === 6) {