1
0
Fork 0

refactor(holmes): Using gore-plugin package, rather than local code

This commit is contained in:
Joost De Cock 2020-02-22 14:18:13 +01:00
parent d1419cf6c8
commit 7d02c76bc8
2 changed files with 6 additions and 68 deletions

View file

@ -1,13 +1,14 @@
import freesewing from '@freesewing/core' import freesewing from '@freesewing/core'
import plugins from '@freesewing/plugin-bundle' import plugins from '@freesewing/plugin-bundle'
import gore from './plugin-gore' import gorePlugin from '@freesewing/plugin-gore'
import config from '../config' import config from '../config'
import draftGore from './gore' import draftGore from './gore'
import draftBrim from './brim' import draftBrim from './brim'
import draftEar from './ear' import draftEar from './ear'
// Create new design // 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 // Attach the draft methods to the prototype
Pattern.prototype.draftGore = draftGore Pattern.prototype.draftGore = draftGore

View file

@ -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
}
}
}