diff --git a/src/components/Roof2.jsx b/src/components/Roof2.jsx index 27aef946..ecd83b02 100644 --- a/src/components/Roof2.jsx +++ b/src/components/Roof2.jsx @@ -230,7 +230,7 @@ export default function Roof2() { ] if (canvas) { - const polygon = new QPolygon(eightPoint4, { + const polygon = new QPolygon(type1, { fill: 'transparent', stroke: 'black', strokeWidth: 1, diff --git a/src/util/qpolygon-utils.js b/src/util/qpolygon-utils.js index 982fa111..b50cd4b9 100644 --- a/src/util/qpolygon-utils.js +++ b/src/util/qpolygon-utils.js @@ -48,7 +48,7 @@ export const drawHelpLineInHexagon = (polygon, chon) => { // line을 이등변 삼각형의 밑변으로 보고 높이를 구한다. - const helpLineLength = Math.sqrt(Math.pow(line.length, 2) - Math.pow(line.length / 2, 2)) - 10 + const helpLineLength = Math.sqrt(2 * Math.pow(line.length / 2, 2)) const firstX2 = Math.floor(line.x1 + helpLineLength * Math.cos(angle1)) const firstY2 = Math.floor(line.y1 + helpLineLength * Math.sin(angle1)) @@ -182,18 +182,61 @@ export const drawHelpLineInHexagon = (polygon, chon) => { /** * 안쓰는 점 제거 */ - centerInterSectionPoints.forEach((point) => { - ridgeEndPoints.forEach((endPoint) => { - if (!(Math.abs(point.x - endPoint.x) < 2 && Math.abs(point.y - endPoint.y) < 2)) { - centerInterSectionPoints.splice(centerInterSectionPoints.indexOf(point), 1) + + const ridgeEndRemainingPoints = [...ridgeEndPoints] + + const uniqueInterSectionPoints = Array.from(new Set(centerInterSectionPoints.map((point) => `${point.x},${point.y}`))).map((key) => { + const [x, y] = key.split(',').map(Number) + return { x, y } + }) + + while (ridgeEndRemainingPoints.length > 0) { + const point = ridgeEndRemainingPoints.shift() + let isExist = false + uniqueInterSectionPoints.forEach((uniquePoint) => { + const degree = calculateAngle(point, uniquePoint) + + if (Math.abs(45 - Math.abs(degree)) <= 5 || Math.abs(135 - Math.abs(degree)) <= 5) { + const line = new QLine([point.x, point.y, uniquePoint.x, uniquePoint.y], { + stroke: 'purple', + fontSize: polygon.fontSize, + }) + + ridgeEndPoints.push(uniquePoint) + + ridgeEndPoints.splice(ridgeEndPoints.indexOf(point), 1) + + isExist = true + + polygon.canvas.add(line) + polygon.canvas.renderAll() + } + + if (isExist) { + return } }) - }) + } + + const ridgeEndRemainingPoints2 = [...ridgeEndPoints] + + while (ridgeEndRemainingPoints2.length > 0) { + // 남아있는 점끼리 연결한다. + const point = ridgeEndRemainingPoints2.shift() + const closestPoint = findClosestPoint(point, ridgeEndRemainingPoints2) + if (!closestPoint) continue + const line = new QLine([point.x, point.y, closestPoint.x, closestPoint.y], { + stroke: 'purple', + fontSize: polygon.fontSize, + }) + + polygon.canvas.add(line) + polygon.canvas.renderAll() + } // ridgeEndPoints와 가까운 centerInterSectionPoints를 찾아서 연결한다. const remainingPoints = centerInterSectionPoints - const ridgeEndRemainingPoints = ridgeEndPoints - + /* helpLines.forEach((line) => { remainingPoints.forEach((point) => { if (line.relatedPoints.includes(point)) { @@ -208,18 +251,7 @@ export const drawHelpLineInHexagon = (polygon, chon) => { }) }) - while (ridgeEndRemainingPoints.length > 0) { - const point = ridgeEndRemainingPoints.shift() - const closestPoint = findClosestPoint(point, remainingPoints) - if (!closestPoint) continue - const line = new QLine([point.x, point.y, closestPoint.x, closestPoint.y], { - stroke: 'green', - fontSize: polygon.fontSize, - }) - polygon.canvas.add(line) - polygon.canvas.renderAll() - } // centerInterSectionPoints에 남아있는 점들을 가까운 점끼리 연결한다. while (remainingPoints.length > 0) { @@ -248,9 +280,11 @@ export const drawHelpLineInHexagon = (polygon, chon) => { polygon.canvas.add(line) polygon.canvas.renderAll() - } + }*/ } +export const drawHelpLineInHexagon2 = (polygon, chon) => {} + export const drawCenterLines = (polygon) => { const centerLines = [] @@ -342,3 +376,9 @@ const getOneSideLines = (polygon) => { return line }) } +const calculateAngle = (point1, point2) => { + const deltaX = point2.x - point1.x + const deltaY = point2.y - point1.y + const angleInRadians = Math.atan2(deltaY, deltaX) + return angleInRadians * (180 / Math.PI) +}