1
0
Fork 0

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

This commit is contained in:
Joost De Cock 2022-09-27 11:35:48 +02:00
parent ab2a86d77c
commit b851e69ec8
2 changed files with 50 additions and 42 deletions

View file

@ -4,55 +4,48 @@ export const plugin = {
name, name,
version, version,
macros: { macros: {
gore: function (so) { gore: function (so, { points, paths, Path }) {
const from = so.from const from = so.from
const gores = so.gores const gores = so.gores
const radius = so.radius //radius of the sphere const radius = so.radius //radius of the sphere
const prefix = so.prefix const prefix = so.prefix
const extraLength = so.extraLength //the length of the straight section after a complete semisphere const 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) points[prefix + 'p1'] = from.shift(0, (radius * Math.PI) / 2 + extraLength)
this.points[prefix + 'Cp1'] = this.points[prefix + 'p1'].shift( points[prefix + 'Cp1'] = points[prefix + 'p1'].shift(
180 - 180 / gores, 180 - 180 / gores,
radius / 2 / Math.cos(Math.PI / gores) radius / 2 / Math.cos(Math.PI / gores)
) )
this.points[prefix + 'p3'] = from.shift(90, (radius * Math.PI) / gores) points[prefix + 'p3'] = from.shift(90, (radius * Math.PI) / gores)
this.points[prefix + 'p2'] = this.points[prefix + 'p3'].shift(0, extraLength) points[prefix + 'p2'] = points[prefix + 'p3'].shift(0, extraLength)
this.points[prefix + 'Cp2'] = this.points[prefix + 'p2'].shift( points[prefix + 'Cp2'] = points[prefix + 'p2'].shift(0, (radius * (Math.PI - 2)) / 2)
0,
(radius * (Math.PI - 2)) / 2
)
if (extraLength < 0) { if (extraLength < 0) {
//top curve used to calculate the new points if extraLength < 0 //top curve used to calculate the new points if extraLength < 0
this.paths.auxiliaryPath = new this.Path() paths.auxiliaryPath = new Path()
.move(this.points[prefix + 'p1']) .move(points[prefix + 'p1'])
.curve( .curve(points[prefix + 'Cp1'], points[prefix + 'Cp2'], points[prefix + 'p2'])
this.points[prefix + 'Cp1'],
this.points[prefix + 'Cp2'],
this.points[prefix + 'p2']
)
.hide() .hide()
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 points[prefix + 'p2'] = 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 paths.auxiliaryPath = paths.auxiliaryPath.split(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 points[prefix + 'Cp1'] = 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 points[prefix + 'Cp2'] = paths.auxiliaryPath.ops[1].cp2
this.points[prefix + 'p3'] = this.points[prefix + 'p2'].clone() points[prefix + 'p3'] = points[prefix + 'p2'].clone()
} }
//the seam path is generated //the seam path is generated
this.paths[prefix + 'seam'] = new this.Path() paths[prefix + 'seam'] = new Path()
.move(from) .move(from)
.line(this.points[prefix + 'p1']) .line(points[prefix + 'p1'])
.curve(this.points[prefix + 'Cp1'], this.points[prefix + 'Cp2'], this.points[prefix + 'p2']) .curve(points[prefix + 'Cp1'], points[prefix + 'Cp2'], points[prefix + 'p2'])
.line(this.points[prefix + 'p3']) .line(points[prefix + 'p3'])
.line(from) .line(from)
.close() .close()
.attr('class', so.class ? so.class : '') .attr('class', so.class ? so.class : '')
if (so?.hidden) this.paths[prefix + 'seam'].hide() if (so?.hidden) paths[prefix + 'seam'].hide()
else this.paths[prefix + 'seam'].unhide() else paths[prefix + 'seam'].unhide()
}, },
}, },
} }

View file

