정렬 배열 리코일 적용

This commit is contained in:
yjnoh 2024-07-08 10:41:35 +09:00
parent fbc519573b
commit e3bff53c09
3 changed files with 19 additions and 5 deletions

View File

@ -6,8 +6,8 @@ import QLine from '@/components/fabric/QLine'
import QPolygon from '@/components/fabric/QPolygon' import QPolygon from '@/components/fabric/QPolygon'
import RangeSlider from './ui/RangeSlider' import RangeSlider from './ui/RangeSlider'
import { useRecoilState } from 'recoil' import { useRecoilState, useRecoilValue } from 'recoil'
import { canvasSizeState, fontSizeState } from '@/store/canvasAtom' import { canvasSizeState, fontSizeState, sortedPolygonArray } from '@/store/canvasAtom'
export default function Roof2() { export default function Roof2() {
const { const {
@ -28,6 +28,8 @@ export default function Roof2() {
// //
const [fontSize, setFontSize] = useRecoilState(fontSizeState) const [fontSize, setFontSize] = useRecoilState(fontSizeState)
const [sortedArray] = useRecoilState(sortedPolygonArray)
const [angle, setAngle] = useState(0) const [angle, setAngle] = useState(0)
const { const {
@ -121,6 +123,9 @@ export default function Roof2() {
*/ */
useEffect(() => { useEffect(() => {
canvasSizeMode() canvasSizeMode()
console.log('sortedArray', sortedArray)
}, [verticalSize, horizontalSize]) }, [verticalSize, horizontalSize])
const makeQPolygon = () => { const makeQPolygon = () => {

View File

@ -4,7 +4,7 @@ import QRect from '@/components/fabric/QRect'
import QPolygon from '@/components/fabric/QPolygon' import QPolygon from '@/components/fabric/QPolygon'
import { getStartIndex, rearrangeArray, findTopTwoIndexesByDistance } from '@/util/canvas-util' import { getStartIndex, rearrangeArray, findTopTwoIndexesByDistance } from '@/util/canvas-util'
import { useRecoilState } from 'recoil' import { useRecoilState } from 'recoil'
import { fontSizeState } from '@/store/canvasAtom' import { fontSizeState, sortedPolygonArray } from '@/store/canvasAtom'
export const Mode = { export const Mode = {
DRAW_LINE: 'drawLine', // 기준선 긋기모드 DRAW_LINE: 'drawLine', // 기준선 긋기모드
@ -24,6 +24,7 @@ export function useMode() {
const [zoom, setZoom] = useState(100) const [zoom, setZoom] = useState(100)
const [fontSize] = useRecoilState(fontSizeState) const [fontSize] = useRecoilState(fontSizeState)
const [shape, setShape] = useState(0) const [shape, setShape] = useState(0)
const [sortedArray, setSortedArray] = useRecoilState(sortedPolygonArray)
const addEvent = (mode) => { const addEvent = (mode) => {
switch (mode) { switch (mode) {
@ -388,8 +389,10 @@ export function useMode() {
if(tmpArraySorted[0].direction === 'right') { //시계방향 if(tmpArraySorted[0].direction === 'right') { //시계방향
tmpArraySorted = tmpArraySorted.reverse() //그럼 배열을 거꾸로 만들어서 무조건 반시계방향으로 배열 보정 tmpArraySorted = tmpArraySorted.reverse() //그럼 배열을 거꾸로 만들어서 무조건 반시계방향으로 배열 보정
} }
setSortedArray(tmpArraySorted) //recoil에 넣음
const topIndex = findTopTwoIndexesByDistance(tmpArraySorted) //배열중에 큰 2값을 가져옴 TODO: 나중에는 인자로 받아서 다각으로 수정 해야됨 const topIndex = findTopTwoIndexesByDistance(tmpArraySorted) //배열중에 큰 2값을 가져옴 TODO: 나중에는 인자로 받아서 다각으로 수정 해야됨
//일단 배열 6개 짜리 기준의 선 번호 //일단 배열 6개 짜리 기준의 선 번호

View File

@ -17,3 +17,9 @@ export const canvasSizeState = atom({
horizontal: 1000, horizontal: 1000,
}, },
}) })
export const sortedPolygonArray = atom({
key: 'sortedArray',
default : [],
dangerouslyAllowMutability: true,
})