점 8개 오류

This commit is contained in:
hyojun.choi 2024-07-22 17:03:32 +09:00
parent e34f3c002a
commit ae5009ba2b

View File

@ -38,7 +38,7 @@ export function actionHandler(eventData, transform, x, y) {
// define a function that can keep the polygon in the same position when we change its width/height/top/left // define a function that can keep the polygon in the same position when we change its width/height/top/left
export function anchorWrapper(anchorIndex, fn) { export function anchorWrapper(anchorIndex, fn) {
return function(eventData, transform, x, y) { return function (eventData, transform, x, y) {
let fabricObject = transform.target let fabricObject = transform.target
let originX = fabricObject?.points[anchorIndex].x - fabricObject.pathOffset.x let originX = fabricObject?.points[anchorIndex].x - fabricObject.pathOffset.x
let originY = fabricObject.points[anchorIndex].y - fabricObject.pathOffset.y let originY = fabricObject.points[anchorIndex].y - fabricObject.pathOffset.y
@ -365,11 +365,11 @@ export const sortedPoints = (points) => {
for (let i = 0; i < copyPoints.length; i++) { for (let i = 0; i < copyPoints.length; i++) {
// y값이 같은 point가 많은 경우 그 중 x값이 가장 큰걸 찾는다. // y값이 같은 point가 많은 경우 그 중 x값이 가장 큰걸 찾는다.
const temp = copyPoints.filter((point) => point.y === currentPoint.y) const temp = copyPoints.filter((point) => point.y === currentPoint.y)
// temp중 x값이 가장 큰 값 // temp중 x값이 가장 큰 값 copyPoint보다 큰값
const max = temp.reduce((prev, current) => (prev.x >= current.x ? prev : current)) const min = temp.reduce((prev, current) => (prev.x <= current.x ? prev : current))
resultPoints.push(max) resultPoints.push(min)
currentPoint = max currentPoint = min
copyPoints.splice(copyPoints.indexOf(max), 1) copyPoints.splice(copyPoints.indexOf(min), 1)
index++ index++
break break
} }
@ -378,12 +378,12 @@ export const sortedPoints = (points) => {
for (let i = 0; i < copyPoints.length; i++) { for (let i = 0; i < copyPoints.length; i++) {
// x값이 같은 point가 많은 경우 그 중 y값이 가장 큰걸 찾는다. // x값이 같은 point가 많은 경우 그 중 y값이 가장 큰걸 찾는다.
const temp = copyPoints.filter((point) => point.x === currentPoint.x) const temp = copyPoints.filter((point) => point.x === currentPoint.x)
// temp중 y값이 가장 // temp중 y값이 가장 작은
const max = temp.reduce((prev, current) => (prev.y >= current.y ? prev : current)) const min = temp.reduce((prev, current) => (prev.y <= current.y ? prev : current))
resultPoints.push(max) resultPoints.push(min)
currentPoint = max currentPoint = min
copyPoints.splice(copyPoints.indexOf(max), 1) copyPoints.splice(copyPoints.indexOf(min), 1)
index++ index++
break break
} }