@ -8,7 +8,7 @@ describe('Gore Plugin Tests', () => {
it('Should create a default gore', () => { it('Should create a default gore', () => {
const part = { const part = {
name: 'test', name: 'test',
draft: ({ Point, points, macro }) => { draft: ({ Point, points, macro, part }) => {
points.anchorPoint = new Point(50, 50) points.anchorPoint = new Point(50, 50)
macro('gore', { macro('gore', {
from: points.anchorPoint, from: points.anchorPoint,
@ -17,12 +17,15 @@ describe('Gore Plugin Tests', () => {
extraLength: 0, extraLength: 0,
prefix: 'gore', prefix: 'gore',
}) })
return part
}, },
plugins: [plugin],
} }
const Test = new Design({ plugins: [plugin], parts: [part] }) const Test = new Design({ parts: [part] })
const pattern = new Test() const pattern = new Test()
pattern.draft() pattern.draft()
let c = pattern.parts.test.points let c = pattern.parts[0].test.points
expect(round(c.gorep1.y)).to.equal(50) expect(round(c.gorep1.y)).to.equal(50)
expect(round(c.gorep2.x)).to.equal(50) expect(round(c.gorep2.x)).to.equal(50)
expect(round(c.gorep2.y)).to.equal(30.37) expect(round(c.gorep2.y)).to.equal(30.37)
@ -33,7 +36,7 @@ describe('Gore Plugin Tests', () => {
it('Should use a configurable number of gores', () => { it('Should use a configurable number of gores', () => {
const part = { const part = {
name: 'test', name: 'test',
draft: ({ Point, points, macro }) => { draft: ({ Point, points, macro, part }) => {
points.anchorPoint = new Point(50, 50) points.anchorPoint = new Point(50, 50)
macro('gore', { macro('gore', {
from: points.anchorPoint, from: points.anchorPoint,
@ -42,12 +45,15 @@ describe('Gore Plugin Tests', () => {
extraLength: 0, extraLength: 0,
prefix: 'gore', prefix: 'gore',
}) })
return part
}, },
plugins: [plugin],
} }
const Test = new Design({ plugins: [plugin], parts: [part] }) const Test = new Design({ parts: [part] })
const pattern = new Test() const pattern = new Test()
pattern.draft() pattern.draft()
let c = pattern.parts.test.points let c = pattern.parts[0].test.points
expect(round(c.gorep1.x)).to.equal(89.27) expect(round(c.gorep1.x)).to.equal(89.27)
expect(round(c.gorep1.y)).to.equal(50) expect(round(c.gorep1.y)).to.equal(50)
expect(round(c.gorep2.x)).to.equal(50) expect(round(c.gorep2.x)).to.equal(50)
@ -59,7 +65,7 @@ describe('Gore Plugin Tests', () => {
it('Should use a configurable extra length', () => { it('Should use a configurable extra length', () => {
const part = { const part = {
name: 'test', name: 'test',
draft: ({ Point, points, macro }) => { draft: ({ Point, points, macro, part }) => {
points.anchorPoint = new Point(50, 50) points.anchorPoint = new Point(50, 50)
macro('gore', { macro('gore', {
from: points.anchorPoint, from: points.anchorPoint,
@ -68,12 +74,15 @@ describe('Gore Plugin Tests', () => {
extraLength: 20, extraLength: 20,
prefix: 'gore', prefix: 'gore',
}) })
return part
}, },
plugins: [plugin],
} }
const Test = new Design({ plugins: [plugin], parts: [part] }) const Test = new Design({ parts: [part] })
const pattern = new Test() const pattern = new Test()
pattern.draft() pattern.draft()
let c = pattern.parts.test.points let c = pattern.parts[0].test.points
expect(round(c.gorep1.x)).to.equal(109.27) expect(round(c.gorep1.x)).to.equal(109.27)
expect(round(c.gorep1.y)).to.equal(50) expect(round(c.gorep1.y)).to.equal(50)
expect(round(c.gorep2.x)).to.equal(70) expect(round(c.gorep2.x)).to.equal(70)
@ -85,7 +94,7 @@ describe('Gore Plugin Tests', () => {
it('Should use a configurable radius', () => { it('Should use a configurable radius', () => {
const part = { const part = {
name: 'test', name: 'test',
draft: ({ Point, points, macro }) => { draft: ({ Point, points, macro, part }) => {
points.anchorPoint = new Point(50, 50) points.anchorPoint = new Point(50, 50)
macro('gore', { macro('gore', {
from: points.anchorPoint, from: points.anchorPoint,
@ -94,12 +103,15 @@ describe('Gore Plugin Tests', () => {
extraLength: 0, extraLength: 0,
prefix: 'gore', prefix: 'gore',
}) })
return part
}, },
plugins: [plugin],
} }
const Test = new Design({ plugins: [plugin], parts: [part] }) const Test = new Design({ parts: [part] })
const pattern = new Test() const pattern = new Test()
pattern.draft() pattern.draft()
let c = pattern.parts.test.points let c = pattern.parts[0].test.points
expect(round(c.gorep1.x)).to.equal(97.12) expect(round(c.gorep1.x)).to.equal(97.12)
expect(round(c.gorep1.y)).to.equal(50) expect(round(c.gorep1.y)).to.equal(50)
expect(round(c.gorep2.x)).to.equal(50) expect(round(c.gorep2.x)).to.equal(50)
@ -111,7 +123,7 @@ describe('Gore Plugin Tests', () => {
it('Should generate a seam path', () => { it('Should generate a seam path', () => {
const part = { const part = {
name: 'test', name: 'test',
draft: ({ Point, points, macro }) => { draft: ({ Point, points, macro, part }) => {
points.anchorPoint = new Point(50, 50) points.anchorPoint = new Point(50, 50)
macro('gore', { macro('gore', {
from: points.anchorPoint, from: points.anchorPoint,
@ -120,12 +132,15 @@ describe('Gore Plugin Tests', () => {
extraLength: 0, extraLength: 0,
prefix: 'gore', prefix: 'gore',
}) })
return part
}, },
plugins: [plugin],
} }
const Test = new Design({ plugins: [plugin], parts: [part] }) const Test = new Design({ parts: [part] })
const pattern = new Test() const pattern = new Test()
pattern.draft() pattern.draft()
let c = pattern.parts.test.paths.goreseam.ops let c = pattern.parts[0].test.paths.goreseam.ops
expect(round(c[1].to.x)).to.equal(89.27) expect(round(c[1].to.x)).to.equal(89.27)
expect(round(c[1].to.y)).to.equal(50) expect(round(c[1].to.y)).to.equal(50)
expect(round(c[2].to.x)).to.equal(50) expect(round(c[2].to.x)).to.equal(50)