QPolygon isValid 추가
This commit is contained in:
parent
876ad15eb0
commit
418fc5073d
@ -199,6 +199,32 @@ export default class QPolygon extends fabric.Group {
|
|||||||
this.canvas.renderAll()
|
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) {
|
inPolygon(point) {
|
||||||
const vertices = this.getCurrentPoints()
|
const vertices = this.getCurrentPoints()
|
||||||
let intersects = 0
|
let intersects = 0
|
||||||
@ -302,6 +328,10 @@ export default class QPolygon extends fabric.Group {
|
|||||||
|
|
||||||
// 보조선 그리기 사각형에서만
|
// 보조선 그리기 사각형에서만
|
||||||
drawHelpLine(chon = 4) {
|
drawHelpLine(chon = 4) {
|
||||||
|
if (!this.isValid()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (this.lines.length === 4) {
|
if (this.lines.length === 4) {
|
||||||
this.#drawHelpLineInRect(chon)
|
this.#drawHelpLineInRect(chon)
|
||||||
} else if (this.lines.length === 6) {
|
} else if (this.lines.length === 6) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user