지붕 모양 파악 로직 수정
This commit is contained in:
parent
c10a46e86f
commit
7175cd0485
@ -268,64 +268,70 @@ export const QPolygon = fabric.util.createClass(fabric.Polygon, {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
const types = []
|
const types = this.lines.map((line) => line.attributes.type)
|
||||||
this.lines.forEach((line) => types.push(line.attributes.type))
|
|
||||||
|
|
||||||
const gableType = [LINE_TYPE.WALLLINE.GABLE, LINE_TYPE.WALLLINE.JERKINHEAD]
|
const isGableRoof = function (types) {
|
||||||
const isEaves = types.every((type) => type === LINE_TYPE.WALLLINE.EAVES)
|
if (!types.includes(LINE_TYPE.WALLLINE.GABLE)) {
|
||||||
|
return false
|
||||||
let isGable = false
|
|
||||||
if (types.includes(LINE_TYPE.WALLLINE.GABLE)) {
|
|
||||||
const gableOdd = types.filter((type, i) => i % 2 === 0)
|
|
||||||
const gableEven = types.filter((type, i) => i % 2 === 1)
|
|
||||||
if (
|
|
||||||
(gableOdd.every((type) => type === LINE_TYPE.WALLLINE.EAVES) && gableEven.every((type) => gableType.includes(type))) ||
|
|
||||||
(gableEven.every((type) => type === LINE_TYPE.WALLLINE.EAVES) && gableOdd.every((type) => gableType.includes(type)))
|
|
||||||
) {
|
|
||||||
isGable = true
|
|
||||||
}
|
}
|
||||||
|
const gableTypes = [LINE_TYPE.WALLLINE.GABLE, LINE_TYPE.WALLLINE.JERKINHEAD]
|
||||||
|
const oddTypes = types.filter((type, i) => i % 2 === 0)
|
||||||
|
const evenTypes = types.filter((type, i) => i % 2 === 1)
|
||||||
|
|
||||||
|
const oddAllEaves = oddTypes.every((type) => type === LINE_TYPE.WALLLINE.EAVES)
|
||||||
|
const evenAllGable = evenTypes.every((type) => gableTypes.includes(type))
|
||||||
|
const evenAllEaves = evenTypes.every((type) => type === LINE_TYPE.WALLLINE.EAVES)
|
||||||
|
const oddAllGable = oddTypes.every((type) => gableTypes.includes(type))
|
||||||
|
|
||||||
|
return (oddAllEaves && evenAllGable) || (evenAllEaves && oddAllGable)
|
||||||
}
|
}
|
||||||
|
|
||||||
let isShed = false
|
const isShedRoof = function (types, lines) {
|
||||||
if (types.includes(LINE_TYPE.WALLLINE.SHED)) {
|
const gableTypes = [LINE_TYPE.WALLLINE.GABLE, LINE_TYPE.WALLLINE.JERKINHEAD]
|
||||||
const sheds = this.lines.filter((line) => line.attributes !== undefined && line.attributes.type === LINE_TYPE.WALLLINE.SHED)
|
if (!types.includes(LINE_TYPE.WALLLINE.SHED)) {
|
||||||
const areLinesParallel = function (line1, line2) {
|
return false
|
||||||
const angle1 = calculateAngle(line1.startPoint, line1.endPoint)
|
}
|
||||||
const angle2 = calculateAngle(line2.startPoint, line2.endPoint)
|
const shedLines = lines.filter((line) => line.attributes?.type === LINE_TYPE.WALLLINE.SHED)
|
||||||
return angle1 === angle2
|
const areShedLinesParallel = function (shedLines) {
|
||||||
|
return shedLines.every((shed, i) => {
|
||||||
|
const nextShed = shedLines[(i + 1) % shedLines.length]
|
||||||
|
const angle1 = calculateAngle(shed.startPoint, shed.endPoint)
|
||||||
|
const angle2 = calculateAngle(nextShed.startPoint, nextShed.endPoint)
|
||||||
|
return angle1 === angle2
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (!areShedLinesParallel(shedLines)) {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
let isShedRoof = true
|
|
||||||
sheds.forEach((shed, i) => {
|
|
||||||
isShedRoof = areLinesParallel(shed, sheds[(i + 1) % sheds.length])
|
|
||||||
})
|
|
||||||
|
|
||||||
if (isShedRoof) {
|
const getParallelEavesLines = function (shedLines, lines) {
|
||||||
const eaves = this.lines
|
const eavesLines = lines.filter((line) => line.attributes?.type === LINE_TYPE.WALLLINE.EAVES)
|
||||||
.filter((line) => line.attributes !== undefined && line.attributes.type === LINE_TYPE.WALLLINE.EAVES)
|
|
||||||
.filter((line) => {
|
const referenceAngle = calculateAngle(shedLines[0].startPoint, shedLines[0].endPoint)
|
||||||
const angle1 = calculateAngle(sheds[0].startPoint, sheds[0].endPoint)
|
|
||||||
const angle2 = calculateAngle(line.startPoint, line.endPoint)
|
return eavesLines.filter((line) => {
|
||||||
if (Math.abs(angle1 - angle2) === 180) {
|
const eavesAngle = calculateAngle(line.startPoint, line.endPoint)
|
||||||
return line
|
return Math.abs(referenceAngle - eavesAngle) === 180
|
||||||
}
|
})
|
||||||
})
|
|
||||||
if (eaves.length > 0) {
|
|
||||||
const gables = this.lines.filter((line) => sheds.includes(line) === false && eaves.includes(line) === false)
|
|
||||||
const isGable = gables.every((line) => gableType.includes(line.attributes.type))
|
|
||||||
if (isGable) {
|
|
||||||
isShed = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const parallelEaves = getParallelEavesLines(shedLines, lines)
|
||||||
|
if (parallelEaves.length === 0) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const remainingLines = lines.filter((line) => !shedLines.includes(line) && !parallelEaves.includes(line))
|
||||||
|
return remainingLines.every((line) => gableTypes.includes(line.attributes.type))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEaves) {
|
if (types.every((type) => type === LINE_TYPE.WALLLINE.EAVES)) {
|
||||||
// 용마루 -- straight-skeleton
|
// 용마루 -- straight-skeleton
|
||||||
console.log('용마루 지붕')
|
console.log('용마루 지붕')
|
||||||
} else if (isGable) {
|
} else if (isGableRoof(types)) {
|
||||||
// A형, B형 박공 지붕
|
// A형, B형 박공 지붕
|
||||||
console.log('패턴 지붕')
|
console.log('패턴 지붕')
|
||||||
} else if (isShed) {
|
isGableRoof(types)
|
||||||
|
} else if (isShedRoof(types, this.lines)) {
|
||||||
console.log('한쪽흐름 지붕')
|
console.log('한쪽흐름 지붕')
|
||||||
drawShedRoof(this.id, this.canvas, textMode)
|
drawShedRoof(this.id, this.canvas, textMode)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user