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

69 lines
2 KiB
JavaScript
Raw Normal View History

2023-04-21 03:48:37 +00:00
// Export defs
export const pleatDefs = [
{
name: 'notch',
def: `
2023-02-16 23:57:44 +00:00
<marker id="pleatTo" markerWidth="12" markerHeight="8" orient="auto" refY="4" refX="12">
<path class="note fill-note" d="M 12,4 L 0,0 C 2,2 2,6 0,8 z" />
</marker>
2023-04-21 03:48:37 +00:00
`,
},
]
// Export macros
export const pleatMacros = {
pleat: function (so, { points, paths, Path, complete, scale }) {
if (so === false) {
delete points.pleatFrom
delete points.pleatFromIn
delete points.pleatTo
delete points.pleatToIn
delete paths.pleatTo
delete paths.pleatFrom
delete paths.pleatArrow
return true
}
so = {
margin: 35,
prefix: 'pleat',
reverse: false,
...so,
}
if (complete) {
points[so.prefix + 'From'] = so.from
points[so.prefix + 'To'] = so.to
points[so.prefix + 'FromIn'] = points[so.prefix + 'From'].shift(
so.from.shiftTowards(so.to, 0.1).angle(so.from) + 270,
so.margin * scale
)
points[so.prefix + 'ToIn'] = points[so.prefix + 'To'].shift(
so.from.shiftTowards(so.to, 0.1).angle(so.to) + 90,
so.margin * scale
)
paths[so.prefix + 'PleatFrom'] = new Path()
.move(points[so.prefix + 'From'])
.line(points[so.prefix + 'FromIn'])
.attr('class', 'note' + (so.reverse ? ' dashed' : ''))
paths[so.prefix + 'PleatTo'] = new Path()
.move(points[so.prefix + 'To'])
.line(points[so.prefix + 'ToIn'])
.attr('class', 'note' + (so.reverse ? '' : ' dashed'))
paths[so.prefix + 'PleatArrow'] = new Path()
.move(
points[so.prefix + (so.reverse ? 'To' : 'From')].shiftFractionTowards(
points[so.prefix + (so.reverse ? 'ToIn' : 'FromIn')],
0.25
2023-02-16 23:57:44 +00:00
)
)
.line(
points[so.prefix + (so.reverse ? 'From' : 'To')].shiftFractionTowards(
points[so.prefix + (so.reverse ? 'FromIn' : 'ToIn')],
0.25
2023-02-16 23:57:44 +00:00
)
)
.attr('class', 'note')
.attr('marker-end', 'url(#pleatTo)')
}
2023-02-16 23:57:44 +00:00
},
}