2022-09-09 12:13:52 -05:00
|
|
|
import { name, version } from '../data.mjs'
|
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: {
|
2021-01-31 09:22:15 +01:00
|
|
|
round: function (so) {
|
2019-08-03 15:03:33 +02:00
|
|
|
const C = 0.55191502449
|
2022-09-27 23:59:52 +02:00
|
|
|
const { hide = true } = so
|
2018-12-21 16:57:10 +01:00
|
|
|
// Find angle between points
|
2019-08-03 15:03:33 +02:00
|
|
|
let from = so.from
|
|
|
|
let to = so.to
|
|
|
|
let via = so.via
|
|
|
|
let radius = so.radius
|
2023-01-12 10:21:42 -06:00
|
|
|
let prefix = so.prefix || 'round'
|
2023-09-08 11:59:18 +02:00
|
|
|
//let angle1 = from.angle(via)
|
|
|
|
//let angle2 = via.angle(to)
|
2023-09-08 11:29:33 +02:00
|
|
|
//if ((Math.round(angle1) - Math.round(angle2)) % 90 !== 0)
|
|
|
|
// console.log('Warning: The round macro only handles 90 degree angles correctly.')
|
2019-08-03 15:03:33 +02:00
|
|
|
let fd = from.dist(via)
|
|
|
|
let td = to.dist(via)
|
|
|
|
if (radius > fd || radius > td || typeof radius === 'undefined') radius = fd > td ? td : fd
|
|
|
|
this.points[prefix + 'Start'] = via.shiftTowards(from, radius)
|
|
|
|
this.points[prefix + 'Cp1'] = via.shiftTowards(from, radius * (1 - C))
|
|
|
|
this.points[prefix + 'Cp2'] = via.shiftTowards(to, radius * (1 - C))
|
|
|
|
this.points[prefix + 'End'] = via.shiftTowards(to, radius)
|
|
|
|
this.paths[prefix + 'Rounded'] = new this.Path()
|
|
|
|
.move(this.points[prefix + 'Start'])
|
2018-12-21 16:57:10 +01:00
|
|
|
.curve(
|
2019-08-03 15:03:33 +02:00
|
|
|
this.points[prefix + 'Cp1'],
|
|
|
|
this.points[prefix + 'Cp2'],
|
|
|
|
this.points[prefix + 'End']
|
2018-12-21 16:57:10 +01:00
|
|
|
)
|
2019-08-03 15:03:33 +02:00
|
|
|
.attr('class', so.class ? so.class : '')
|
2022-09-27 23:59:52 +02:00
|
|
|
if (hide) this.paths[prefix + 'Rounded'].hide()
|
2022-09-18 17:01:19 +02:00
|
|
|
else this.paths[prefix + 'Rounded'].unhide()
|
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
|