모든 각이 45도의 배수인지 확인하는 함수 추가
This commit is contained in:
parent
9a543c4b90
commit
8853b7ae86
@ -212,6 +212,7 @@ export const SAVE_KEY = [
|
|||||||
'endPoint',
|
'endPoint',
|
||||||
'editable',
|
'editable',
|
||||||
'isSortedPoints',
|
'isSortedPoints',
|
||||||
|
'isMultipleOf45',
|
||||||
]
|
]
|
||||||
|
|
||||||
export const OBJECT_PROTOTYPE = [fabric.Line.prototype, fabric.Polygon.prototype, fabric.Triangle.prototype, fabric.Group.prototype]
|
export const OBJECT_PROTOTYPE = [fabric.Line.prototype, fabric.Polygon.prototype, fabric.Triangle.prototype, fabric.Group.prototype]
|
||||||
|
|||||||
@ -1162,6 +1162,8 @@ export const usePolygon = () => {
|
|||||||
pitch: pitch,
|
pitch: pitch,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
roof.isMultipleOf45 = calculateDegree(roof)
|
||||||
|
|
||||||
//allLines중 생성된 roof와 관련있는 line을 찾는다.
|
//allLines중 생성된 roof와 관련있는 line을 찾는다.
|
||||||
|
|
||||||
const roofLines = [...polygonLines, ...polygon.innerLines].filter((line) => {
|
const roofLines = [...polygonLines, ...polygon.innerLines].filter((line) => {
|
||||||
@ -1208,6 +1210,24 @@ export const usePolygon = () => {
|
|||||||
canvas.discardActiveObject()
|
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) => {
|
const getSplitRoofsPoints = (allLines) => {
|
||||||
// ==== Utility functions ====
|
// ==== Utility functions ====
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user