From 7d02c76bc806b1a9a59bf5bad09681d8d28b3579 Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Sat, 22 Feb 2020 14:18:13 +0100 Subject: [PATCH] refactor(holmes): Using gore-plugin package, rather than local code --- packages/holmes/src/index.js | 11 +++--- packages/holmes/src/plugin-gore.js | 63 ------------------------------ 2 files changed, 6 insertions(+), 68 deletions(-) delete mode 100644 packages/holmes/src/plugin-gore.js diff --git a/packages/holmes/src/index.js b/packages/holmes/src/index.js index c1610596cd7..398a186276d 100644 --- a/packages/holmes/src/index.js +++ b/packages/holmes/src/index.js @@ -1,17 +1,18 @@ import freesewing from '@freesewing/core' import plugins from '@freesewing/plugin-bundle' -import gore from './plugin-gore' +import gorePlugin from '@freesewing/plugin-gore' import config from '../config' + import draftGore from './gore' import draftBrim from './brim' import draftEar from './ear' // Create new design -const Pattern = new freesewing.Design(config, [plugins,gore]) +const Pattern = new freesewing.Design(config, [plugins, gorePlugin]) // Attach the draft methods to the prototype -Pattern.prototype.draftGore = draftGore -Pattern.prototype.draftBrim = draftBrim -Pattern.prototype.draftEar = draftEar +Pattern.prototype.draftGore = draftGore +Pattern.prototype.draftBrim = draftBrim +Pattern.prototype.draftEar = draftEar export default Pattern diff --git a/packages/holmes/src/plugin-gore.js b/packages/holmes/src/plugin-gore.js deleted file mode 100644 index 1b0396709d2..00000000000 --- a/packages/holmes/src/plugin-gore.js +++ /dev/null @@ -1,63 +0,0 @@ -import { name, version } from '../package.json' - -export default { - name: name, - version: version, - hooks: { - preRender: function(svg) { - if (svg.attributes.get('freesewing:plugin-gore') === false) - svg.attributes.set('freesewing:plugin-gore', version) - } - }, - macros: { - gore: function(so) { - let from = so.from - let goreNumber = so.goreNumber //number of gores for the complete sphere - let radius = so.radius //radius of the sphere - let prefix = so.prefix - let extraLength = so.extraLength //the length of the straight section after a complete semisphere - - this.points[prefix + 'p1'] = from.shift(0, radius*Math.PI/2 + extraLength) - this.points[prefix + 'Cp1'] = this.points[prefix + 'p1'].shift(180-180/goreNumber, radius/2/Math.cos(Math.PI/goreNumber)) - this.points[prefix + 'p3'] = from.shift(90, radius*Math.PI/goreNumber) - this.points[prefix + 'p2'] = this.points[prefix + 'p3'].shift(0, extraLength) - this.points[prefix + 'Cp2'] = this.points[prefix + 'p2'].shift(0, radius*(Math.PI-2)/2) - - if (extraLength < 0){ - //top curve used to calculate the new points if extraLength < 0 - this.paths.auxiliaryPath = new this.Path() - .move(this.points[prefix + "p1"]) - .curve( - this.points[prefix + 'Cp1'], - this.points[prefix + 'Cp2'], - this.points[prefix + 'p2'] - ) - .setRender(false) - - this.points[prefix + 'p2'] = this.paths.auxiliaryPath.intersectsX(0)[0] //the new point p2 is the one in which the auxiliary curve intersects x=0 - this.paths.auxiliaryPath = this.paths.auxiliaryPath.split(this.points[prefix + 'p2'])[0] //the auxiliary curve is split - this.points[prefix + 'Cp1'] = this.paths.auxiliaryPath.ops[1].cp1 //the new control points are those of the new curve - this.points[prefix + 'Cp2'] = this.paths.auxiliaryPath.ops[1].cp2 - this.points[prefix + 'p3'] = this.points[prefix + 'p2'].clone() - } - - //the seam path is generated - this.paths[prefix + 'seam'] = new this.Path() - .move(from) - .line(this.points[prefix + 'p1']) - .curve( - this.points[prefix + 'Cp1'], - this.points[prefix + 'Cp2'], - this.points[prefix + 'p2'] - ) - .line(this.points[prefix + "p3"]) - .line(from) - .close() - .attr('class', so.class ? so.class : '') - - if (typeof so.render !== 'undefined' && so.render) - this.paths[prefix + 'seam'].render = true - else this.paths[prefix + 'seam'].render = false - } - } -}