점 6개일때 shape 추가
This commit is contained in:
parent
446f5ba093
commit
b04e7128a7
@ -1,6 +1,7 @@
|
|||||||
import { fabric } from 'fabric'
|
import { fabric } from 'fabric'
|
||||||
import {
|
import {
|
||||||
distanceBetweenPoints,
|
distanceBetweenPoints,
|
||||||
|
findTopTwoIndexesByDistance,
|
||||||
getDegreeByChon,
|
getDegreeByChon,
|
||||||
getDirectionByPoint,
|
getDirectionByPoint,
|
||||||
getRoofHeight,
|
getRoofHeight,
|
||||||
@ -19,6 +20,7 @@ export default class QPolygon extends fabric.Group {
|
|||||||
fontSize
|
fontSize
|
||||||
qCells = []
|
qCells = []
|
||||||
name
|
name
|
||||||
|
shape = 0 // 점 6개일때의 shape 모양
|
||||||
constructor(points, options, canvas) {
|
constructor(points, options, canvas) {
|
||||||
if (!options.fontSize) {
|
if (!options.fontSize) {
|
||||||
throw new Error('Font size is required.')
|
throw new Error('Font size is required.')
|
||||||
@ -38,6 +40,7 @@ export default class QPolygon extends fabric.Group {
|
|||||||
this.#init()
|
this.#init()
|
||||||
this.#addEvent()
|
this.#addEvent()
|
||||||
this.#initLines()
|
this.#initLines()
|
||||||
|
this.setShape()
|
||||||
}
|
}
|
||||||
|
|
||||||
#initLines() {
|
#initLines() {
|
||||||
@ -460,4 +463,50 @@ export default class QPolygon extends fabric.Group {
|
|||||||
this.addWithUpdate(realLine6)
|
this.addWithUpdate(realLine6)
|
||||||
this.canvas.add(ridge)
|
this.canvas.add(ridge)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 현재 점 6개만 가능
|
||||||
|
*/
|
||||||
|
setShape() {
|
||||||
|
let shape = 0
|
||||||
|
if (this.lines.length !== 6) {
|
||||||
|
throw new Error('Only 6 points are allowed.')
|
||||||
|
}
|
||||||
|
//외각선 기준
|
||||||
|
const topIndex = findTopTwoIndexesByDistance(this.lines) //배열중에 큰 2값을 가져옴 TODO: 나중에는 인자로 받아서 다각으로 수정 해야됨
|
||||||
|
|
||||||
|
//일단 배열 6개 짜리 기준의 선 번호
|
||||||
|
if (topIndex[0] === 4) {
|
||||||
|
if (topIndex[1] === 5) {
|
||||||
|
//1번
|
||||||
|
shape = 1
|
||||||
|
}
|
||||||
|
} else if (topIndex[0] === 1) {
|
||||||
|
//4번
|
||||||
|
if (topIndex[1] === 2) {
|
||||||
|
shape = 4
|
||||||
|
}
|
||||||
|
} else if (topIndex[0] === 0) {
|
||||||
|
if (topIndex[1] === 1) {
|
||||||
|
//2번
|
||||||
|
shape = 2
|
||||||
|
} else if (topIndex[1] === 5) {
|
||||||
|
//3번
|
||||||
|
shape = 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.shape = shape
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 현재 점 6개만 가능
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
getShape() {
|
||||||
|
if (this.lines.length !== 6) {
|
||||||
|
throw new Error('Only 6 points are allowed.')
|
||||||
|
}
|
||||||
|
return this.shape
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -392,6 +392,8 @@ export function useMode() {
|
|||||||
canvas,
|
canvas,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
console.log(polygon.getShape())
|
||||||
|
|
||||||
// 새로운 다각형 객체를 캔버스에 추가합니다.
|
// 새로운 다각형 객체를 캔버스에 추가합니다.
|
||||||
canvas.add(polygon)
|
canvas.add(polygon)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user