Qpolygon 수정

This commit is contained in:
hyojun.choi 2024-07-31 10:13:11 +09:00
parent d5a124c335
commit ba590c4f9f

View File

@ -1,8 +1,8 @@
import { fabric } from 'fabric' import { fabric } from 'fabric'
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
import { QLine } from '@/components/fabric/QLine' import { QLine } from '@/components/fabric/QLine'
import { distanceBetweenPoints, findTopTwoIndexesByDistance, getDirectionByPoint, sortedPoints } from '@/util/canvas-util' import { distanceBetweenPoints, findTopTwoIndexesByDistance, getDirectionByPoint, sortedPointLessEightPoint, sortedPoints } from '@/util/canvas-util'
import { drawHelpLineInHexagon } from '@/util/qpolygon-utils' import { drawHelpLineInHexagon, drawHelpLineInHexagon2, drawHelpLineInHexagon3 } from '@/util/qpolygon-utils'
export const QPolygon = fabric.util.createClass(fabric.Polygon, { export const QPolygon = fabric.util.createClass(fabric.Polygon, {
type: 'QPolygon', type: 'QPolygon',
@ -16,7 +16,12 @@ export const QPolygon = fabric.util.createClass(fabric.Polygon, {
point.x = Math.round(point.x) point.x = Math.round(point.x)
point.y = Math.round(point.y) point.y = Math.round(point.y)
}) })
points = sortedPoints(points) if (points.length <= 8) {
points = sortedPointLessEightPoint(points)
} else {
points = sortedPoints(points)
}
this.callSuper('initialize', points, options) this.callSuper('initialize', points, options)
if (options.id) { if (options.id) {
this.id = options.id this.id = options.id
@ -117,11 +122,11 @@ export const QPolygon = fabric.util.createClass(fabric.Polygon, {
// 보조선 그리기 // 보조선 그리기
drawHelpLine(chon = 4) { drawHelpLine(chon = 4) {
drawHelpLineInHexagon(this, chon) drawHelpLineInHexagon2(this, chon)
}, },
addLengthText() { addLengthText() {
const points = this.getCurrentPoints() let points = this.points
points.forEach((start, i) => { points.forEach((start, i) => {
const thisText = this.canvas.getObjects().find((obj) => obj.name === 'lengthText' && obj.parentId === this.id && obj.idx === i) const thisText = this.canvas.getObjects().find((obj) => obj.name === 'lengthText' && obj.parentId === this.id && obj.idx === i)