2021-11-27 16:43:52 +01:00
|
|
|
import chai from 'chai'
|
2022-08-28 12:36:09 +02:00
|
|
|
import { round, Pattern } from '@freesewing/core'
|
|
|
|
import { plugin } from './dist/index.mjs'
|
2021-11-27 16:43:52 +01:00
|
|
|
|
2022-08-28 12:36:09 +02:00
|
|
|
const expect = chai.expect
|
2021-11-27 16:43:52 +01:00
|
|
|
|
|
|
|
describe('Gore Plugin Tests', () => {
|
2022-01-27 20:52:55 +01:00
|
|
|
it('Should create a default gore', () => {
|
2022-08-28 12:36:09 +02:00
|
|
|
let pattern = new Pattern()
|
2022-01-27 20:52:55 +01:00
|
|
|
pattern.use(plugin)
|
|
|
|
let anchorPoint = new pattern.Point(50,50)
|
|
|
|
pattern.parts.test = new pattern.Part()
|
|
|
|
let { macro } = pattern.parts.test.shorthand()
|
|
|
|
macro('gore', {
|
|
|
|
from:anchorPoint,
|
|
|
|
radius:25,
|
2022-08-24 11:59:57 +02:00
|
|
|
gores:4,
|
2022-01-27 20:52:55 +01:00
|
|
|
extraLength:0,
|
|
|
|
prefix:'gore'
|
|
|
|
})
|
|
|
|
let c = pattern.parts.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)
|
|
|
|
expect(round(c.gorep3.x)).to.equal(50)
|
|
|
|
expect(round(c.gorep3.y)).to.equal(30.37)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should use a configurable number of gores', () => {
|
2022-08-28 12:36:09 +02:00
|
|
|
let pattern = new Pattern()
|
2022-01-27 20:52:55 +01:00
|
|
|
pattern.use(plugin)
|
|
|
|
let anchorPoint = new pattern.Point(50,50)
|
|
|
|
pattern.parts.test = new pattern.Part()
|
|
|
|
let { macro } = pattern.parts.test.shorthand()
|
|
|
|
macro('gore', {
|
|
|
|
from:anchorPoint,
|
|
|
|
radius:25,
|
2022-08-24 11:59:57 +02:00
|
|
|
gores:8,
|
2022-01-27 20:52:55 +01:00
|
|
|
extraLength:0,
|
|
|
|
prefix:'gore'
|
|
|
|
})
|
|
|
|
let c = pattern.parts.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)
|
|
|
|
expect(round(c.gorep2.y)).to.equal(40.18)
|
|
|
|
expect(round(c.gorep3.x)).to.equal(50)
|
|
|
|
expect(round(c.gorep3.y)).to.equal(40.18)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should use a configurable extra length', () => {
|
2022-08-28 12:36:09 +02:00
|
|
|
let pattern = new Pattern()
|
2022-01-27 20:52:55 +01:00
|
|
|
pattern.use(plugin)
|
|
|
|
let anchorPoint = new pattern.Point(50,50)
|
|
|
|
pattern.parts.test = new pattern.Part()
|
|
|
|
let { macro } = pattern.parts.test.shorthand()
|
|
|
|
macro('gore', {
|
|
|
|
from:anchorPoint,
|
|
|
|
radius:25,
|
2022-08-24 11:59:57 +02:00
|
|
|
gores:4,
|
2022-01-27 20:52:55 +01:00
|
|
|
extraLength:20,
|
|
|
|
prefix:'gore'
|
|
|
|
})
|
|
|
|
let c = pattern.parts.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)
|
|
|
|
expect(round(c.gorep2.y)).to.equal(30.37)
|
|
|
|
expect(round(c.gorep3.x)).to.equal(50)
|
|
|
|
expect(round(c.gorep3.y)).to.equal(30.37)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should use a configurable radius', () => {
|
2022-08-28 12:36:09 +02:00
|
|
|
let pattern = new Pattern()
|
2022-01-27 20:52:55 +01:00
|
|
|
pattern.use(plugin)
|
|
|
|
let anchorPoint = new pattern.Point(50,50)
|
|
|
|
pattern.parts.test = new pattern.Part()
|
|
|
|
let { macro } = pattern.parts.test.shorthand()
|
|
|
|
macro('gore', {
|
|
|
|
from:anchorPoint,
|
|
|
|
radius:30,
|
2022-08-24 11:59:57 +02:00
|
|
|
gores:4,
|
2022-01-27 20:52:55 +01:00
|
|
|
extraLength:0,
|
|
|
|
prefix:'gore'
|
|
|
|
})
|
|
|
|
let c = pattern.parts.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)
|
|
|
|
expect(round(c.gorep2.y)).to.equal(26.44)
|
|
|
|
expect(round(c.gorep3.x)).to.equal(50)
|
|
|
|
expect(round(c.gorep3.y)).to.equal(26.44)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should generate a seam path', () => {
|
2022-08-28 12:36:09 +02:00
|
|
|
let pattern = new Pattern()
|
2022-01-27 20:52:55 +01:00
|
|
|
pattern.use(plugin)
|
|
|
|
let anchorPoint = new pattern.Point(50,50)
|
|
|
|
pattern.parts.test = new pattern.Part()
|
|
|
|
let { macro } = pattern.parts.test.shorthand()
|
|
|
|
macro('gore', {
|
|
|
|
from:anchorPoint,
|
|
|
|
radius:25,
|
2022-08-24 11:59:57 +02:00
|
|
|
gores:4,
|
2022-01-27 20:52:55 +01:00
|
|
|
extraLength:0,
|
|
|
|
prefix:'gore'
|
|
|
|
})
|
|
|
|
pattern.render()
|
|
|
|
let c = pattern.parts.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)
|
|
|
|
expect(round(c[2].to.y)).to.equal(30.37)
|
2021-11-27 16:43:52 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|