refactor: Remove unnecessary code for handling outer line template B
This commit is contained in:
parent
ff19fe7389
commit
71ecdfd40a
@ -1319,197 +1319,6 @@ export function useMode() {
|
|||||||
canvas.renderAll()
|
canvas.renderAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleOuterLineTemplateB = (params) => {
|
|
||||||
const { eaves, edge, polygon } = params
|
|
||||||
polygon.points.forEach((point, index) => {
|
|
||||||
let x2 = index === polygon.points.length - 1 ? polygon.points[0].x : polygon.points[index + 1].x
|
|
||||||
let y2 = index === polygon.points.length - 1 ? polygon.points[0].y : polygon.points[index + 1].y
|
|
||||||
|
|
||||||
let x1 = point.x
|
|
||||||
let y1 = point.y
|
|
||||||
if (index % 2 === 0) {
|
|
||||||
if (polygon.lines[index].direction === 'bottom') {
|
|
||||||
y1 = y1 - eaves
|
|
||||||
y2 = y2 + eaves
|
|
||||||
x1 = x1 - edge
|
|
||||||
x2 = x2 - edge
|
|
||||||
} else {
|
|
||||||
y1 = y1 + eaves
|
|
||||||
y2 = y2 - eaves
|
|
||||||
x1 = x1 + edge
|
|
||||||
x2 = x2 + edge
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (polygon.lines[index].direction === 'right') {
|
|
||||||
x1 = x1 - edge
|
|
||||||
x2 = x2 + edge
|
|
||||||
y1 = y1 + eaves
|
|
||||||
y2 = y2 + eaves
|
|
||||||
} else {
|
|
||||||
x1 = x1 + edge
|
|
||||||
x2 = x2 - edge
|
|
||||||
y1 = y1 - eaves
|
|
||||||
y2 = y2 - eaves
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (polygon.shape) {
|
|
||||||
case 1:
|
|
||||||
if (index === 0) {
|
|
||||||
const subLine = new QLine(
|
|
||||||
[
|
|
||||||
point.x - edge,
|
|
||||||
polygon.points[0].y + (polygon.points[1].y - polygon.points[0].y) / 2,
|
|
||||||
polygon.points[2].x,
|
|
||||||
polygon.points[0].y + (polygon.points[1].y - polygon.points[0].y) / 2,
|
|
||||||
],
|
|
||||||
{
|
|
||||||
stroke: 'blue',
|
|
||||||
strokeWidth: 2,
|
|
||||||
selectable: false,
|
|
||||||
fontSize: fontSize,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
canvas.add(subLine)
|
|
||||||
}
|
|
||||||
if (index === 1) {
|
|
||||||
x2 = x2 - edge
|
|
||||||
const subLine = new QLine([x2, y2, x2, polygon.points[0].y + (polygon.points[1].y - polygon.points[0].y) / 2], {
|
|
||||||
stroke: 'blue',
|
|
||||||
strokeWidth: 2,
|
|
||||||
selectable: false,
|
|
||||||
fontSize: fontSize,
|
|
||||||
})
|
|
||||||
canvas.add(subLine)
|
|
||||||
}
|
|
||||||
if (index === 2) {
|
|
||||||
y1 = point.y - (polygon.points[1].y - polygon.points[0].y) / 2
|
|
||||||
const centeredPoint = getCenterPoint(polygon.points[1].x, point.x)
|
|
||||||
const subLine = new QLine(
|
|
||||||
[centeredPoint, point.y + eaves, centeredPoint, polygon.points[0].y + (polygon.points[1].y - polygon.points[0].y) / 2],
|
|
||||||
{
|
|
||||||
stroke: 'black',
|
|
||||||
strokeWidth: 2,
|
|
||||||
strokeDashArray: [5, 5],
|
|
||||||
selectable: false,
|
|
||||||
fontSize: fontSize,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
canvas.add(subLine)
|
|
||||||
}
|
|
||||||
if (index === 3) {
|
|
||||||
const centeredPoint = getCenterPoint(point.x, polygon.points[4].x)
|
|
||||||
const subLine = new QLine([centeredPoint, point.y + eaves, centeredPoint, polygon.points[5].y - eaves], {
|
|
||||||
stroke: 'black',
|
|
||||||
strokeWidth: 2,
|
|
||||||
strokeDashArray: [5, 5],
|
|
||||||
selectable: false,
|
|
||||||
fontSize: fontSize,
|
|
||||||
})
|
|
||||||
canvas.add(subLine)
|
|
||||||
}
|
|
||||||
if (index === 5) {
|
|
||||||
const centeredPoint = getCenterPoint(point.y, polygon.points[4].y)
|
|
||||||
const subLine = new QLine([point.x + edge, centeredPoint, polygon.points[2].x - edge, centeredPoint], {
|
|
||||||
stroke: 'blue',
|
|
||||||
strokeWidth: 2,
|
|
||||||
selectable: false,
|
|
||||||
fontSize: fontSize,
|
|
||||||
})
|
|
||||||
canvas.add(subLine)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 2:
|
|
||||||
const centerPoint = polygon.points[3].y + (polygon.points[2].y - polygon.points[3].y) / 2
|
|
||||||
if (index === 0) {
|
|
||||||
const subLine = new QLine(
|
|
||||||
[
|
|
||||||
point.x - egde,
|
|
||||||
polygon.points[0].y + (polygon.points[1].y - polygon.points[0].y) / 2,
|
|
||||||
polygon.points[5].x + egde,
|
|
||||||
polygon.points[0].y + (polygon.points[1].y - polygon.points[0].y) / 2,
|
|
||||||
],
|
|
||||||
{
|
|
||||||
stroke: 'blue',
|
|
||||||
strokeWidth: 2,
|
|
||||||
selectable: false,
|
|
||||||
fontSize: fontSize,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
canvas.add(subLine)
|
|
||||||
}
|
|
||||||
if (index === 3) {
|
|
||||||
x2 = x2 + egde
|
|
||||||
|
|
||||||
const subLine = new QLine([x2, y2, x2, centerPoint], {
|
|
||||||
stroke: 'blue',
|
|
||||||
strokeWidth: 2,
|
|
||||||
selectable: false,
|
|
||||||
fontSize: fontSize,
|
|
||||||
})
|
|
||||||
canvas.add(subLine)
|
|
||||||
}
|
|
||||||
if (index === 4) {
|
|
||||||
y1 = point.y + (polygon.points[index - 2].y - polygon.points[index - 1].y) / 2
|
|
||||||
|
|
||||||
const subLine = new QLine([point.x, centerPoint, polygon.points[2].x + 20, centerPoint], {
|
|
||||||
stroke: 'blue',
|
|
||||||
strokeWidth: 2,
|
|
||||||
selectable: false,
|
|
||||||
fontSize: fontSize,
|
|
||||||
})
|
|
||||||
|
|
||||||
const subVerticalLine = new QLine(
|
|
||||||
[
|
|
||||||
getCenterPoint(point.x, polygon.points[2].x + egde),
|
|
||||||
polygon.points[3].y - eaves,
|
|
||||||
getCenterPoint(point.x, polygon.points[2].x + egde),
|
|
||||||
centerPoint,
|
|
||||||
],
|
|
||||||
{
|
|
||||||
stroke: 'black',
|
|
||||||
strokeWidth: 2,
|
|
||||||
strokeDashArray: [5, 5],
|
|
||||||
selectable: false,
|
|
||||||
fontSize: fontSize,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
canvas.add(subVerticalLine)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index === 5) {
|
|
||||||
const centeredPoint = getCenterPoint(polygon.points[0].x, polygon.points[5].x)
|
|
||||||
const verticalSubLine = new QLine([centeredPoint, polygon.points[0].y - eaves, centeredPoint, polygon.points[1].y + eaves], {
|
|
||||||
stroke: 'black',
|
|
||||||
strokeWidth: 2,
|
|
||||||
strokeDashArray: [5, 5],
|
|
||||||
selectable: false,
|
|
||||||
fontSize: fontSize,
|
|
||||||
})
|
|
||||||
|
|
||||||
canvas.add(verticalSubLine)
|
|
||||||
}
|
|
||||||
|
|
||||||
break
|
|
||||||
case 3:
|
|
||||||
break
|
|
||||||
case 4:
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
const line = new QLine([x1, y1, x2, y2], {
|
|
||||||
stroke: 'blue',
|
|
||||||
strokeWidth: 2,
|
|
||||||
selectable: false,
|
|
||||||
fontSize: fontSize,
|
|
||||||
})
|
|
||||||
canvas.add(line)
|
|
||||||
})
|
|
||||||
canvas.renderAll()
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
mode,
|
mode,
|
||||||
changeMode,
|
changeMode,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user