1
0
Fork 0

chore(plugin-grainline): Changes for v3. See #2856

This commit is contained in:
Joost De Cock 2022-09-27 11:42:54 +02:00
parent b851e69ec8
commit 88e5339b37
2 changed files with 12 additions and 10 deletions

View file

@ -19,19 +19,18 @@ export const plugin = {
},
},
macros: {
grainline: function (so = {}) {
grainline: function (so = {}, { points, paths, Path, complete, setGrain }) {
if (so === false) {
delete this.points.grainlineFrom
delete this.points.grainlineTo
delete this.paths.grainline
this.setGrain(90) // Restoring default
delete points.grainlineFrom
delete points.grainlineTo
delete paths.grainline
setGrain(90) // Restoring default
return true
}
so = {
...dflts,
...so,
}
const { points, complete, setGrain } = this.shorthand()
// setGrain relies on plugin-cutlist
if (typeof setGrain === 'function') {
setGrain(so.from.angle(so.to))
@ -39,7 +38,7 @@ export const plugin = {
if (complete) {
points.grainlineFrom = so.from.shiftFractionTowards(so.to, 0.05)
points.grainlineTo = so.to.shiftFractionTowards(so.from, 0.05)
this.paths.grainline = new this.Path()
paths.grainline = new Path()
.move(points.grainlineFrom)
.line(points.grainlineTo)
.attr('class', 'note')

View file

@ -8,19 +8,22 @@ describe('Grainline Plugin Tests', () => {
it('Should run the default grainline macro', () => {
const part = {
name: 'test',
draft: ({ points, Point, macro }) => {
draft: ({ points, Point, macro, part }) => {
points.from = new Point(10, 20)
points.to = new Point(10, 230)
macro('grainline', {
from: points.from,
to: points.to,
})
return part
},
plugins: [plugin],
}
const Pattern = new Design({ plugins: [plugin], parts: [part] })
const Pattern = new Design({ parts: [part] })
const pattern = new Pattern()
pattern.draft()
const c = pattern.parts.test.paths.grainline
const c = pattern.parts[0].test.paths.grainline
expect(c.attributes.get('class')).to.equal('note')
expect(c.attributes.get('marker-start')).to.equal('url(#grainlineFrom)')
expect(c.attributes.get('marker-end')).to.equal('url(#grainlineTo)')