Merge pull request 'dev' (#364) from dev into dev-deploy
Reviewed-on: #364
This commit is contained in:
commit
e5d32dc466
@ -2,7 +2,7 @@ import { fabric } from 'fabric'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { QLine } from '@/components/fabric/QLine'
|
||||
import { distanceBetweenPoints, findTopTwoIndexesByDistance, getDirectionByPoint, sortedPointLessEightPoint, sortedPoints } from '@/util/canvas-util'
|
||||
import { calculateAngle, drawRidgeRoof, drawShedRoof, toGeoJSON } from '@/util/qpolygon-utils'
|
||||
import { calculateAngle, drawGableRoof, drawRidgeRoof, drawShedRoof, toGeoJSON } from '@/util/qpolygon-utils'
|
||||
import * as turf from '@turf/turf'
|
||||
import { LINE_TYPE, POLYGON_TYPE } from '@/common/common'
|
||||
import Big from 'big.js'
|
||||
@ -255,6 +255,7 @@ export const QPolygon = fabric.util.createClass(fabric.Polygon, {
|
||||
// && obj.name !== 'outerLinePoint',
|
||||
)
|
||||
.forEach((obj) => this.canvas.remove(obj))
|
||||
this.innerLines = []
|
||||
this.canvas.renderAll()
|
||||
|
||||
let textMode = 'plane'
|
||||
@ -274,50 +275,75 @@ export const QPolygon = fabric.util.createClass(fabric.Polygon, {
|
||||
break
|
||||
}
|
||||
|
||||
const types = []
|
||||
this.lines.forEach((line) => types.push(line.attributes.type))
|
||||
const types = this.lines.map((line) => line.attributes.type)
|
||||
|
||||
const gableType = [LINE_TYPE.WALLLINE.GABLE, LINE_TYPE.WALLLINE.JERKINHEAD]
|
||||
const isGableRoof = function (types) {
|
||||
if (!types.includes(LINE_TYPE.WALLLINE.GABLE)) {
|
||||
return false
|
||||
}
|
||||
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 hasShed = types.includes(LINE_TYPE.WALLLINE.SHED)
|
||||
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))
|
||||
|
||||
if (hasShed) {
|
||||
const sheds = this.lines.filter((line) => line.attributes !== undefined && line.attributes.type === LINE_TYPE.WALLLINE.SHED)
|
||||
const areLinesParallel = function (line1, line2) {
|
||||
const angle1 = calculateAngle(line1.startPoint, line1.endPoint)
|
||||
const angle2 = calculateAngle(line2.startPoint, line2.endPoint)
|
||||
return angle1 === angle2
|
||||
return (oddAllEaves && evenAllGable) || (evenAllEaves && oddAllGable)
|
||||
}
|
||||
|
||||
const isShedRoof = function (types, lines) {
|
||||
const gableTypes = [LINE_TYPE.WALLLINE.GABLE, LINE_TYPE.WALLLINE.JERKINHEAD]
|
||||
if (!types.includes(LINE_TYPE.WALLLINE.SHED)) {
|
||||
return false
|
||||
}
|
||||
const shedLines = lines.filter((line) => line.attributes?.type === LINE_TYPE.WALLLINE.SHED)
|
||||
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 eaves = this.lines
|
||||
.filter((line) => line.attributes !== undefined && line.attributes.type === LINE_TYPE.WALLLINE.EAVES)
|
||||
.filter((line) => {
|
||||
const angle1 = calculateAngle(sheds[0].startPoint, sheds[0].endPoint)
|
||||
const angle2 = calculateAngle(line.startPoint, line.endPoint)
|
||||
if (Math.abs(angle1 - angle2) === 180) {
|
||||
return line
|
||||
}
|
||||
})
|
||||
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) {
|
||||
drawShedRoof(this.id, this.canvas, textMode)
|
||||
} else {
|
||||
drawRidgeRoof(this.id, this.canvas, textMode)
|
||||
}
|
||||
} else {
|
||||
drawRidgeRoof(this.id, this.canvas, textMode)
|
||||
}
|
||||
} else {
|
||||
drawRidgeRoof(this.id, this.canvas, textMode)
|
||||
const getParallelEavesLines = function (shedLines, lines) {
|
||||
const eavesLines = lines.filter((line) => line.attributes?.type === LINE_TYPE.WALLLINE.EAVES)
|
||||
|
||||
const referenceAngle = calculateAngle(shedLines[0].startPoint, shedLines[0].endPoint)
|
||||
|
||||
return eavesLines.filter((line) => {
|
||||
const eavesAngle = calculateAngle(line.startPoint, line.endPoint)
|
||||
return Math.abs(referenceAngle - eavesAngle) === 180
|
||||
})
|
||||
}
|
||||
|
||||
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 (types.every((type) => type === LINE_TYPE.WALLLINE.EAVES)) {
|
||||
// 용마루 -- straight-skeleton
|
||||
console.log('용마루 지붕')
|
||||
drawRidgeRoof(this.id, this.canvas, textMode)
|
||||
} else if (isGableRoof(types)) {
|
||||
// A형, B형 박공 지붕
|
||||
console.log('패턴 지붕')
|
||||
drawGableRoof(this.id, this.canvas, textMode)
|
||||
} else if (isShedRoof(types, this.lines)) {
|
||||
console.log('한쪽흐름 지붕')
|
||||
drawShedRoof(this.id, this.canvas, textMode)
|
||||
} else {
|
||||
console.log('변별로 설정')
|
||||
drawRidgeRoof(this.id, this.canvas, textMode)
|
||||
}
|
||||
},
|
||||
|
||||
@ -49,34 +49,25 @@ export default function Simulator() {
|
||||
return isNaN(num) ? 0 : num
|
||||
}),
|
||||
|
||||
backgroundColor: [
|
||||
'rgba(255, 99, 132, 0.2)',
|
||||
'rgba(54, 162, 235, 0.2)',
|
||||
'rgba(255, 206, 86, 0.2)',
|
||||
'rgba(75, 192, 192, 0.2)',
|
||||
'rgba(153, 102, 255, 0.2)',
|
||||
'rgba(255, 159, 64, 0.2)',
|
||||
'rgba(0, 99, 132, 0.2)',
|
||||
'rgba(0, 162, 235, 0.2)',
|
||||
'rgba(0, 206, 86, 0.2)',
|
||||
'rgba(0, 192, 192, 0.2)',
|
||||
'rgba(0, 102, 255, 0.2)',
|
||||
'rgba(0, 159, 64, 0.2)',
|
||||
],
|
||||
borderColor: [
|
||||
'rgba(255, 99, 132, 0.2)',
|
||||
'rgba(54, 162, 235, 0.2)',
|
||||
'rgba(255, 206, 86, 0.2)',
|
||||
'rgba(75, 192, 192, 0.2)',
|
||||
'rgba(153, 102, 255, 0.2)',
|
||||
'rgba(255, 159, 64, 0.2)',
|
||||
'rgba(0, 99, 132, 0.2)',
|
||||
'rgba(0, 162, 235, 0.2)',
|
||||
'rgba(0, 206, 86, 0.2)',
|
||||
'rgba(0, 192, 192, 0.2)',
|
||||
'rgba(0, 102, 255, 0.2)',
|
||||
'rgba(0, 159, 64, 0.2)',
|
||||
],
|
||||
backgroundColor: (context) => {
|
||||
const chart = context.chart
|
||||
const { ctx, chartArea } = chart
|
||||
|
||||
if (!chartArea) {
|
||||
// This case happens on initial chart load
|
||||
return null
|
||||
}
|
||||
|
||||
const gradient = ctx.createLinearGradient(0, chartArea.bottom, 0, chartArea.top)
|
||||
gradient.addColorStop(0, '#4FC3F7') // Light blue at bottom
|
||||
gradient.addColorStop(0.3, '#2FA8E0') // Original blue
|
||||
gradient.addColorStop(0.7, '#1976D2') // Medium blue
|
||||
gradient.addColorStop(1, '#0D47A1') // Dark blue at top
|
||||
|
||||
|
||||
return gradient
|
||||
},
|
||||
borderColor: '#2FA8E0' ,
|
||||
borderWidth: 1,
|
||||
},
|
||||
],
|
||||
|
||||
@ -411,6 +411,35 @@ export function useMovementSetting(id) {
|
||||
|
||||
targetBaseLines.sort((a, b) => a.distance - b.distance)
|
||||
targetBaseLines = targetBaseLines.filter((line) => line.distance === targetBaseLines[0].distance)
|
||||
|
||||
if (isGableRoof) {
|
||||
const zeroLengthLines = targetBaseLines.filter(
|
||||
(line) => Math.sqrt(Math.pow(line.line.x2 - line.line.x1, 2) + Math.pow(line.line.y2 - line.line.y1, 2)) < 1,
|
||||
)
|
||||
if (zeroLengthLines.length > 0) {
|
||||
zeroLengthLines.forEach((line) => {
|
||||
const findLine = line.line
|
||||
const findCoords = [
|
||||
{ x: findLine.x1, y: findLine.y1 },
|
||||
{ x: findLine.x2, y: findLine.y2 },
|
||||
]
|
||||
wall.baseLines
|
||||
.filter((baseLine) => {
|
||||
return findCoords.some(
|
||||
(coord) =>
|
||||
(Math.abs(coord.x - baseLine.x1) < 0.1 && Math.abs(coord.y - baseLine.y1) < 0.1) ||
|
||||
(Math.abs(coord.x - baseLine.x2) < 0.1 && Math.abs(coord.y - baseLine.y2) < 0.1),
|
||||
)
|
||||
})
|
||||
.forEach((baseLine) => {
|
||||
const isAlready = targetBaseLines.find((target) => target.line === baseLine)
|
||||
if (isAlready) return
|
||||
targetBaseLines.push({ line: baseLine, distance: targetBaseLines[0].distance })
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
let value
|
||||
if (typeRef.current === TYPE.FLOW_LINE) {
|
||||
value =
|
||||
@ -445,58 +474,56 @@ export function useMovementSetting(id) {
|
||||
}
|
||||
}
|
||||
value = value.div(10)
|
||||
targetBaseLines.forEach((target) => {
|
||||
const currentLine = target.line
|
||||
const index = baseLines.findIndex((line) => line === currentLine)
|
||||
const nextLine = baseLines[(index + 1) % baseLines.length]
|
||||
const prevLine = baseLines[(index - 1 + baseLines.length) % baseLines.length]
|
||||
let deltaX = 0
|
||||
let deltaY = 0
|
||||
if (currentLine.y1 === currentLine.y2) {
|
||||
deltaY = value.toNumber()
|
||||
} else {
|
||||
deltaX = value.toNumber()
|
||||
}
|
||||
targetBaseLines
|
||||
.filter((line) => Math.sqrt(Math.pow(line.line.x2 - line.line.x1, 2) + Math.pow(line.line.y2 - line.line.y1, 2)) >= 1)
|
||||
.forEach((target) => {
|
||||
const currentLine = target.line
|
||||
const index = baseLines.findIndex((line) => line === currentLine)
|
||||
const nextLine = baseLines[(index + 1) % baseLines.length]
|
||||
const prevLine = baseLines[(index - 1 + baseLines.length) % baseLines.length]
|
||||
let deltaX = 0
|
||||
let deltaY = 0
|
||||
if (currentLine.y1 === currentLine.y2) {
|
||||
deltaY = value.toNumber()
|
||||
} else {
|
||||
deltaX = value.toNumber()
|
||||
}
|
||||
|
||||
currentLine.set({
|
||||
x1: currentLine.x1 + deltaX,
|
||||
y1: currentLine.y1 + deltaY,
|
||||
x2: currentLine.x2 + deltaX,
|
||||
y2: currentLine.y2 + deltaY,
|
||||
startPoint: { x: currentLine.x1 + deltaX, y: currentLine.y1 + deltaY },
|
||||
endPoint: { x: currentLine.x2 + deltaX, y: currentLine.y2 + deltaY },
|
||||
})
|
||||
const currentSize = calcLinePlaneSize({
|
||||
x1: currentLine.x1,
|
||||
y1: currentLine.y1,
|
||||
x2: currentLine.x2,
|
||||
y2: currentLine.y2,
|
||||
})
|
||||
currentLine.attributes.planeSize = currentSize
|
||||
currentLine.attributes.actualSize = currentSize
|
||||
currentLine.set({
|
||||
x1: currentLine.x1 + deltaX,
|
||||
y1: currentLine.y1 + deltaY,
|
||||
x2: currentLine.x2 + deltaX,
|
||||
y2: currentLine.y2 + deltaY,
|
||||
startPoint: { x: currentLine.x1 + deltaX, y: currentLine.y1 + deltaY },
|
||||
endPoint: { x: currentLine.x2 + deltaX, y: currentLine.y2 + deltaY },
|
||||
})
|
||||
const currentSize = calcLinePlaneSize({
|
||||
x1: currentLine.x1,
|
||||
y1: currentLine.y1,
|
||||
x2: currentLine.x2,
|
||||
y2: currentLine.y2,
|
||||
})
|
||||
currentLine.attributes.planeSize = currentSize
|
||||
currentLine.attributes.actualSize = currentSize
|
||||
|
||||
const nextOldActualSize = nextLine.attributes.planeSize
|
||||
nextLine.set({
|
||||
x1: nextLine.x1 + deltaX,
|
||||
y1: nextLine.y1 + deltaY,
|
||||
startPoint: { x: nextLine.x1 + deltaX, y: nextLine.y1 + deltaY },
|
||||
})
|
||||
const nextSize = calcLinePlaneSize({ x1: nextLine.x1, y1: nextLine.y1, x2: nextLine.x2, y2: nextLine.y2 })
|
||||
nextLine.attributes.planeSize = nextSize
|
||||
nextLine.attributes.actualSize = nextSize
|
||||
nextLine.set({
|
||||
x1: currentLine.x2,
|
||||
y1: currentLine.y2,
|
||||
startPoint: { x: currentLine.x2, y: currentLine.y2 },
|
||||
})
|
||||
const nextSize = calcLinePlaneSize({ x1: nextLine.x1, y1: nextLine.y1, x2: nextLine.x2, y2: nextLine.y2 })
|
||||
nextLine.attributes.planeSize = nextSize
|
||||
nextLine.attributes.actualSize = nextSize
|
||||
|
||||
const prevOldActualSize = prevLine.attributes.planeSize
|
||||
prevLine.set({
|
||||
x2: prevLine.x2 + deltaX,
|
||||
y2: prevLine.y2 + deltaY,
|
||||
endPoint: { x: prevLine.x2 + deltaX, y: prevLine.y2 + deltaY },
|
||||
prevLine.set({
|
||||
x2: currentLine.x1,
|
||||
y2: currentLine.y1,
|
||||
endPoint: { x: currentLine.x1, y: currentLine.y1 },
|
||||
})
|
||||
const prevSize = calcLinePlaneSize({ x1: prevLine.x1, y1: prevLine.y1, x2: prevLine.x2, y2: prevLine.y2 })
|
||||
prevLine.attributes.planeSize = prevSize
|
||||
prevLine.attributes.actualSize = prevSize
|
||||
})
|
||||
const prevSize = calcLinePlaneSize({ x1: prevLine.x1, y1: prevLine.y1, x2: prevLine.x2, y2: prevLine.y2 })
|
||||
prevLine.attributes.planeSize = prevSize
|
||||
prevLine.attributes.actualSize = prevSize
|
||||
|
||||
canvas.renderAll()
|
||||
})
|
||||
|
||||
roof.drawHelpLine()
|
||||
initEvent()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user