모든 각이 45도의 배수인지 확인하는 함수 추가

This commit is contained in:
hyojun.choi 2025-06-19 14:56:14 +09:00
parent 9a543c4b90
commit 8853b7ae86
2 changed files with 21 additions and 0 deletions

View File

@ -212,6 +212,7 @@ export const SAVE_KEY = [
'endPoint',
'editable',
'isSortedPoints',
'isMultipleOf45',
]
export const OBJECT_PROTOTYPE = [fabric.Line.prototype, fabric.Polygon.prototype, fabric.Triangle.prototype, fabric.Group.prototype]

View File

@ -1162,6 +1162,8 @@ export const usePolygon = () => {
pitch: pitch,
})
roof.isMultipleOf45 = calculateDegree(roof)
//allLines중 생성된 roof와 관련있는 line을 찾는다.
const roofLines = [...polygonLines, ...polygon.innerLines].filter((line) => {
@ -1208,6 +1210,24 @@ export const usePolygon = () => {
canvas.discardActiveObject()
}
const calculateDegree = (polygon) => {
const degrees = []
// polygon.lines를 순회하며 각도를 구해 출력
polygon.lines.forEach((line, idx) => {
const dx = line.x2 - line.x1
const dy = line.y2 - line.y1
const rad = Math.atan2(dy, dx)
const degree = (rad * 180) / Math.PI
degrees.push(degree)
})
function isMultipleOf45(degree, epsilon = 1) {
return Math.abs(degree % 45) <= epsilon || Math.abs((degree % 45) - 45) <= epsilon
}
return degrees.every((degree) => isMultipleOf45(degree))
}
const getSplitRoofsPoints = (allLines) => {
// ==== Utility functions ====