1
0
Fork 0
freesewing/plugins/plugin-round/src/index.mjs

61 lines
1.7 KiB
JavaScript
Raw Normal View History

import { name, version } from '../data.mjs'
2023-09-28 13:26:32 +02:00
import { getIds } from './utils.mjs'
/*
* These are the keys for macro IDs
*/
const pointKeys = ['start', 'cp1', 'cp2', 'end']
const pathKeys = ['path']
2018-12-21 16:57:10 +01:00
2022-08-28 13:38:49 +02:00
export const plugin = {
name,
version,
2018-12-21 16:57:10 +01:00
macros: {
2023-09-28 13:26:32 +02:00
round: function (mc, { points, paths, Point, Path, store, part }) {
2019-08-03 15:03:33 +02:00
const C = 0.55191502449
2023-09-28 13:26:32 +02:00
const {
from = new Point(0, 0),
to = new Point(666, 666),
via = new Point(666, 0),
id = 'round',
classes = '',
hide = true,
} = mc
let { radius = 66.6 } = mc
const ids = getIds([...pointKeys, ...pathKeys], id, name)
const fd = from.dist(via)
const td = to.dist(via)
2023-09-28 15:58:50 +02:00
if (radius > fd || radius > td) radius = fd > td ? td : fd
2023-09-28 13:26:32 +02:00
points[ids.start] = via.shiftTowards(from, radius)
points[ids.cp1] = via.shiftTowards(from, radius * (1 - C))
points[ids.cp2] = via.shiftTowards(to, radius * (1 - C))
points[ids.end] = via.shiftTowards(to, radius)
paths[ids.path] = new Path()
.move(this.points[ids.start])
.curve(points[ids.cp1], points[ids.cp2], points[ids.end])
.addClass(classes)
if (hide) paths[ids.path].hide()
else paths[ids.path].unhide()
/*
* Store all IDs in the store so we can remove this macro with rmtitle
*/
store.set(
['parts', part.name, 'macros', 'round', 'ids', mc.id, 'points'],
getIds(pointKeys, id, name)
)
store.set(
['parts', part.name, 'macros', 'round', 'ids', mc.id, 'paths'],
getIds(pathKeys, id, name)
)
return store.getMacroIds(id, 'round')
2021-04-24 10:16:31 +02:00
},
},
2019-08-03 15:03:33 +02:00
}
2022-08-28 13:38:49 +02:00
// More specifically named exports
export const roundPlugin = plugin
export const pluginRound = plugin