From 74816e04030f187bd8829acee584f8de128f6540 Mon Sep 17 00:00:00 2001 From: nalpari Date: Fri, 5 Jul 2024 10:08:24 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=9D=BC=EC=9D=B8=208=EA=B0=9C=20?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EB=B6=84=EA=B8=B0=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 라인 6개 케이스와 겹치는 부분 분기 처리 스팀 팍팍 빠직빠직 --- src/hooks/useMode.js | 168 ++++++++++++++++++++++++++++++------------- 1 file changed, 120 insertions(+), 48 deletions(-) diff --git a/src/hooks/useMode.js b/src/hooks/useMode.js index 88d50d4a..9f20990f 100644 --- a/src/hooks/useMode.js +++ b/src/hooks/useMode.js @@ -456,12 +456,21 @@ export function useMode() { // 다름 라인이 오른쪽으로 이동 if (historyLines.current[i].direction === 'top') { if (prev.direction !== 'right') { - newOuterlines.push({ - x1: historyLines.current[i].x1 - 50, - y1: historyLines.current[i].y1 + 50, - x2: historyLines.current[i].x2 - 50, - y2: historyLines.current[i].y2 - 50, - }) + if(historyLines.current.length === 6) { + newOuterlines.push({ + x1: historyLines.current[i].x1 - 50, + y1: historyLines.current[i].y1 + 50, + x2: historyLines.current[i].x2 - 50, + y2: historyLines.current[i].y2 - 50, + }) + } else if(historyLines.current.length === 8) { + newOuterlines.push({ + x1: historyLines.current[i].x1 + 50, + y1: historyLines.current[i].y1 - 50, + x2: historyLines.current[i].x2 + 50, + y2: historyLines.current[i].y2 + 50, + } + } } else { newOuterlines.push({ x1: historyLines.current[i].x1 + 50, @@ -473,12 +482,21 @@ export function useMode() { } else { // bottom if (prev?.direction !== 'right') { - newOuterlines.push({ - x1: historyLines.current[i].x1 - 50, - y1: historyLines.current[i].y1 - 50, - x2: historyLines.current[i].x2 - 50, - y2: historyLines.current[i].y2 + 50, - }) + if(historyLines.current.length === 6) { + newOuterlines.push({ + x1: historyLines.current[i].x1 - 50, + y1: historyLines.current[i].y1 - 50, + x2: historyLines.current[i].x2 - 50, + y2: historyLines.current[i].y2 + 50, + }) + } else if(historyLines.current.length === 8) { + newOuterlines.push({ + x1: historyLines.current[i].x1 + 50, + y1: historyLines.current[i].y1 + 50, + x2: historyLines.current[i].x2 + 50, + y2: historyLines.current[i].y2 - 50, + }) + } } else { newOuterlines.push({ x1: historyLines.current[i].x1 - 50, @@ -491,12 +509,21 @@ export function useMode() { } else if (next.direction === 'left') { if (historyLines.current[i].direction === 'top') { if (prev?.direction !== 'left') { - newOuterlines.push({ - x1: historyLines.current[i].x1 + 50, - y1: historyLines.current[i].y1 + 50, - x2: historyLines.current[i].x2 + 50, - y2: historyLines.current[i].y2 - 50, - }) + if(historyLines.current.length === 6) { + newOuterlines.push({ + x1: historyLines.current[i].x1 + 50, + y1: historyLines.current[i].y1 + 50, + x2: historyLines.current[i].x2 + 50, + y2: historyLines.current[i].y2 - 50, + }) + } else if(historyLines.current.length === 8) { + newOuterlines.push({ + x1: historyLines.current[i].x1 - 50, + y1: historyLines.current[i].y1 - 50, + x2: historyLines.current[i].x2 - 50, + y2: historyLines.current[i].y2 + 50, + }) + } } else { newOuterlines.push({ x1: historyLines.current[i].x1 - 50, @@ -508,12 +535,21 @@ export function useMode() { } else { // bottom if (prev?.direction !== 'left') { - newOuterlines.push({ - x1: historyLines.current[i].x1 + 50, - y1: historyLines.current[i].y1 - 50, - x2: historyLines.current[i].x2 + 50, - y2: historyLines.current[i].y2 + 50, - }) + if(historyLines.current.length === 6) { + newOuterlines.push({ + x1: historyLines.current[i].x1 + 50, + y1: historyLines.current[i].y1 - 50, + x2: historyLines.current[i].x2 + 50, + y2: historyLines.current[i].y2 + 50, + }) + } else if(historyLines.current.length === 8) { + newOuterlines.push({ + x1: historyLines.current[i].x1 - 50, + y1: historyLines.current[i].y1 + 50, + x2: historyLines.current[i].x2 - 50, + y2: historyLines.current[i].y2 - 50, + }) + } } else { newOuterlines.push({ x1: historyLines.current[i].x1 - 50, @@ -526,12 +562,21 @@ export function useMode() { } else if (next.direction === 'top') { if (historyLines.current[i].direction === 'right') { if (prev?.direction !== 'top') { - newOuterlines.push({ - x1: historyLines.current[i].x1 - 50, - y1: historyLines.current[i].y1 + 50, - x2: historyLines.current[i].x2 + 50, - y2: historyLines.current[i].y2 + 50, - }) + if(historyLines.current.length === 6) { + newOuterlines.push({ + x1: historyLines.current[i].x1 - 50, + y1: historyLines.current[i].y1 + 50, + x2: historyLines.current[i].x2 + 50, + y2: historyLines.current[i].y2 + 50, + }) + } else if(historyLines.current.length === 8) { + newOuterlines.push({ + x1: historyLines.current[i].x1 + 50, + y1: historyLines.current[i].y1 - 50, + x2: historyLines.current[i].x2 - 50, + y2: historyLines.current[i].y2 - 50, + }) + } } else { newOuterlines.push({ x1: historyLines.current[i].x1 + 50, @@ -543,12 +588,21 @@ export function useMode() { } else { // left if (prev?.direction !== 'top') { - newOuterlines.push({ - x1: historyLines.current[i].x1 + 50, - y1: historyLines.current[i].y1 + 50, - x2: historyLines.current[i].x2 - 50, - y2: historyLines.current[i].y2 + 50, - }) + if(historyLines.current.length === 6) { + newOuterlines.push({ + x1: historyLines.current[i].x1 + 50, + y1: historyLines.current[i].y1 + 50, + x2: historyLines.current[i].x2 - 50, + y2: historyLines.current[i].y2 + 50, + }) + } else if(historyLines.current.length === 8) { + newOuterlines.push({ + x1: historyLines.current[i].x1 - 50, + y1: historyLines.current[i].y1 - 50, + x2: historyLines.current[i].x2 + 50, + y2: historyLines.current[i].y2 - 50, + }) + } } else { newOuterlines.push({ x1: historyLines.current[i].x1 - 50, @@ -561,12 +615,21 @@ export function useMode() { } else if (next.direction === 'bottom') { if (historyLines.current[i].direction === 'right') { if (prev?.direction !== 'bottom') { - newOuterlines.push({ - x1: historyLines.current[i].x1 - 50, - y1: historyLines.current[i].y1 - 50, - x2: historyLines.current[i].x2 + 50, - y2: historyLines.current[i].y2 - 50, - }) + if(historyLines.current.length === 6) { + newOuterlines.push({ + x1: historyLines.current[i].x1 - 50, + y1: historyLines.current[i].y1 - 50, + x2: historyLines.current[i].x2 + 50, + y2: historyLines.current[i].y2 - 50, + }) + } else if(historyLines.current.length === 8) { + newOuterlines.push({ + x1: historyLines.current[i].x1 + 50, + y1: historyLines.current[i].y1 + 50, + x2: historyLines.current[i].x2 - 50, + y2: historyLines.current[i].y2 + 50, + }) + } } else { newOuterlines.push({ x1: historyLines.current[i].x1 - 50, @@ -578,12 +641,21 @@ export function useMode() { } else { // left if (prev.direction !== 'bottom') { - newOuterlines.push({ - x1: historyLines.current[i].x1 + 50, - y1: historyLines.current[i].y1 - 50, - x2: historyLines.current[i].x2 - 50, - y2: historyLines.current[i].y2 - 50, - }) + if(historyLines.current.length === 6) { + newOuterlines.push({ + x1: historyLines.current[i].x1 + 50, + y1: historyLines.current[i].y1 - 50, + x2: historyLines.current[i].x2 - 50, + y2: historyLines.current[i].y2 - 50, + }) + } else if(historyLines.current.length === 8) { + newOuterlines.push({ + x1: historyLines.current[i].x1 - 50, + y1: historyLines.current[i].y1 + 50, + x2: historyLines.current[i].x2 + 50, + y2: historyLines.current[i].y2 + 50, + }) + } } else { newOuterlines.push({ x1: historyLines.current[i].x1 - 50,