1
0
Fork 0
freesewing/plugins/plugin-annotations/src/crossbox.mjs

54 lines
1.9 KiB
JavaScript
Raw Normal View History

// Export macros
export const crossboxMacros = {
crossbox: function (so, { points, Point, paths, Path, getId }) {
let id = getId()
let shiftFraction = 0.1
points[id + '_boxTopLeft'] = so.from.copy()
points[id + '_boxBottomRight'] = so.to.copy()
points[id + '_boxTopRight'] = new Point(so.to.x, so.from.y)
points[id + '_boxBottomLeft'] = new Point(so.from.x, so.to.y)
2023-02-16 23:57:44 +00:00
points[id + '_topCrossTL'] = points[id + '_boxTopLeft'].shiftFractionTowards(
points[id + '_boxBottomRight'],
shiftFraction
)
points[id + '_topCrossTR'] = points[id + '_boxTopRight'].shiftFractionTowards(
points[id + '_boxBottomLeft'],
shiftFraction
)
points[id + '_topCrossBL'] = points[id + '_boxBottomLeft'].shiftFractionTowards(
points[id + '_boxTopRight'],
shiftFraction
)
points[id + '_topCrossBR'] = points[id + '_boxBottomRight'].shiftFractionTowards(
points[id + '_boxTopLeft'],
shiftFraction
)
2023-02-16 23:57:44 +00:00
paths[id + 'crossBox'] = new Path()
.move(points[id + '_boxTopLeft'])
.line(points[id + '_boxTopRight'])
.line(points[id + '_boxBottomRight'])
.line(points[id + '_boxBottomLeft'])
.line(points[id + '_boxTopLeft'])
.close()
.attr('class', 'lining dotted stroke-sm')
paths[id + '_topCross'] = new Path()
.move(points[id + '_topCrossTL'])
.line(points[id + '_topCrossBR'])
.line(points[id + '_topCrossTR'])
.line(points[id + '_topCrossBL'])
.line(points[id + '_topCrossTL'])
.line(points[id + '_topCrossTR'])
.move(points[id + '_topCrossBR'])
.line(points[id + '_topCrossBL'])
.attr('class', 'lining dotted stroke-sm')
if (typeof so.text === 'string') {
points.textAnchor = points[id + '_boxTopLeft']
.shiftFractionTowards(points[id + '_boxBottomRight'], 0.5)
.attr('data-text', so.text)
.attr('data-text-class', 'center')
}
2023-02-16 23:57:44 +00:00
},
}