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,
version,
macros: {
gore: function (so) {
gore: function (so, { points, paths, Path }) {
const from = so.from
const gores = so.gores
const radius = so.radius //radius of the sphere
const prefix = so.prefix
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)
this.points[prefix + 'Cp1'] = this.points[prefix + 'p1'].shift(
points[prefix + 'p1'] = from.shift(0, (radius * Math.PI) / 2 + extraLength)
points[prefix + 'Cp1'] = points[prefix + 'p1'].shift(
180 - 180 / gores,
radius / 2 / Math.cos(Math.PI / gores)
)
this.points[prefix + 'p3'] = from.shift(90, (radius * Math.PI) / gores)
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
)
points[prefix + 'p3'] = from.shift(90, (radius * Math.PI) / gores)
points[prefix + 'p2'] = points[prefix + 'p3'].shift(0, extraLength)
points[prefix + 'Cp2'] = 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']
)
paths.auxiliaryPath = new Path()
.move(points[prefix + 'p1'])
.curve(points[prefix + 'Cp1'], points[prefix + 'Cp2'], points[prefix + 'p2'])
.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
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()
points[prefix + 'p2'] = paths.auxiliaryPath.intersectsX(0)[0] //the new point p2 is the one in which the auxiliary curve intersects x=0
paths.auxiliaryPath = paths.auxiliaryPath.split(points[prefix + 'p2'])[0] //the auxiliary curve is split
points[prefix + 'Cp1'] = paths.auxiliaryPath.ops[1].cp1 //the new control points are those of the new curve
points[prefix + 'Cp2'] = paths.auxiliaryPath.ops[1].cp2
points[prefix + 'p3'] = points[prefix + 'p2'].clone()
}
//the seam path is generated
this.paths[prefix + 'seam'] = new this.Path()
paths[prefix + 'seam'] = new 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(points[prefix + 'p1'])
.curve(points[prefix + 'Cp1'], points[prefix + 'Cp2'], points[prefix + 'p2'])
.line(points[prefix + 'p3'])
.line(from)
.close()
.attr('class', so.class ? so.class : '')
if (so?.hidden) this.paths[prefix + 'seam'].hide()
else this.paths[prefix + 'seam'].unhide()
if (so?.hidden) paths[prefix + 'seam'].hide()
else paths[prefix + 'seam'].unhide()
},
},
}

View file

@ -8,7 +8,7 @@ describe('Gore Plugin Tests', () => {
it('Should create a default gore', () => {
const part = {
name: 'test',
draft: ({ Point, points, macro }) => {
draft: ({ Point, points, macro, part }) => {
points.anchorPoint = new Point(50, 50)
macro('gore', {
from: points.anchorPoint,
@ -17,12 +17,15 @@ describe('Gore Plugin Tests', () => {
extraLength: 0,
prefix: 'gore',
})
return part
},
plugins: [plugin],
}
const Test = new Design({ plugins: [plugin], parts: [part] })
const Test = new Design({ parts: [part] })
const pattern = new Test()
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.gorep2.x)).to.equal(50)
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', () => {
const part = {
name: 'test',
draft: ({ Point, points, macro }) => {
draft: ({ Point, points, macro, part }) => {
points.anchorPoint = new Point(50, 50)
macro('gore', {
from: points.anchorPoint,
@ -42,12 +45,15 @@ describe('Gore Plugin Tests', () => {
extraLength: 0,
prefix: 'gore',
})
return part
},
plugins: [plugin],
}
const Test = new Design({ plugins: [plugin], parts: [part] })
const Test = new Design({ parts: [part] })
const pattern = new Test()
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.y)).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', () => {
const part = {
name: 'test',
draft: ({ Point, points, macro }) => {
draft: ({ Point, points, macro, part }) => {
points.anchorPoint = new Point(50, 50)
macro('gore', {
from: points.anchorPoint,
@ -68,12 +74,15 @@ describe('Gore Plugin Tests', () => {
extraLength: 20,
prefix: 'gore',
})
return part
},
plugins: [plugin],
}
const Test = new Design({ plugins: [plugin], parts: [part] })
const Test = new Design({ parts: [part] })
const pattern = new Test()
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.y)).to.equal(50)
expect(round(c.gorep2.x)).to.equal(70)
@ -85,7 +94,7 @@ describe('Gore Plugin Tests', () => {
it('Should use a configurable radius', () => {
const part = {
name: 'test',
draft: ({ Point, points, macro }) => {
draft: ({ Point, points, macro, part }) => {
points.anchorPoint = new Point(50, 50)
macro('gore', {
from: points.anchorPoint,
@ -94,12 +103,15 @@ describe('Gore Plugin Tests', () => {
extraLength: 0,
prefix: 'gore',
})
return part
},
plugins: [plugin],
}
const Test = new Design({ plugins: [plugin], parts: [part] })
const Test = new Design({ parts: [part] })
const pattern = new Test()
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.y)).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', () => {
const part = {
name: 'test',
draft: ({ Point, points, macro }) => {
draft: ({ Point, points, macro, part }) => {
points.anchorPoint = new Point(50, 50)
macro('gore', {
from: points.anchorPoint,
@ -120,12 +132,15 @@ describe('Gore Plugin Tests', () => {
extraLength: 0,
prefix: 'gore',
})
return part
},
plugins: [plugin],
}
const Test = new Design({ plugins: [plugin], parts: [part] })
const Test = new Design({ parts: [part] })
const pattern = new Test()
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.y)).to.equal(50)
expect(round(c[2].to.x)).to.equal(50)