wip(core): Migrated to named exports only
This commit is contained in:
parent
4b12a7330c
commit
c09ae4aa69
23 changed files with 592 additions and 557 deletions
|
@ -1,4 +1,4 @@
|
||||||
function Attributes() {
|
export function Attributes() {
|
||||||
this.list = {}
|
this.list = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,4 +103,3 @@ Attributes.prototype.clone = function () {
|
||||||
return clone
|
return clone
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Attributes
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import Pattern from './pattern.mjs'
|
import { Pattern } from './pattern.mjs'
|
||||||
import { addPartConfig } from './utils.mjs'
|
import { addPartConfig } from './utils.mjs'
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import { addPartConfig } from './utils.mjs'
|
||||||
* The Design constructor. Returns a Pattern constructor
|
* The Design constructor. Returns a Pattern constructor
|
||||||
* So it's sort of a super-constructor
|
* So it's sort of a super-constructor
|
||||||
*/
|
*/
|
||||||
export default function Design(config) {
|
export function Design(config) {
|
||||||
|
|
||||||
// Merge config with defaults
|
// Merge config with defaults
|
||||||
config = {
|
config = {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export default function Hooks() {
|
export function Hooks() {
|
||||||
return {
|
return {
|
||||||
preDraft: [],
|
preDraft: [],
|
||||||
postDraft: [],
|
postDraft: [],
|
||||||
|
|
|
@ -1,42 +1,78 @@
|
||||||
import Design from './design.mjs'
|
import { Attributes } from './attributes.mjs'
|
||||||
import Pattern from './pattern.mjs'
|
import { Design } from './design.mjs'
|
||||||
import Point from './point.mjs'
|
import { Pattern } from './pattern.mjs'
|
||||||
import Path from './path.mjs'
|
import { Point } from './point.mjs'
|
||||||
import Snippet from './snippet.mjs'
|
import { Path } from './path.mjs'
|
||||||
import * as utils from './utils.mjs'
|
import { Snippet } from './snippet.mjs'
|
||||||
import pkg from '../package.json' assert { type: 'json' }
|
import {
|
||||||
|
isCoord,
|
||||||
const { version } = pkg
|
capitalize,
|
||||||
|
beamsIntersect,
|
||||||
/*
|
linesIntersect,
|
||||||
* Named exports will become the default in FreeSewing v3
|
pointOnBeam,
|
||||||
*/
|
pointOnLine,
|
||||||
export {
|
pointOnCurve,
|
||||||
version,
|
splitCurve,
|
||||||
Design,
|
beamIntersectsX,
|
||||||
Pattern,
|
beamIntersectsY,
|
||||||
Point,
|
units,
|
||||||
Path,
|
lineIntersectsCurve,
|
||||||
Snippet,
|
curveIntersectsX,
|
||||||
utils,
|
curveIntersectsY,
|
||||||
}
|
curvesIntersect,
|
||||||
|
circlesIntersect,
|
||||||
// This is a helper for configuration files
|
beamIntersectsCircle,
|
||||||
export const pctBasedOn = utils.pctBasedOn
|
lineIntersectsCircle,
|
||||||
|
curveEdge,
|
||||||
// This is a helper for manual layouts
|
stretchToScale,
|
||||||
export const generatePartTransform = utils.generatePartTransform
|
round,
|
||||||
|
sampleStyle,
|
||||||
/*
|
deg2rad,
|
||||||
* Default exports will be removed in FreeSewing v3
|
rad2deg,
|
||||||
*/
|
|
||||||
export default {
|
|
||||||
version,
|
|
||||||
Design,
|
|
||||||
Pattern,
|
|
||||||
Point,
|
|
||||||
Path,
|
|
||||||
Snippet,
|
|
||||||
utils,
|
|
||||||
pctBasedOn,
|
pctBasedOn,
|
||||||
|
Bezier,
|
||||||
|
generatePartTransform,
|
||||||
|
macroName,
|
||||||
|
} from "./utils.mjs"
|
||||||
|
import { version } from '../package.json' assert { type: 'json' }
|
||||||
|
|
||||||
|
// Named exports
|
||||||
|
export {
|
||||||
|
Attributes,
|
||||||
|
Design,
|
||||||
|
Pattern,
|
||||||
|
Point,
|
||||||
|
Path,
|
||||||
|
Snippet,
|
||||||
|
|
||||||
|
Bezier,
|
||||||
|
version,
|
||||||
|
capitalize,
|
||||||
|
beamsIntersect,
|
||||||
|
linesIntersect,
|
||||||
|
pointOnBeam,
|
||||||
|
pointOnLine,
|
||||||
|
pointOnCurve,
|
||||||
|
splitCurve,
|
||||||
|
beamIntersectsX,
|
||||||
|
beamIntersectsY,
|
||||||
|
units,
|
||||||
|
lineIntersectsCurve,
|
||||||
|
curveIntersectsX,
|
||||||
|
curveIntersectsY,
|
||||||
|
curvesIntersect,
|
||||||
|
circlesIntersect,
|
||||||
|
beamIntersectsCircle,
|
||||||
|
lineIntersectsCircle,
|
||||||
|
curveEdge,
|
||||||
|
stretchToScale,
|
||||||
|
round,
|
||||||
|
sampleStyle,
|
||||||
|
deg2rad,
|
||||||
|
rad2deg,
|
||||||
|
pctBasedOn,
|
||||||
|
generatePartTransform,
|
||||||
|
macroName,
|
||||||
|
isCoord
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
function Option(config) {
|
export function Option(config) {
|
||||||
this.id = config.id
|
this.id = config.id
|
||||||
this.config = config
|
this.config = config
|
||||||
this.val = config.val
|
this.val = config.val
|
||||||
|
@ -6,4 +6,3 @@ function Option(config) {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Option
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
|
import { Attributes } from './attributes.mjs'
|
||||||
import * as utils from './utils.mjs'
|
import * as utils from './utils.mjs'
|
||||||
import Point from './point.mjs'
|
import { Point } from './point.mjs'
|
||||||
import Path from './path.mjs'
|
import { Path } from './path.mjs'
|
||||||
import Snippet from './snippet.mjs'
|
import { Snippet } from './snippet.mjs'
|
||||||
import Attributes from './attributes.mjs'
|
import { Hooks } from './hooks.mjs'
|
||||||
import Hooks from './hooks.mjs'
|
|
||||||
|
|
||||||
function Part() {
|
export function Part() {
|
||||||
this.attributes = new Attributes()
|
this.attributes = new Attributes()
|
||||||
this.points = {}
|
this.points = {}
|
||||||
this.paths = {}
|
this.paths = {}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import Attributes from './attributes.mjs'
|
import { Attributes } from './attributes.mjs'
|
||||||
import Point from './point.mjs'
|
import { Point } from './point.mjs'
|
||||||
import { Bezier } from 'bezier-js'
|
import { Bezier } from 'bezier-js'
|
||||||
import {
|
import {
|
||||||
linesIntersect,
|
linesIntersect,
|
||||||
|
@ -11,7 +11,7 @@ import {
|
||||||
round,
|
round,
|
||||||
} from './utils.mjs'
|
} from './utils.mjs'
|
||||||
|
|
||||||
function Path(debug = false) {
|
export function Path(debug = false) {
|
||||||
this.render = true
|
this.render = true
|
||||||
this.topLeft = false
|
this.topLeft = false
|
||||||
this.bottomRight = false
|
this.bottomRight = false
|
||||||
|
@ -913,4 +913,3 @@ Path.prototype.translate = function (x, y) {
|
||||||
return clone
|
return clone
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Path
|
|
||||||
|
|
|
@ -1,23 +1,28 @@
|
||||||
|
import { Attributes } from './attributes.mjs'
|
||||||
import pack from 'bin-pack'
|
import pack from 'bin-pack'
|
||||||
import {
|
import {
|
||||||
macroName,
|
macroName,
|
||||||
sampleStyle,
|
sampleStyle,
|
||||||
capitalize,
|
capitalize,
|
||||||
decoratePartDependency,
|
|
||||||
addPartConfig,
|
addPartConfig,
|
||||||
mergeDependencies,
|
mergeDependencies,
|
||||||
} from './utils.mjs'
|
} from './utils.mjs'
|
||||||
import Part from './part.mjs'
|
import { Part } from './part.mjs'
|
||||||
import Point from './point.mjs'
|
import { Point } from './point.mjs'
|
||||||
import Path from './path.mjs'
|
import { Path } from './path.mjs'
|
||||||
import Snippet from './snippet.mjs'
|
import { Snippet } from './snippet.mjs'
|
||||||
import Svg from './svg.mjs'
|
import { Svg } from './svg.mjs'
|
||||||
import Store from './store.mjs'
|
import { Store } from './store.mjs'
|
||||||
import Hooks from './hooks.mjs'
|
import { Hooks } from './hooks.mjs'
|
||||||
import Attributes from './attributes.mjs'
|
|
||||||
import { version } from '../package.json' assert { type: 'json' }
|
import { version } from '../package.json' assert { type: 'json' }
|
||||||
|
|
||||||
export default function Pattern(config = { options: {} }) {
|
/*
|
||||||
|
* Makes sure an object passed to be attached as a part it not merely a method
|
||||||
|
*/
|
||||||
|
const decoratePartDependency = (obj, name) => (typeof obj === 'function') ? { draft: obj, name } : obj
|
||||||
|
|
||||||
|
|
||||||
|
export function Pattern(config = { options: {} }) {
|
||||||
|
|
||||||
// Apply default settings
|
// Apply default settings
|
||||||
this.settings = {
|
this.settings = {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import Attributes from './attributes.mjs'
|
import { Attributes } from './attributes.mjs'
|
||||||
|
|
||||||
function Point(x, y, debug = false) {
|
export function Point(x, y, debug = false) {
|
||||||
this.x = x
|
this.x = x
|
||||||
this.y = y
|
this.y = y
|
||||||
this.attributes = new Attributes()
|
this.attributes = new Attributes()
|
||||||
|
@ -249,4 +249,3 @@ Point.prototype.setCircle = function (radius = false, className=false) {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Point
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import Attributes from './attributes.mjs'
|
import { Attributes } from './attributes.mjs'
|
||||||
|
|
||||||
function Snippet(def, anchor, debug = false) {
|
export function Snippet(def, anchor, debug = false) {
|
||||||
this.def = def
|
this.def = def
|
||||||
this.anchor = anchor
|
this.anchor = anchor
|
||||||
this.attributes = new Attributes()
|
this.attributes = new Attributes()
|
||||||
|
@ -31,4 +31,3 @@ Snippet.prototype.clone = function () {
|
||||||
return clone
|
return clone
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Snippet
|
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
import Path from './path'
|
|
||||||
|
|
||||||
/** Splits a curve on a point */
|
|
||||||
export default function splitCurve(start, cp1, cp2, end, split) {
|
|
||||||
let [c1, c2] = new Path().move(start).curve(cp1, cp2, end).split(split)
|
|
||||||
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
start: c1.ops[0].to,
|
|
||||||
cp1: c1.ops[1].cp1,
|
|
||||||
cp2: c1.ops[1].cp2,
|
|
||||||
end: c1.ops[1].to,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
start: c2.ops[0].to,
|
|
||||||
cp1: c2.ops[1].cp1,
|
|
||||||
cp2: c2.ops[1].cp2,
|
|
||||||
end: c2.ops[1].to,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
function Store(raise) {
|
export function Store(raise) {
|
||||||
this.data = new Map()
|
this.data = new Map()
|
||||||
this.raise = raise
|
this.raise = raise
|
||||||
}
|
}
|
||||||
|
@ -20,4 +20,3 @@ Store.prototype.get = function (key) {
|
||||||
return this.data.get(key)
|
return this.data.get(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Store
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import Attributes from './attributes.mjs'
|
import { Attributes } from './attributes.mjs'
|
||||||
import { round } from './utils.mjs'
|
import { round } from './utils.mjs'
|
||||||
import pkg from '../package.json'
|
import { version } from '../package.json'
|
||||||
|
|
||||||
function Svg(pattern) {
|
export function Svg(pattern) {
|
||||||
this.openGroups = []
|
this.openGroups = []
|
||||||
this.layout = {}
|
this.layout = {}
|
||||||
this.freeId = 0
|
this.freeId = 0
|
||||||
|
@ -23,7 +23,7 @@ function Svg(pattern) {
|
||||||
this.attributes.add('xmlns:xlink', 'http://www.w3.org/1999/xlink')
|
this.attributes.add('xmlns:xlink', 'http://www.w3.org/1999/xlink')
|
||||||
this.attributes.add('xml:lang', pattern.settings.locale)
|
this.attributes.add('xml:lang', pattern.settings.locale)
|
||||||
this.attributes.add('xmlns:freesewing', 'http://freesewing.org/namespaces/freesewing')
|
this.attributes.add('xmlns:freesewing', 'http://freesewing.org/namespaces/freesewing')
|
||||||
this.attributes.add('freesewing', pkg.version)
|
this.attributes.add('freesewing', version)
|
||||||
}
|
}
|
||||||
|
|
||||||
Svg.prototype.runHooks = function (hookName, data = false) {
|
Svg.prototype.runHooks = function (hookName, data = false) {
|
||||||
|
@ -312,4 +312,3 @@ Svg.prototype.getId = function () {
|
||||||
return '' + this.freeId
|
return '' + this.freeId
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Svg
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Bezier } from 'bezier-js'
|
import { Bezier } from 'bezier-js'
|
||||||
import Path from './path.mjs'
|
import { Path } from './path.mjs'
|
||||||
import Point from './point.mjs'
|
import { Point } from './point.mjs'
|
||||||
|
|
||||||
export function capitalize(string) {
|
export function capitalize(string) {
|
||||||
return string.charAt(0).toUpperCase() + string.slice(1)
|
return string.charAt(0).toUpperCase() + string.slice(1)
|
||||||
|
@ -410,11 +410,6 @@ export const generatePartTransform = (x, y, rotate, flipX, flipY, part) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Makes sure an object passed to be attached as a part it not merely a method
|
|
||||||
*/
|
|
||||||
export const decoratePartDependency = (obj, name) => (typeof obj === 'function') ? { draft: obj, name } : obj
|
|
||||||
|
|
||||||
// Add part-level options
|
// Add part-level options
|
||||||
const addPartOptions = (part, config) => {
|
const addPartOptions = (part, config) => {
|
||||||
if (part.options) {
|
if (part.options) {
|
||||||
|
@ -432,6 +427,7 @@ const addPartOptions = (part, config) => {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
// Helper method for detecting a array with only strings
|
// Helper method for detecting a array with only strings
|
||||||
const isStringArray = val => (Array.isArray(val) && val.length > 0)
|
const isStringArray = val => (Array.isArray(val) && val.length > 0)
|
||||||
? val.reduce((prev=true, cur) => (prev && typeof cur === 'string'))
|
? val.reduce((prev=true, cur) => (prev && typeof cur === 'string'))
|
||||||
|
@ -473,7 +469,7 @@ const mergeOptionGroups = (cur, add) => {
|
||||||
|
|
||||||
return cur
|
return cur
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
// Add part-level optionGroups
|
// Add part-level optionGroups
|
||||||
const addPartOptionGroups = (part, config) => {
|
const addPartOptionGroups = (part, config) => {
|
||||||
if (typeof config.optionGroups === 'undefined') {
|
if (typeof config.optionGroups === 'undefined') {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import chai from "chai"
|
import chai from "chai"
|
||||||
import freesewing from "./dist/index.mjs"
|
import { Design } from "./dist/index.mjs"
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
describe('Design', () => {
|
describe('Design', () => {
|
||||||
it("Design constructor should return pattern constructor", () => {
|
it("Design constructor should return pattern constructor", () => {
|
||||||
const design = new freesewing.Design({
|
const design = new Design({
|
||||||
foo: "bar",
|
foo: "bar",
|
||||||
options: {
|
options: {
|
||||||
constant: 2,
|
constant: 2,
|
||||||
|
@ -35,7 +35,7 @@ describe('Design', () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let design = new freesewing.Design({plugins: plugin});
|
let design = new Design({plugins: plugin});
|
||||||
let pattern = new design();
|
let pattern = new design();
|
||||||
expect(pattern.hooks.preRender.length).to.equal(1);
|
expect(pattern.hooks.preRender.length).to.equal(1);
|
||||||
});
|
});
|
||||||
|
@ -60,7 +60,7 @@ describe('Design', () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let design = new freesewing.Design( { plugins: [plugin1, plugin2] });
|
let design = new Design( { plugins: [plugin1, plugin2] });
|
||||||
let pattern = new design();
|
let pattern = new design();
|
||||||
expect(pattern.hooks.preRender.length).to.equal(2);
|
expect(pattern.hooks.preRender.length).to.equal(2);
|
||||||
});
|
});
|
||||||
|
@ -76,7 +76,7 @@ describe('Design', () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const condition = () => true
|
const condition = () => true
|
||||||
const design = new freesewing.Design({ conditionalPlugins: { plugin, condition } });
|
const design = new Design({ conditionalPlugins: { plugin, condition } });
|
||||||
const pattern = new design();
|
const pattern = new design();
|
||||||
expect(pattern.hooks.preRender.length).to.equal(1);
|
expect(pattern.hooks.preRender.length).to.equal(1);
|
||||||
});
|
});
|
||||||
|
@ -92,7 +92,7 @@ describe('Design', () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const condition = () => false
|
const condition = () => false
|
||||||
const design = new freesewing.Design({ conditionalPlugins: { plugin, condition } });
|
const design = new Design({ conditionalPlugins: { plugin, condition } });
|
||||||
const pattern = new design();
|
const pattern = new design();
|
||||||
expect(pattern.hooks.preRender.length).to.equal(0);
|
expect(pattern.hooks.preRender.length).to.equal(0);
|
||||||
});
|
});
|
||||||
|
@ -109,7 +109,7 @@ describe('Design', () => {
|
||||||
};
|
};
|
||||||
const condition1 = () => true
|
const condition1 = () => true
|
||||||
const condition2 = () => false
|
const condition2 = () => false
|
||||||
const design = new freesewing.Design({ conditionalPlugins: [
|
const design = new Design({ conditionalPlugins: [
|
||||||
{ plugin, condition: condition1 },
|
{ plugin, condition: condition1 },
|
||||||
{ plugin, condition: condition2 },
|
{ plugin, condition: condition2 },
|
||||||
]});
|
]});
|
||||||
|
@ -203,7 +203,7 @@ describe('Design', () => {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
it("Pattern constructor should add default hide() method to options", () => {
|
it("Pattern constructor should add default hide() method to options", () => {
|
||||||
const design = new freesewing.Design({
|
const design = new Design({
|
||||||
foo: "bar",
|
foo: "bar",
|
||||||
options: {
|
options: {
|
||||||
constant: 2,
|
constant: 2,
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import chai from "chai"
|
import chai from "chai"
|
||||||
import freesewing from "./dist/index.mjs"
|
import { Pattern, Path } from "./dist/index.mjs"
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
describe('Part', () => {
|
describe('Part', () => {
|
||||||
it("Svg constructor should initialize object", () => {
|
it("Svg constructor should initialize object", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
expect(part.paths).to.eql({});
|
expect(part.paths).to.eql({});
|
||||||
expect(part.snippets).to.eql({});
|
expect(part.snippets).to.eql({});
|
||||||
|
@ -18,20 +18,20 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return a function from macroClosure", () => {
|
it("Should return a function from macroClosure", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
expect(typeof part.macroClosure()).to.equal("function");
|
expect(typeof part.macroClosure()).to.equal("function");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not run an unknown macro", () => {
|
it("Should not run an unknown macro", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
let macro = part.macroClosure();
|
let macro = part.macroClosure();
|
||||||
expect(macro("unknown")).to.equal(undefined);
|
expect(macro("unknown")).to.equal(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should register and run a macro", () => {
|
it("Should register and run a macro", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let plugin = {
|
let plugin = {
|
||||||
name: "test",
|
name: "test",
|
||||||
version: "0.1-test",
|
version: "0.1-test",
|
||||||
|
@ -51,20 +51,20 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return a free ID", () => {
|
it("Should return a free ID", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
let free = part.getId();
|
let free = part.getId();
|
||||||
expect(part.getId()).to.equal("" + (parseInt(free) + 1));
|
expect(part.getId()).to.equal("" + (parseInt(free) + 1));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return a function from unitsClosure", () => {
|
it("Should return a function from unitsClosure", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
expect(typeof part.unitsClosure()).to.equal("function");
|
expect(typeof part.unitsClosure()).to.equal("function");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should convert units", () => {
|
it("Should convert units", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
let units = part.unitsClosure();
|
let units = part.unitsClosure();
|
||||||
expect(units(123.456)).to.equal("12.35cm");
|
expect(units(123.456)).to.equal("12.35cm");
|
||||||
|
@ -72,7 +72,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should set part attributes", () => {
|
it("Should set part attributes", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
part.attr("foo", "bar");
|
part.attr("foo", "bar");
|
||||||
expect(part.attributes.get("foo")).to.equal("bar");
|
expect(part.attributes.get("foo")).to.equal("bar");
|
||||||
|
@ -83,12 +83,12 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should inject a part", () => {
|
it("Should inject a part", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
part.points.a = new part.Point(12, 23);
|
part.points.a = new part.Point(12, 23);
|
||||||
part.points.b = new part.Point(10, 10);
|
part.points.b = new part.Point(10, 10);
|
||||||
part.points.c = new part.Point(20, 20);
|
part.points.c = new part.Point(20, 20);
|
||||||
part.paths.bar = new freesewing.Path()
|
part.paths.bar = new Path()
|
||||||
.move(part.points.a)
|
.move(part.points.a)
|
||||||
.line(part.points.b)
|
.line(part.points.b)
|
||||||
.curve(part.points.c, part.points.b, part.points.a)
|
.curve(part.points.c, part.points.b, part.points.a)
|
||||||
|
@ -109,7 +109,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return shorthand", () => {
|
it("Should return shorthand", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.settings.mode = "draft";
|
pattern.settings.mode = "draft";
|
||||||
pattern.settings.paperless = true;
|
pattern.settings.paperless = true;
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
|
@ -119,7 +119,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should raise a warning when setting a non-Point value in points", () => {
|
it("Should raise a warning when setting a non-Point value in points", () => {
|
||||||
const pattern = new freesewing.Pattern();
|
const pattern = new Pattern();
|
||||||
pattern.settings.mode = "draft";
|
pattern.settings.mode = "draft";
|
||||||
const part = new pattern.Part();
|
const part = new pattern.Part();
|
||||||
const { points } = part.shorthand()
|
const { points } = part.shorthand()
|
||||||
|
@ -131,7 +131,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should raise a warning when setting a non-Snippet value in snippets", () => {
|
it("Should raise a warning when setting a non-Snippet value in snippets", () => {
|
||||||
const pattern = new freesewing.Pattern();
|
const pattern = new Pattern();
|
||||||
pattern.settings.mode = "draft";
|
pattern.settings.mode = "draft";
|
||||||
const part = new pattern.Part();
|
const part = new pattern.Part();
|
||||||
const { snippets } = part.shorthand()
|
const { snippets } = part.shorthand()
|
||||||
|
@ -143,7 +143,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should calculate the part boundary with default margin", () => {
|
it("Should calculate the part boundary with default margin", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.settings.mode = "draft";
|
pattern.settings.mode = "draft";
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
let short = part.shorthand();
|
let short = part.shorthand();
|
||||||
|
@ -163,7 +163,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should calculate the part boundary with custom margin", () => {
|
it("Should calculate the part boundary with custom margin", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.settings.mode = "draft";
|
pattern.settings.mode = "draft";
|
||||||
pattern.settings.margin = 5;
|
pattern.settings.margin = 5;
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
|
@ -184,7 +184,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should calculate the part boundary for paperless", () => {
|
it("Should calculate the part boundary for paperless", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.settings.mode = "draft";
|
pattern.settings.mode = "draft";
|
||||||
pattern.settings.margin = 5;
|
pattern.settings.margin = 5;
|
||||||
pattern.settings.paperless = true;
|
pattern.settings.paperless = true;
|
||||||
|
@ -206,7 +206,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should stack a part", () => {
|
it("Should stack a part", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.settings.mode = "draft";
|
pattern.settings.mode = "draft";
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
let short = part.shorthand();
|
let short = part.shorthand();
|
||||||
|
@ -220,7 +220,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should only stack a part if needed", () => {
|
it("Should only stack a part if needed", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.settings.mode = "draft";
|
pattern.settings.mode = "draft";
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
let short = part.shorthand();
|
let short = part.shorthand();
|
||||||
|
@ -237,7 +237,7 @@ describe('Part', () => {
|
||||||
|
|
||||||
it("Should run hooks", () => {
|
it("Should run hooks", () => {
|
||||||
let count = 0
|
let count = 0
|
||||||
const pattern = new freesewing.Pattern()
|
const pattern = new Pattern()
|
||||||
const part = new pattern.Part();
|
const part = new pattern.Part();
|
||||||
part.hooks.preDraft = [{ method: function(p) { count++ }} ]
|
part.hooks.preDraft = [{ method: function(p) { count++ }} ]
|
||||||
part.runHooks('preDraft')
|
part.runHooks('preDraft')
|
||||||
|
@ -245,7 +245,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should get the units closure to raise a debug when passing a non-number", () => {
|
it("Should get the units closure to raise a debug when passing a non-number", () => {
|
||||||
const pattern = new freesewing.Pattern();
|
const pattern = new Pattern();
|
||||||
pattern.settings.mode = "draft";
|
pattern.settings.mode = "draft";
|
||||||
pattern.settings.debug = true
|
pattern.settings.debug = true
|
||||||
const part = new pattern.Part();
|
const part = new pattern.Part();
|
||||||
|
@ -256,7 +256,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should generate the part transforms", () => {
|
it("Should generate the part transforms", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.settings.mode = "draft";
|
pattern.settings.mode = "draft";
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
let short = part.shorthand();
|
let short = part.shorthand();
|
||||||
|
@ -278,7 +278,7 @@ describe('Part', () => {
|
||||||
|
|
||||||
|
|
||||||
it("Should add the part cut", () => {
|
it("Should add the part cut", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
part.addCut(4, 'fabric', true)
|
part.addCut(4, 'fabric', true)
|
||||||
expect(part.cut.materials.fabric.cut).to.equal(4)
|
expect(part.cut.materials.fabric.cut).to.equal(4)
|
||||||
|
@ -289,7 +289,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should generate an error if cut is not a number", () => {
|
it("Should generate an error if cut is not a number", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
part.addCut('a', 'fabric', true)
|
part.addCut('a', 'fabric', true)
|
||||||
expect(pattern.events.error.length).to.equal(1)
|
expect(pattern.events.error.length).to.equal(1)
|
||||||
|
@ -297,7 +297,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should generate an warning if material is not a string", () => {
|
it("Should generate an warning if material is not a string", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
part.addCut(3, 4)
|
part.addCut(3, 4)
|
||||||
expect(pattern.events.warning.length).to.equal(1)
|
expect(pattern.events.warning.length).to.equal(1)
|
||||||
|
@ -305,7 +305,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should generate an error when removing a material that is not set (through addCut)", () => {
|
it("Should generate an error when removing a material that is not set (through addCut)", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
part.addCut(4, 'fabric', true)
|
part.addCut(4, 'fabric', true)
|
||||||
part.addCut(false, 'lining')
|
part.addCut(false, 'lining')
|
||||||
|
@ -314,7 +314,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should remove the part cut through addCut", () => {
|
it("Should remove the part cut through addCut", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
part.addCut(4, 'fabric', true)
|
part.addCut(4, 'fabric', true)
|
||||||
part.addCut(false, 'fabric')
|
part.addCut(false, 'fabric')
|
||||||
|
@ -322,7 +322,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should remove the part cut through removeCut", () => {
|
it("Should remove the part cut through removeCut", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
part.addCut(4, 'fabric', true)
|
part.addCut(4, 'fabric', true)
|
||||||
part.removeCut('fabric')
|
part.removeCut('fabric')
|
||||||
|
@ -330,7 +330,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should generate an error when removing a material that is not set (through removeCut)", () => {
|
it("Should generate an error when removing a material that is not set (through removeCut)", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
part.addCut(4, 'fabric', true)
|
part.addCut(4, 'fabric', true)
|
||||||
part.removeCut('lining')
|
part.removeCut('lining')
|
||||||
|
@ -339,7 +339,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should generate an error when removing a material that is not a string (through removeCut)", () => {
|
it("Should generate an error when removing a material that is not a string (through removeCut)", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
part.addCut(4, 'fabric', true)
|
part.addCut(4, 'fabric', true)
|
||||||
part.removeCut(23)
|
part.removeCut(23)
|
||||||
|
@ -348,7 +348,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should generate a warning when calling removeCut without parameters", () => {
|
it("Should generate a warning when calling removeCut without parameters", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
part.addCut(4, 'fabric', true)
|
part.addCut(4, 'fabric', true)
|
||||||
part.removeCut()
|
part.removeCut()
|
||||||
|
@ -357,7 +357,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should set the part grainline", () => {
|
it("Should set the part grainline", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
expect(part.cut.grain).to.equal(90)
|
expect(part.cut.grain).to.equal(90)
|
||||||
part.setGrain(123)
|
part.setGrain(123)
|
||||||
|
@ -365,14 +365,14 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should raise a warning when calling part.setGrain() without any parameters", () => {
|
it("Should raise a warning when calling part.setGrain() without any parameters", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
part.setGrain()
|
part.setGrain()
|
||||||
expect(part.cut.grain).to.equal(false)
|
expect(part.cut.grain).to.equal(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should raise an error when calling part.setGrain() with a value that is not a number", () => {
|
it("Should raise an error when calling part.setGrain() with a value that is not a number", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
part.setGrain('a')
|
part.setGrain('a')
|
||||||
expect(part.cut.grain).to.equal(90)
|
expect(part.cut.grain).to.equal(90)
|
||||||
|
@ -381,7 +381,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should set and then remove the cutOnFold", () => {
|
it("Should set and then remove the cutOnFold", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
const { Point } = part.shorthand()
|
const { Point } = part.shorthand()
|
||||||
part.setCutOnFold(new Point(2,3), new Point(100,200))
|
part.setCutOnFold(new Point(2,3), new Point(100,200))
|
||||||
|
@ -394,7 +394,7 @@ describe('Part', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should raise an error when setting the cutOnFold with a non-Point value", () => {
|
it("Should raise an error when setting the cutOnFold with a non-Point value", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
const { Point } = part.shorthand()
|
const { Point } = part.shorthand()
|
||||||
part.setCutOnFold(new Point(2,3), 12)
|
part.setCutOnFold(new Point(2,3), 12)
|
||||||
|
@ -404,13 +404,13 @@ describe('Part', () => {
|
||||||
|
|
||||||
describe('isEmpty', () => {
|
describe('isEmpty', () => {
|
||||||
it("Should return true if the part has no paths or snippets", () => {
|
it("Should return true if the part has no paths or snippets", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
expect(part.isEmpty()).to.be.true
|
expect(part.isEmpty()).to.be.true
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Should return true if the part has paths but they have no length", () => {
|
it("Should return true if the part has paths but they have no length", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
const { Path, paths, Point } = part.shorthand()
|
const { Path, paths, Point } = part.shorthand()
|
||||||
paths.seam = new Path()
|
paths.seam = new Path()
|
||||||
|
@ -418,7 +418,7 @@ describe('Part', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Should return true if the part has paths but they don't render", () => {
|
it("Should return true if the part has paths but they don't render", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
const { Path, paths, Point } = part.shorthand()
|
const { Path, paths, Point } = part.shorthand()
|
||||||
paths.seam = new Path().move(new Point(0,0)).line(new Point(2,3)).setRender(false)
|
paths.seam = new Path().move(new Point(0,0)).line(new Point(2,3)).setRender(false)
|
||||||
|
@ -426,7 +426,7 @@ describe('Part', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Should return false if the part has a path with length", () => {
|
it("Should return false if the part has a path with length", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
const { Path, paths, Point } = part.shorthand()
|
const { Path, paths, Point } = part.shorthand()
|
||||||
paths.seam = new Path().move(new Point(0,0)).line(new Point(2,3))
|
paths.seam = new Path().move(new Point(0,0)).line(new Point(2,3))
|
||||||
|
@ -435,7 +435,7 @@ describe('Part', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Should return false if the part has a snippet", () => {
|
it("Should return false if the part has a snippet", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
const { Point, snippets, Snippet } = part.shorthand()
|
const { Point, snippets, Snippet } = part.shorthand()
|
||||||
snippets.test = new Snippet('test', new Point(0,0))
|
snippets.test = new Snippet('test', new Point(0,0))
|
||||||
|
@ -444,7 +444,7 @@ describe('Part', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Should return false if the part has a point that has text", () => {
|
it("Should return false if the part has a point that has text", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
const {Point, points} = part.shorthand()
|
const {Point, points} = part.shorthand()
|
||||||
points.test = new Point(0,0)
|
points.test = new Point(0,0)
|
||||||
|
@ -453,7 +453,7 @@ describe('Part', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Should return false if the part has a point that has a circle", () => {
|
it("Should return false if the part has a point that has a circle", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
const {Point, points} = part.shorthand()
|
const {Point, points} = part.shorthand()
|
||||||
points.test = new Point(0,0)
|
points.test = new Point(0,0)
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import chai from "chai"
|
import chai from "chai"
|
||||||
import freesewing from "./dist/index.mjs"
|
import { round, Pattern, Path, Point } from "./dist/index.mjs"
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
const round = freesewing.utils.round
|
|
||||||
|
|
||||||
describe('Path', () => {
|
describe('Path', () => {
|
||||||
it("Should offset a line", () => {
|
it("Should offset a line", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -18,7 +17,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should offset a curve", () => {
|
it("Should offset a curve", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -32,7 +31,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should offset a curve where cp1 = start", () => {
|
it("Should offset a curve where cp1 = start", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -46,7 +45,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should offset a curve where cp2 = end", () => {
|
it("Should offset a curve where cp2 = end", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -61,7 +60,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should throw error when offsetting line that is no line", () => {
|
it("Should throw error when offsetting line that is no line", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -70,7 +69,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return the length of a line", () => {
|
it("Should return the length of a line", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -79,7 +78,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return the length of a curve", () => {
|
it("Should return the length of a curve", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -91,7 +90,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return the path start point", () => {
|
it("Should return the path start point", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -104,7 +103,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return the path end point", () => {
|
it("Should return the path end point", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -119,7 +118,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should calculate that path boundary", () => {
|
it("Should calculate that path boundary", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -135,7 +134,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should clone a path", () => {
|
it("Should clone a path", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -152,7 +151,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should join paths", () => {
|
it("Should join paths", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -165,7 +164,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should throw error when joining a closed paths", () => {
|
it("Should throw error when joining a closed paths", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -178,7 +177,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should shift along a line", () => {
|
it("Should shift along a line", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -187,7 +186,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not shift along a path/line if we end up on the end point", () => {
|
it("Should not shift along a path/line if we end up on the end point", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -196,7 +195,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should shift along lines", () => {
|
it("Should shift along lines", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -209,7 +208,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should shift along curve + line", () => {
|
it("Should shift along curve + line", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -223,7 +222,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should throw error when shifting along path further than it's long", () => {
|
it("Should throw error when shifting along path further than it's long", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.paths.test = new a.Path()
|
a.paths.test = new a.Path()
|
||||||
|
@ -234,7 +233,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should shift along with sufficient precision", () => {
|
it("Should shift along with sufficient precision", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.paths.test = new a.Path()
|
a.paths.test = new a.Path()
|
||||||
|
@ -246,7 +245,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should shift fraction with sufficient precision", () => {
|
it("Should shift fraction with sufficient precision", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.paths.test = new a.Path()
|
a.paths.test = new a.Path()
|
||||||
|
@ -258,7 +257,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should shift a fraction along a line", () => {
|
it("Should shift a fraction along a line", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.paths.line = new a.Path()
|
a.paths.line = new a.Path()
|
||||||
|
@ -270,7 +269,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find the bounding box of a line", () => {
|
it("Should find the bounding box of a line", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let Path = pattern.parts.a.Path;
|
let Path = pattern.parts.a.Path;
|
||||||
let Point = pattern.parts.a.Point;
|
let Point = pattern.parts.a.Point;
|
||||||
|
@ -333,7 +332,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find the bounding box of a line", () => {
|
it("Should find the bounding box of a line", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.paths.curve = new a.Path()
|
a.paths.curve = new a.Path()
|
||||||
|
@ -348,7 +347,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should reverse a path", () => {
|
it("Should reverse a path", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
let test = new a.Path()
|
let test = new a.Path()
|
||||||
|
@ -368,7 +367,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find the edges of a path", () => {
|
it("Should find the edges of a path", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.points.A = new a.Point(45, 60);
|
a.points.A = new a.Point(45, 60);
|
||||||
|
@ -403,7 +402,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find the edges of a path for corner cases", () => {
|
it("Should find the edges of a path for corner cases", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.points.A = new a.Point(-45, -60);
|
a.points.A = new a.Point(-45, -60);
|
||||||
|
@ -430,7 +429,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find the edge of a path for this edge-case", () => {
|
it("Should find the edge of a path for this edge-case", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.points.A = new a.Point(-109.7, 77, 12);
|
a.points.A = new a.Point(-109.7, 77, 12);
|
||||||
|
@ -445,7 +444,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find where a path intersects with an X value", () => {
|
it("Should find where a path intersects with an X value", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.points.A = new a.Point(95, 50);
|
a.points.A = new a.Point(95, 50);
|
||||||
|
@ -474,7 +473,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find where a path intersects with an Y value", () => {
|
it("Should find where a path intersects with an Y value", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.points.A = new a.Point(95, 50);
|
a.points.A = new a.Point(95, 50);
|
||||||
|
@ -499,7 +498,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should throw an error when not passing a value to path.intersectsX", () => {
|
it("Should throw an error when not passing a value to path.intersectsX", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.paths.test = new a.Path();
|
a.paths.test = new a.Path();
|
||||||
|
@ -508,7 +507,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find the intersections between two paths", () => {
|
it("Should find the intersections between two paths", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.points.A = new a.Point(45, 60);
|
a.points.A = new a.Point(45, 60);
|
||||||
|
@ -554,7 +553,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should throw an error when running path.intersect on an identical path", () => {
|
it("Should throw an error when running path.intersect on an identical path", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.paths.test = new a.Path();
|
a.paths.test = new a.Path();
|
||||||
|
@ -562,7 +561,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should divide a path", () => {
|
it("Should divide a path", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.points.A = new a.Point(45, 60);
|
a.points.A = new a.Point(45, 60);
|
||||||
|
@ -615,7 +614,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should split a path on a curve", () => {
|
it("Should split a path on a curve", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.points.A = new a.Point(45, 60);
|
a.points.A = new a.Point(45, 60);
|
||||||
|
@ -645,7 +644,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should split a path on a line", () => {
|
it("Should split a path on a line", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.points.A = new a.Point(45, 60);
|
a.points.A = new a.Point(45, 60);
|
||||||
|
@ -671,7 +670,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should trim a path when lines overlap", () => {
|
it("Should trim a path when lines overlap", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.points.A = new a.Point(0, 0);
|
a.points.A = new a.Point(0, 0);
|
||||||
|
@ -694,7 +693,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should trim a path when a line overlaps with a curve", () => {
|
it("Should trim a path when a line overlaps with a curve", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.points.A = new a.Point(0, 0);
|
a.points.A = new a.Point(0, 0);
|
||||||
|
@ -717,7 +716,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should trim a path when a curves overlap", () => {
|
it("Should trim a path when a curves overlap", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.points.A = new a.Point(0, 0);
|
a.points.A = new a.Point(0, 0);
|
||||||
|
@ -740,7 +739,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should translate a path", () => {
|
it("Should translate a path", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
a.points.A = new a.Point(0, 0);
|
a.points.A = new a.Point(0, 0);
|
||||||
|
@ -761,7 +760,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should add a path attribute", () => {
|
it("Should add a path attribute", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -774,7 +773,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should overwrite a path attribute", () => {
|
it("Should overwrite a path attribute", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -790,7 +789,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should move along a path even if it lands just on a joint", () => {
|
it("Should move along a path even if it lands just on a joint", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
let a = pattern.parts.a;
|
let a = pattern.parts.a;
|
||||||
|
|
||||||
|
@ -811,23 +810,23 @@ describe('Path', () => {
|
||||||
|
|
||||||
it("Should add raise methods to a path", () => {
|
it("Should add raise methods to a path", () => {
|
||||||
const raise = () => 'hello'
|
const raise = () => 'hello'
|
||||||
const p1 = new freesewing.Path(10, 20).withRaise(raise);
|
const p1 = new Path(10, 20).withRaise(raise);
|
||||||
expect(p1.raise()).to.equal('hello');
|
expect(p1.raise()).to.equal('hello');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should add raise methods to a path", () => {
|
it("Should add raise methods to a path", () => {
|
||||||
const raise = () => 'hello'
|
const raise = () => 'hello'
|
||||||
const p1 = new freesewing.Path().withRaise(raise);
|
const p1 = new Path().withRaise(raise);
|
||||||
expect(p1.raise()).to.equal('hello');
|
expect(p1.raise()).to.equal('hello');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should set render to true/false", () => {
|
it("Should set render to true/false", () => {
|
||||||
const p1 = new freesewing.Path().setRender(false)
|
const p1 = new Path().setRender(false)
|
||||||
expect(p1.render).to.equal(false);
|
expect(p1.render).to.equal(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should set class with setClass", () => {
|
it("Should set class with setClass", () => {
|
||||||
const p1 = new freesewing.Path().setClass('fabric')
|
const p1 = new Path().setClass('fabric')
|
||||||
p1.setClass()
|
p1.setClass()
|
||||||
expect(p1.attributes.get('class')).to.equal('fabric');
|
expect(p1.attributes.get('class')).to.equal('fabric');
|
||||||
});
|
});
|
||||||
|
@ -835,7 +834,7 @@ describe('Path', () => {
|
||||||
it("Should raise a warning when moving to a non-point", () => {
|
it("Should raise a warning when moving to a non-point", () => {
|
||||||
let invalid = false
|
let invalid = false
|
||||||
const raise = { warning: () => invalid = true }
|
const raise = { warning: () => invalid = true }
|
||||||
const p1 = new freesewing.Path().withRaise(raise)
|
const p1 = new Path().withRaise(raise)
|
||||||
expect(invalid).to.equal(false);
|
expect(invalid).to.equal(false);
|
||||||
try {
|
try {
|
||||||
p1.move('a')
|
p1.move('a')
|
||||||
|
@ -849,7 +848,7 @@ describe('Path', () => {
|
||||||
it("Should raise a warning when drawing a line to a non-point", () => {
|
it("Should raise a warning when drawing a line to a non-point", () => {
|
||||||
let invalid = false
|
let invalid = false
|
||||||
const raise = { warning: () => invalid = true }
|
const raise = { warning: () => invalid = true }
|
||||||
const p1 = new freesewing.Path().withRaise(raise)
|
const p1 = new Path().withRaise(raise)
|
||||||
expect(invalid).to.equal(false);
|
expect(invalid).to.equal(false);
|
||||||
try {
|
try {
|
||||||
p1.line('a')
|
p1.line('a')
|
||||||
|
@ -863,9 +862,9 @@ describe('Path', () => {
|
||||||
it("Should raise a warning when drawing a curve to a non-point", () => {
|
it("Should raise a warning when drawing a curve to a non-point", () => {
|
||||||
let invalid = false
|
let invalid = false
|
||||||
const raise = { warning: () => invalid = true }
|
const raise = { warning: () => invalid = true }
|
||||||
const p1 = new freesewing.Path().withRaise(raise)
|
const p1 = new Path().withRaise(raise)
|
||||||
const a = new freesewing.Point(0,0)
|
const a = new Point(0,0)
|
||||||
const b = new freesewing.Point(10,10)
|
const b = new Point(10,10)
|
||||||
expect(invalid).to.equal(false);
|
expect(invalid).to.equal(false);
|
||||||
try {
|
try {
|
||||||
p1.move(b).curve(a, b, 'c')
|
p1.move(b).curve(a, b, 'c')
|
||||||
|
@ -879,9 +878,9 @@ describe('Path', () => {
|
||||||
it("Should raise a warning when drawing a curve with a Cp1 that is a non-point", () => {
|
it("Should raise a warning when drawing a curve with a Cp1 that is a non-point", () => {
|
||||||
let invalid = false
|
let invalid = false
|
||||||
const raise = { warning: () => invalid = true }
|
const raise = { warning: () => invalid = true }
|
||||||
const p1 = new freesewing.Path().withRaise(raise)
|
const p1 = new Path().withRaise(raise)
|
||||||
const a = new freesewing.Point(0,0)
|
const a = new Point(0,0)
|
||||||
const b = new freesewing.Point(10,10)
|
const b = new Point(10,10)
|
||||||
expect(invalid).to.equal(false);
|
expect(invalid).to.equal(false);
|
||||||
try {
|
try {
|
||||||
p1.move(b).curve(a, 'x', b)
|
p1.move(b).curve(a, 'x', b)
|
||||||
|
@ -895,8 +894,8 @@ describe('Path', () => {
|
||||||
it("Should raise a warning when drawing a curve with a Cp1 that is a non-point", () => {
|
it("Should raise a warning when drawing a curve with a Cp1 that is a non-point", () => {
|
||||||
let invalid = false
|
let invalid = false
|
||||||
const raise = { warning: () => invalid = true }
|
const raise = { warning: () => invalid = true }
|
||||||
const p1 = new freesewing.Path().withRaise(raise)
|
const p1 = new Path().withRaise(raise)
|
||||||
const b = new freesewing.Point(10,10)
|
const b = new Point(10,10)
|
||||||
expect(invalid).to.equal(false);
|
expect(invalid).to.equal(false);
|
||||||
try {
|
try {
|
||||||
p1.move(b).curve('a', b, b)
|
p1.move(b).curve('a', b, b)
|
||||||
|
@ -910,8 +909,8 @@ describe('Path', () => {
|
||||||
it("Should raise a warning when drawing a curve with a Cp2 that is a non-point", () => {
|
it("Should raise a warning when drawing a curve with a Cp2 that is a non-point", () => {
|
||||||
let invalid = false
|
let invalid = false
|
||||||
const raise = { warning: () => invalid = true }
|
const raise = { warning: () => invalid = true }
|
||||||
const p1 = new freesewing.Path().withRaise(raise)
|
const p1 = new Path().withRaise(raise)
|
||||||
const b = new freesewing.Point(10,10)
|
const b = new Point(10,10)
|
||||||
expect(invalid).to.equal(false);
|
expect(invalid).to.equal(false);
|
||||||
try {
|
try {
|
||||||
p1.move(b).curve(b, 'a', b)
|
p1.move(b).curve(b, 'a', b)
|
||||||
|
@ -925,8 +924,8 @@ describe('Path', () => {
|
||||||
it("Should raise a warning when drawing a _curve with a To that is a non-point", () => {
|
it("Should raise a warning when drawing a _curve with a To that is a non-point", () => {
|
||||||
let invalid = false
|
let invalid = false
|
||||||
const raise = { warning: () => invalid = true }
|
const raise = { warning: () => invalid = true }
|
||||||
const p1 = new freesewing.Path().withRaise(raise)
|
const p1 = new Path().withRaise(raise)
|
||||||
const b = new freesewing.Point(10,10)
|
const b = new Point(10,10)
|
||||||
expect(invalid).to.equal(false);
|
expect(invalid).to.equal(false);
|
||||||
try {
|
try {
|
||||||
p1.move(b)._curve(b, 'a')
|
p1.move(b)._curve(b, 'a')
|
||||||
|
@ -940,8 +939,8 @@ describe('Path', () => {
|
||||||
it("Should raise a warning when drawing a _curve with a Cp2 that is a non-point", () => {
|
it("Should raise a warning when drawing a _curve with a Cp2 that is a non-point", () => {
|
||||||
let invalid = false
|
let invalid = false
|
||||||
const raise = { warning: () => invalid = true }
|
const raise = { warning: () => invalid = true }
|
||||||
const p1 = new freesewing.Path().withRaise(raise)
|
const p1 = new Path().withRaise(raise)
|
||||||
const b = new freesewing.Point(10,10)
|
const b = new Point(10,10)
|
||||||
expect(invalid).to.equal(false);
|
expect(invalid).to.equal(false);
|
||||||
try {
|
try {
|
||||||
p1.move(b)._curve('a', b)
|
p1.move(b)._curve('a', b)
|
||||||
|
@ -955,8 +954,8 @@ describe('Path', () => {
|
||||||
it("Should raise a warning when drawing a curve_ with a To that is a non-point", () => {
|
it("Should raise a warning when drawing a curve_ with a To that is a non-point", () => {
|
||||||
let invalid = false
|
let invalid = false
|
||||||
const raise = { warning: () => invalid = true }
|
const raise = { warning: () => invalid = true }
|
||||||
const p1 = new freesewing.Path().withRaise(raise)
|
const p1 = new Path().withRaise(raise)
|
||||||
const b = new freesewing.Point(10,10)
|
const b = new Point(10,10)
|
||||||
expect(invalid).to.equal(false);
|
expect(invalid).to.equal(false);
|
||||||
try {
|
try {
|
||||||
p1.move(b).curve_(b, 'a')
|
p1.move(b).curve_(b, 'a')
|
||||||
|
@ -970,8 +969,8 @@ describe('Path', () => {
|
||||||
it("Should raise a warning when drawing a curve_ with a Cp2 that is a non-point", () => {
|
it("Should raise a warning when drawing a curve_ with a Cp2 that is a non-point", () => {
|
||||||
let invalid = false
|
let invalid = false
|
||||||
const raise = { warning: () => invalid = true }
|
const raise = { warning: () => invalid = true }
|
||||||
const p1 = new freesewing.Path().withRaise(raise)
|
const p1 = new Path().withRaise(raise)
|
||||||
const b = new freesewing.Point(10,10)
|
const b = new Point(10,10)
|
||||||
expect(invalid).to.equal(false);
|
expect(invalid).to.equal(false);
|
||||||
try {
|
try {
|
||||||
p1.move(b).curve_('a', b)
|
p1.move(b).curve_('a', b)
|
||||||
|
@ -983,16 +982,16 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should add a noop operation", () => {
|
it("Should add a noop operation", () => {
|
||||||
const p1 = new freesewing.Path().noop()
|
const p1 = new Path().noop()
|
||||||
expect(p1.ops.length).to.equal(1);
|
expect(p1.ops.length).to.equal(1);
|
||||||
expect(p1.ops[0].type).to.equal('noop');
|
expect(p1.ops[0].type).to.equal('noop');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should handle an insop operation", () => {
|
it("Should handle an insop operation", () => {
|
||||||
const a = new freesewing.Point(0,0)
|
const a = new Point(0,0)
|
||||||
const b = new freesewing.Point(10,10)
|
const b = new Point(10,10)
|
||||||
const p1 = new freesewing.Path().move(a).line(b)
|
const p1 = new Path().move(a).line(b)
|
||||||
const p2 = new freesewing.Path().noop('test').insop('test', p1)
|
const p2 = new Path().noop('test').insop('test', p1)
|
||||||
expect(p2.ops.length).to.equal(2);
|
expect(p2.ops.length).to.equal(2);
|
||||||
expect(p1.ops[0].type).to.equal('move');
|
expect(p1.ops[0].type).to.equal('move');
|
||||||
expect(p1.ops[1].type).to.equal('line');
|
expect(p1.ops[1].type).to.equal('line');
|
||||||
|
@ -1001,23 +1000,23 @@ describe('Path', () => {
|
||||||
it("Should raise a warning when an insop operation used an falsy ID", () => {
|
it("Should raise a warning when an insop operation used an falsy ID", () => {
|
||||||
let invalid = false
|
let invalid = false
|
||||||
const raise = { warning: () => invalid = true }
|
const raise = { warning: () => invalid = true }
|
||||||
const a = new freesewing.Point(0,0)
|
const a = new Point(0,0)
|
||||||
const b = new freesewing.Point(10,10)
|
const b = new Point(10,10)
|
||||||
const p1 = new freesewing.Path().move(a).line(b)
|
const p1 = new Path().move(a).line(b)
|
||||||
expect(invalid).to.equal(false);
|
expect(invalid).to.equal(false);
|
||||||
const p2 = new freesewing.Path().withRaise(raise).noop('test').insop(false, p1)
|
const p2 = new Path().withRaise(raise).noop('test').insop(false, p1)
|
||||||
expect(invalid).to.equal(true);
|
expect(invalid).to.equal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should raise a warning when an insop operation used an falsy ID", () => {
|
it("Should raise a warning when an insop operation used an falsy ID", () => {
|
||||||
let invalid = false
|
let invalid = false
|
||||||
const raise = { warning: () => invalid = true }
|
const raise = { warning: () => invalid = true }
|
||||||
const a = new freesewing.Point(0,0)
|
const a = new Point(0,0)
|
||||||
const b = new freesewing.Point(10,10)
|
const b = new Point(10,10)
|
||||||
const p1 = new freesewing.Path().move(a).line(b)
|
const p1 = new Path().move(a).line(b)
|
||||||
expect(invalid).to.equal(false);
|
expect(invalid).to.equal(false);
|
||||||
try {
|
try {
|
||||||
new freesewing.Path().withRaise(raise).noop('test').insop('test')
|
new Path().withRaise(raise).noop('test').insop('test')
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
expect(''+err).to.contain("Cannot read properties of undefined (reading 'ops')")
|
expect(''+err).to.contain("Cannot read properties of undefined (reading 'ops')")
|
||||||
|
@ -1029,7 +1028,7 @@ describe('Path', () => {
|
||||||
let invalid = false
|
let invalid = false
|
||||||
const raise = { warning: () => invalid = true }
|
const raise = { warning: () => invalid = true }
|
||||||
expect(invalid).to.equal(false);
|
expect(invalid).to.equal(false);
|
||||||
const p1 = new freesewing.Path().withRaise(raise).attr()
|
const p1 = new Path().withRaise(raise).attr()
|
||||||
expect(invalid).to.equal(true);
|
expect(invalid).to.equal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1037,12 +1036,12 @@ describe('Path', () => {
|
||||||
let invalid = false
|
let invalid = false
|
||||||
const raise = { warning: () => invalid = true }
|
const raise = { warning: () => invalid = true }
|
||||||
expect(invalid).to.equal(false);
|
expect(invalid).to.equal(false);
|
||||||
const p1 = new freesewing.Path().withRaise(raise).attr('test')
|
const p1 = new Path().withRaise(raise).attr('test')
|
||||||
expect(invalid).to.equal(true);
|
expect(invalid).to.equal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should raise a warning when calling offset without a distance", () => {
|
it("Should raise a warning when calling offset without a distance", () => {
|
||||||
const pattern = new freesewing.Pattern();
|
const pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
const { Path, Point, points, paths } = pattern.parts.a.shorthand()
|
const { Path, Point, points, paths } = pattern.parts.a.shorthand()
|
||||||
points.a = new Point(0,0)
|
points.a = new Point(0,0)
|
||||||
|
@ -1054,7 +1053,7 @@ describe('Path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should raise a warning when calling join without a path", () => {
|
it("Should raise a warning when calling join without a path", () => {
|
||||||
const pattern = new freesewing.Pattern();
|
const pattern = new Pattern();
|
||||||
pattern.parts.a = new pattern.Part();
|
pattern.parts.a = new pattern.Part();
|
||||||
const { Path, Point, points, paths } = pattern.parts.a.shorthand()
|
const { Path, Point, points, paths } = pattern.parts.a.shorthand()
|
||||||
points.a = new Point(0,0)
|
points.a = new Point(0,0)
|
||||||
|
@ -1075,7 +1074,7 @@ describe('Path', () => {
|
||||||
const raise = { error: () => invalid = true }
|
const raise = { error: () => invalid = true }
|
||||||
expect(invalid).to.equal(false);
|
expect(invalid).to.equal(false);
|
||||||
try {
|
try {
|
||||||
new freesewing.Path().withRaise(raise).start()
|
new Path().withRaise(raise).start()
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
expect(''+err).to.contain("Cannot read properties of undefined (reading 'to')")
|
expect(''+err).to.contain("Cannot read properties of undefined (reading 'to')")
|
||||||
|
@ -1088,7 +1087,7 @@ describe('Path', () => {
|
||||||
const raise = { error: () => invalid = true }
|
const raise = { error: () => invalid = true }
|
||||||
expect(invalid).to.equal(false);
|
expect(invalid).to.equal(false);
|
||||||
try {
|
try {
|
||||||
new freesewing.Path().withRaise(raise).end()
|
new Path().withRaise(raise).end()
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
expect(''+err).to.contain("Cannot read properties of undefined (reading 'type')")
|
expect(''+err).to.contain("Cannot read properties of undefined (reading 'type')")
|
||||||
|
@ -1100,10 +1099,10 @@ describe('Path', () => {
|
||||||
let invalid = false
|
let invalid = false
|
||||||
const raise = { error: () => invalid = true }
|
const raise = { error: () => invalid = true }
|
||||||
expect(invalid).to.equal(false);
|
expect(invalid).to.equal(false);
|
||||||
new freesewing.Path()
|
new Path()
|
||||||
.withRaise(raise)
|
.withRaise(raise)
|
||||||
.move(new freesewing.Point(0,0))
|
.move(new Point(0,0))
|
||||||
.line(new freesewing.Point(10,10))
|
.line(new Point(10,10))
|
||||||
.shiftAlong()
|
.shiftAlong()
|
||||||
expect(invalid).to.equal(true);
|
expect(invalid).to.equal(true);
|
||||||
});
|
});
|
||||||
|
@ -1115,11 +1114,11 @@ describe('Path', () => {
|
||||||
warning: () => invalid = true,
|
warning: () => invalid = true,
|
||||||
}
|
}
|
||||||
expect(invalid).to.equal(false);
|
expect(invalid).to.equal(false);
|
||||||
new freesewing.Path()
|
new Path()
|
||||||
.withRaise(raise)
|
.withRaise(raise)
|
||||||
.move(new freesewing.Point(0,0).withRaise(raise))
|
.move(new Point(0,0).withRaise(raise))
|
||||||
.line(new freesewing.Point(10,10).withRaise(raise))
|
.line(new Point(10,10).withRaise(raise))
|
||||||
.line(new freesewing.Point(10,20).withRaise(raise))
|
.line(new Point(10,20).withRaise(raise))
|
||||||
.shiftFractionAlong()
|
.shiftFractionAlong()
|
||||||
expect(invalid).to.equal(true);
|
expect(invalid).to.equal(true);
|
||||||
});
|
});
|
||||||
|
@ -1130,11 +1129,11 @@ describe('Path', () => {
|
||||||
error: () => invalid = true,
|
error: () => invalid = true,
|
||||||
warning: () => invalid = true,
|
warning: () => invalid = true,
|
||||||
}
|
}
|
||||||
const from = new freesewing.Point(0,0).withRaise(raise)
|
const from = new Point(0,0).withRaise(raise)
|
||||||
const cp1 = new freesewing.Point(10,0).withRaise(raise)
|
const cp1 = new Point(10,0).withRaise(raise)
|
||||||
const cp2 = new freesewing.Point(90,0).withRaise(raise)
|
const cp2 = new Point(90,0).withRaise(raise)
|
||||||
const to = new freesewing.Point(100,0).withRaise(raise)
|
const to = new Point(100,0).withRaise(raise)
|
||||||
const path = new freesewing.Path()
|
const path = new Path()
|
||||||
.withRaise(raise)
|
.withRaise(raise)
|
||||||
.move(from)
|
.move(from)
|
||||||
.curve(cp1, cp2, to)
|
.curve(cp1, cp2, to)
|
||||||
|
@ -1155,11 +1154,11 @@ describe('Path', () => {
|
||||||
error: () => invalid = true,
|
error: () => invalid = true,
|
||||||
warning: () => invalid = true,
|
warning: () => invalid = true,
|
||||||
}
|
}
|
||||||
const from = new freesewing.Point(0,0).withRaise(raise)
|
const from = new Point(0,0).withRaise(raise)
|
||||||
const cp1 = new freesewing.Point(10,0).withRaise(raise)
|
const cp1 = new Point(10,0).withRaise(raise)
|
||||||
const cp2 = new freesewing.Point(90,0).withRaise(raise)
|
const cp2 = new Point(90,0).withRaise(raise)
|
||||||
const to = new freesewing.Point(100,0).withRaise(raise)
|
const to = new Point(100,0).withRaise(raise)
|
||||||
const path = new freesewing.Path()
|
const path = new Path()
|
||||||
.withRaise(raise)
|
.withRaise(raise)
|
||||||
.move(from)
|
.move(from)
|
||||||
.curve(cp1, cp2, to)
|
.curve(cp1, cp2, to)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import chai from "chai"
|
import chai from "chai"
|
||||||
import freesewing from "./dist/index.mjs"
|
import { round, Pattern, Design, pctBasedOn } from "./dist/index.mjs"
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
describe('Pattern', () => {
|
describe('Pattern', () => {
|
||||||
it("Pattern constructor should initialize object", () => {
|
it("Pattern constructor should initialize object", () => {
|
||||||
let pattern = new freesewing.Pattern({
|
let pattern = new Pattern({
|
||||||
foo: "bar",
|
foo: "bar",
|
||||||
options: {
|
options: {
|
||||||
constant: 2,
|
constant: 2,
|
||||||
|
@ -24,7 +24,7 @@ describe('Pattern', () => {
|
||||||
|
|
||||||
|
|
||||||
it("Should load percentage options", () => {
|
it("Should load percentage options", () => {
|
||||||
let pattern = new freesewing.Pattern({
|
let pattern = new Pattern({
|
||||||
options: {
|
options: {
|
||||||
test: { pct: 30 }
|
test: { pct: 30 }
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ describe('Pattern', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should load millimeter options", () => {
|
it("Should load millimeter options", () => {
|
||||||
let pattern = new freesewing.Pattern({
|
let pattern = new Pattern({
|
||||||
options: {
|
options: {
|
||||||
test: { mm: 30 }
|
test: { mm: 30 }
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ describe('Pattern', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should load degree options", () => {
|
it("Should load degree options", () => {
|
||||||
let pattern = new freesewing.Pattern({
|
let pattern = new Pattern({
|
||||||
options: {
|
options: {
|
||||||
test: { deg: 15 }
|
test: { deg: 15 }
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ describe('Pattern', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should load an array option", () => {
|
it("Should load an array option", () => {
|
||||||
let pattern = new freesewing.Pattern({
|
let pattern = new Pattern({
|
||||||
options: {
|
options: {
|
||||||
test: { dflt: "foo" }
|
test: { dflt: "foo" }
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ describe('Pattern', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should load a count option", () => {
|
it("Should load a count option", () => {
|
||||||
let pattern = new freesewing.Pattern({
|
let pattern = new Pattern({
|
||||||
options: {
|
options: {
|
||||||
test: { count: 3 }
|
test: { count: 3 }
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ describe('Pattern', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should load a boolean option", () => {
|
it("Should load a boolean option", () => {
|
||||||
let pattern = new freesewing.Pattern({
|
let pattern = new Pattern({
|
||||||
options: {
|
options: {
|
||||||
test1: { bool: false },
|
test1: { bool: false },
|
||||||
test2: { bool: true }
|
test2: { bool: true }
|
||||||
|
@ -82,7 +82,7 @@ describe('Pattern', () => {
|
||||||
it("Should throw an error for an unknown option", () => {
|
it("Should throw an error for an unknown option", () => {
|
||||||
expect(
|
expect(
|
||||||
() =>
|
() =>
|
||||||
new freesewing.Pattern({
|
new Pattern({
|
||||||
options: {
|
options: {
|
||||||
test: { foo: "bar" }
|
test: { foo: "bar" }
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ describe('Pattern', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should merge settings with default settings", () => {
|
it("Should merge settings with default settings", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let settings = {
|
let settings = {
|
||||||
foo: "bar",
|
foo: "bar",
|
||||||
deep: {
|
deep: {
|
||||||
|
@ -124,7 +124,7 @@ describe('Pattern', () => {
|
||||||
return part;
|
return part;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const Test = new freesewing.Design({
|
const Test = new Design({
|
||||||
name: "test",
|
name: "test",
|
||||||
parts: [ back, front ],
|
parts: [ back, front ],
|
||||||
});
|
});
|
||||||
|
@ -135,7 +135,7 @@ describe('Pattern', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should sample an option", () => {
|
it("Should sample an option", () => {
|
||||||
let pattern = new freesewing.Pattern({
|
let pattern = new Pattern({
|
||||||
options: {
|
options: {
|
||||||
len: { pct: 30, min: 10 },
|
len: { pct: 30, min: 10 },
|
||||||
bonus: 10
|
bonus: 10
|
||||||
|
@ -284,7 +284,7 @@ describe('Pattern', () => {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
it("Should register a hook via on", () => {
|
it("Should register a hook via on", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let count = 0;
|
let count = 0;
|
||||||
pattern._draft = () => {};
|
pattern._draft = () => {};
|
||||||
pattern.on("preDraft", function(pattern) {
|
pattern.on("preDraft", function(pattern) {
|
||||||
|
@ -295,7 +295,7 @@ describe('Pattern', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should register a hook from a plugin", () => {
|
it("Should register a hook from a plugin", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let count = 0;
|
let count = 0;
|
||||||
pattern._draft = () => {};
|
pattern._draft = () => {};
|
||||||
let plugin = {
|
let plugin = {
|
||||||
|
@ -313,7 +313,7 @@ describe('Pattern', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should register multiple methods on a single hook", () => {
|
it("Should register multiple methods on a single hook", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let count = 0;
|
let count = 0;
|
||||||
pattern._draft = () => {};
|
pattern._draft = () => {};
|
||||||
let plugin = {
|
let plugin = {
|
||||||
|
@ -342,7 +342,7 @@ describe('Pattern', () => {
|
||||||
inject: { back: "front" },
|
inject: { back: "front" },
|
||||||
hide: ["back"]
|
hide: ["back"]
|
||||||
};
|
};
|
||||||
const Test = new freesewing.Design(config)
|
const Test = new Design(config)
|
||||||
Test.prototype.draftBack = function(part) {
|
Test.prototype.draftBack = function(part) {
|
||||||
return part;
|
return part;
|
||||||
};
|
};
|
||||||
|
@ -369,10 +369,10 @@ describe('Pattern', () => {
|
||||||
hide: ["back"]
|
hide: ["back"]
|
||||||
};
|
};
|
||||||
const Test = function(settings = false) {
|
const Test = function(settings = false) {
|
||||||
freesewing.Pattern.call(this, config);
|
Pattern.call(this, config);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
Test.prototype = Object.create(freesewing.Pattern.prototype);
|
Test.prototype = Object.create(Pattern.prototype);
|
||||||
Test.prototype.constructor = Test;
|
Test.prototype.constructor = Test;
|
||||||
Test.prototype.draftBack = function(part) {
|
Test.prototype.draftBack = function(part) {
|
||||||
return part;
|
return part;
|
||||||
|
@ -397,8 +397,8 @@ describe('Pattern', () => {
|
||||||
name: "test",
|
name: "test",
|
||||||
dependencies: { front: "back", side: "back", hood: "front", stripe: "hood" },
|
dependencies: { front: "back", side: "back", hood: "front", stripe: "hood" },
|
||||||
};
|
};
|
||||||
const Test = new freesewing.Design(config)
|
const Test = new Design(config)
|
||||||
Test.prototype = Object.create(freesewing.Pattern.prototype);
|
Test.prototype = Object.create(Pattern.prototype);
|
||||||
Test.prototype.constructor = Test;
|
Test.prototype.constructor = Test;
|
||||||
Test.prototype.draftBack = function(part) {
|
Test.prototype.draftBack = function(part) {
|
||||||
return part;
|
return part;
|
||||||
|
@ -432,10 +432,10 @@ describe('Pattern', () => {
|
||||||
dependencies: { front: ["back"], side: ["back"], hood: ["front"], stripe: ["hood"]},
|
dependencies: { front: ["back"], side: ["back"], hood: ["front"], stripe: ["hood"]},
|
||||||
};
|
};
|
||||||
const Test = function(settings = false) {
|
const Test = function(settings = false) {
|
||||||
freesewing.Pattern.call(this, config);
|
Pattern.call(this, config);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
Test.prototype = Object.create(freesewing.Pattern.prototype);
|
Test.prototype = Object.create(Pattern.prototype);
|
||||||
Test.prototype.constructor = Test;
|
Test.prototype.constructor = Test;
|
||||||
Test.prototype.draftBack = function(part) {
|
Test.prototype.draftBack = function(part) {
|
||||||
return part;
|
return part;
|
||||||
|
@ -470,10 +470,10 @@ describe('Pattern', () => {
|
||||||
parts: ['back','front','crotch'],
|
parts: ['back','front','crotch'],
|
||||||
};
|
};
|
||||||
const Test = function(settings = false) {
|
const Test = function(settings = false) {
|
||||||
freesewing.Pattern.call(this, config);
|
Pattern.call(this, config);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
Test.prototype = Object.create(freesewing.Pattern.prototype);
|
Test.prototype = Object.create(Pattern.prototype);
|
||||||
Test.prototype.constructor = Test;
|
Test.prototype.constructor = Test;
|
||||||
Test.prototype.draftBack = function(part) {
|
Test.prototype.draftBack = function(part) {
|
||||||
return part;
|
return part;
|
||||||
|
@ -495,10 +495,10 @@ describe('Pattern', () => {
|
||||||
parts: ['back','front','crotch'],
|
parts: ['back','front','crotch'],
|
||||||
};
|
};
|
||||||
const Test = function(settings = false) {
|
const Test = function(settings = false) {
|
||||||
freesewing.Pattern.call(this, config);
|
Pattern.call(this, config);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
Test.prototype = Object.create(freesewing.Pattern.prototype);
|
Test.prototype = Object.create(Pattern.prototype);
|
||||||
Test.prototype.constructor = Test;
|
Test.prototype.constructor = Test;
|
||||||
Test.prototype.draftBack = function(part) {
|
Test.prototype.draftBack = function(part) {
|
||||||
return part;
|
return part;
|
||||||
|
@ -527,10 +527,10 @@ describe('Pattern', () => {
|
||||||
parts: ['back','front','crotch'],
|
parts: ['back','front','crotch'],
|
||||||
};
|
};
|
||||||
const Test = function(settings = false) {
|
const Test = function(settings = false) {
|
||||||
freesewing.Pattern.call(this, config);
|
Pattern.call(this, config);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
Test.prototype = Object.create(freesewing.Pattern.prototype);
|
Test.prototype = Object.create(Pattern.prototype);
|
||||||
Test.prototype.constructor = Test;
|
Test.prototype.constructor = Test;
|
||||||
Test.prototype.draftBack = function(part) {
|
Test.prototype.draftBack = function(part) {
|
||||||
return part;
|
return part;
|
||||||
|
@ -547,13 +547,13 @@ describe('Pattern', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should check whether created parts get the pattern context", () => {
|
it("Should check whether created parts get the pattern context", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
expect(part.context.settings).to.equal(pattern.settings);
|
expect(part.context.settings).to.equal(pattern.settings);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should correctly merge settings", () => {
|
it("Should correctly merge settings", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let settings = {
|
let settings = {
|
||||||
complete: false,
|
complete: false,
|
||||||
only: [1, 2, 3],
|
only: [1, 2, 3],
|
||||||
|
@ -567,7 +567,7 @@ describe('Pattern', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should correctly merge settings for existing array", () => {
|
it("Should correctly merge settings for existing array", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.settings.only = [1];
|
pattern.settings.only = [1];
|
||||||
let settings = {
|
let settings = {
|
||||||
complete: false,
|
complete: false,
|
||||||
|
@ -585,7 +585,7 @@ describe('Pattern', () => {
|
||||||
name: 'front',
|
name: 'front',
|
||||||
draft: function(part) { return part }
|
draft: function(part) { return part }
|
||||||
}
|
}
|
||||||
const Test = new freesewing.Design({
|
const Test = new Design({
|
||||||
name: "test",
|
name: "test",
|
||||||
parts: [front],
|
parts: [front],
|
||||||
});
|
});
|
||||||
|
@ -599,7 +599,7 @@ describe('Pattern', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not pack a pattern with errors", () => {
|
it("Should not pack a pattern with errors", () => {
|
||||||
const pattern = new freesewing.Pattern()
|
const pattern = new Pattern()
|
||||||
pattern.events.error.push('error')
|
pattern.events.error.push('error')
|
||||||
pattern.pack()
|
pattern.pack()
|
||||||
expect(pattern.events.warning.length).to.equal(1)
|
expect(pattern.events.warning.length).to.equal(1)
|
||||||
|
@ -633,7 +633,7 @@ describe('Pattern', () => {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
it("Should handle custom layouts", () => {
|
it("Should handle custom layouts", () => {
|
||||||
const Test = new freesewing.Design({ name: "test", parts: ['front'] })
|
const Test = new Design({ name: "test", parts: ['front'] })
|
||||||
Test.prototype.draftFront = function(part) { return part }
|
Test.prototype.draftFront = function(part) { return part }
|
||||||
const pattern = new Test({
|
const pattern = new Test({
|
||||||
layout: {
|
layout: {
|
||||||
|
@ -648,12 +648,12 @@ describe('Pattern', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should handle a simple snapped option", () => {
|
it("Should handle a simple snapped option", () => {
|
||||||
const Test = new freesewing.Design({
|
const Test = new Design({
|
||||||
name: "test",
|
name: "test",
|
||||||
parts: ['front'],
|
parts: ['front'],
|
||||||
measurements: [ 'head' ],
|
measurements: [ 'head' ],
|
||||||
options: {
|
options: {
|
||||||
len: { pct: 50, min: 22, max: 78, snap: 10, ...freesewing.pctBasedOn('head') }
|
len: { pct: 50, min: 22, max: 78, snap: 10, ...pctBasedOn('head') }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Test.prototype.draftFront = function(part) {
|
Test.prototype.draftFront = function(part) {
|
||||||
|
@ -691,7 +691,7 @@ describe('Pattern', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should handle a list snapped option", () => {
|
it("Should handle a list snapped option", () => {
|
||||||
const Test = new freesewing.Design({
|
const Test = new Design({
|
||||||
name: "test",
|
name: "test",
|
||||||
parts: [
|
parts: [
|
||||||
{
|
{
|
||||||
|
@ -710,7 +710,7 @@ describe('Pattern', () => {
|
||||||
],
|
],
|
||||||
measurements: [ 'head' ],
|
measurements: [ 'head' ],
|
||||||
options: {
|
options: {
|
||||||
len: { pct: 50, min: 22, max: 78, snap: [10,14,19,28], ...freesewing.pctBasedOn('head') }
|
len: { pct: 50, min: 22, max: 78, snap: [10,14,19,28], ...pctBasedOn('head') }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
let pattern = new Test({
|
let pattern = new Test({
|
||||||
|
@ -734,12 +734,12 @@ describe('Pattern', () => {
|
||||||
expect(pattern.parts.front.paths.line_7.ops[1].to.x).to.equal(28);
|
expect(pattern.parts.front.paths.line_7.ops[1].to.x).to.equal(28);
|
||||||
expect(pattern.parts.front.paths.line_8.ops[1].to.x).to.equal(28);
|
expect(pattern.parts.front.paths.line_8.ops[1].to.x).to.equal(28);
|
||||||
expect(pattern.parts.front.paths.line_9.ops[1].to.x).to.equal(28);
|
expect(pattern.parts.front.paths.line_9.ops[1].to.x).to.equal(28);
|
||||||
expect(freesewing.utils.round(pattern.parts.front.paths.line_10.ops[1].to.x)).to.equal(33.72);
|
expect(round(pattern.parts.front.paths.line_10.ops[1].to.x)).to.equal(33.72);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it("Should retrieve the cutList", () => {
|
it("Should retrieve the cutList", () => {
|
||||||
const Test = new freesewing.Design({
|
const Test = new Design({
|
||||||
name: "test",
|
name: "test",
|
||||||
parts: [{
|
parts: [{
|
||||||
name: 'front',
|
name: 'front',
|
||||||
|
@ -818,8 +818,8 @@ describe('Pattern', () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Design = new freesewing.Design({ parts: [ partC ] });
|
const design = new Design({ parts: [ partC ] });
|
||||||
const pattern = new Design().addPart(partR).draft()
|
const pattern = new design().addPart(partR).draft()
|
||||||
// Measurements
|
// Measurements
|
||||||
expect(pattern.config.measurements.length).to.equal(4)
|
expect(pattern.config.measurements.length).to.equal(4)
|
||||||
expect(pattern.config.measurements.indexOf('measieA') === -1).to.equal(false)
|
expect(pattern.config.measurements.indexOf('measieA') === -1).to.equal(false)
|
||||||
|
@ -970,8 +970,8 @@ describe('Pattern', () => {
|
||||||
return part
|
return part
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const Design = new freesewing.Design({ parts: [ partD ] });
|
const design = new Design({ parts: [ partD ] });
|
||||||
const pattern = new Design().draft()
|
const pattern = new design().draft()
|
||||||
// Measurements
|
// Measurements
|
||||||
expect(pattern.config.measurements.length).to.equal(4)
|
expect(pattern.config.measurements.length).to.equal(4)
|
||||||
expect(pattern.config.measurements.indexOf('measieA') === -1).to.equal(false)
|
expect(pattern.config.measurements.indexOf('measieA') === -1).to.equal(false)
|
||||||
|
@ -1120,10 +1120,10 @@ describe('Pattern', () => {
|
||||||
},
|
},
|
||||||
draft: part => part,
|
draft: part => part,
|
||||||
}
|
}
|
||||||
let Design, pattern
|
let design, pattern
|
||||||
try {
|
try {
|
||||||
Design = new freesewing.Design({ parts: [ partB ] });
|
design = new Design({ parts: [ partB ] });
|
||||||
pattern = new Design().init()
|
pattern = new design().init()
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import chai from "chai"
|
import chai from "chai"
|
||||||
import freesewing from "./dist/index.mjs"
|
import { round, Point } from "./dist/index.mjs"
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
const Point = freesewing.Point
|
|
||||||
const round = freesewing.utils.round
|
|
||||||
|
|
||||||
describe('Point', () => {
|
describe('Point', () => {
|
||||||
it("Should return point object", () => {
|
it("Should return point object", () => {
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
import chai from "chai"
|
import chai from "chai"
|
||||||
import freesewing from "./dist/index.mjs"
|
import { Snippet, Point } from "./dist/index.mjs"
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
describe('Snippet', () => {
|
describe('Snippet', () => {
|
||||||
it("Should create a snippet", () => {
|
it("Should create a snippet", () => {
|
||||||
let snip1 = new freesewing.Snippet("test", new freesewing.Point(12, 34));
|
let snip1 = new Snippet("test", new Point(12, 34));
|
||||||
expect(snip1.def).to.equal("test");
|
expect(snip1.def).to.equal("test");
|
||||||
expect(snip1.anchor.x).to.equal(12);
|
expect(snip1.anchor.x).to.equal(12);
|
||||||
expect(snip1.anchor.y).to.equal(34);
|
expect(snip1.anchor.y).to.equal(34);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should clone a snippet", () => {
|
it("Should clone a snippet", () => {
|
||||||
let snip3 = new freesewing.Snippet("boo", new freesewing.Point(56, 78));
|
let snip3 = new Snippet("boo", new Point(56, 78));
|
||||||
expect(snip3.clone().def).to.equal("boo");
|
expect(snip3.clone().def).to.equal("boo");
|
||||||
expect(snip3.clone().anchor.x).to.equal(56);
|
expect(snip3.clone().anchor.x).to.equal(56);
|
||||||
expect(snip3.clone().anchor.y).to.equal(78);
|
expect(snip3.clone().anchor.y).to.equal(78);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should set an attribute", () => {
|
it("Should set an attribute", () => {
|
||||||
let s = new freesewing.Snippet("test", new freesewing.Point(12, -34)).attr(
|
let s = new Snippet("test", new Point(12, -34)).attr(
|
||||||
"class",
|
"class",
|
||||||
"test"
|
"test"
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import chai from "chai"
|
import chai from "chai"
|
||||||
import freesewing from "./dist/index.mjs"
|
import { Pattern } from "./dist/index.mjs"
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
const pattern = new freesewing.Pattern();
|
const pattern = new Pattern();
|
||||||
const store = pattern.store;
|
const store = pattern.store;
|
||||||
|
|
||||||
describe('Store', () => {
|
describe('Store', () => {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import chai from "chai"
|
import chai from "chai"
|
||||||
import chaiString from "chai-string"
|
import chaiString from "chai-string"
|
||||||
import freesewing from "./dist/index.mjs"
|
import { Pattern } from "./dist/index.mjs"
|
||||||
import pkg from '../package.json' assert { type: 'json' }
|
import pkg from '../package.json' assert { type: 'json' }
|
||||||
import render from "./fixtures/render.mjs"
|
import render from "./fixtures/render.mjs"
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ const { version } = pkg
|
||||||
|
|
||||||
describe('Svg', () => {
|
describe('Svg', () => {
|
||||||
it("Svg constructor should initialize object", () => {
|
it("Svg constructor should initialize object", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.render();
|
pattern.render();
|
||||||
let svg = pattern.svg;
|
let svg = pattern.svg;
|
||||||
expect(svg.openGroups).to.eql([]);
|
expect(svg.openGroups).to.eql([]);
|
||||||
|
@ -37,24 +37,24 @@ describe('Svg', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should render Svg boilerplate", () => {
|
it("Should render Svg boilerplate", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
expect(pattern.render()).to.equalIgnoreSpaces(render.boilerplate);
|
expect(pattern.render()).to.equalIgnoreSpaces(render.boilerplate);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should render language attribute", () => {
|
it("Should render language attribute", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.settings.locale = "nl";
|
pattern.settings.locale = "nl";
|
||||||
expect(pattern.render()).to.equalIgnoreSpaces(render.boilerplateNl);
|
expect(pattern.render()).to.equalIgnoreSpaces(render.boilerplateNl);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should render Svg boilerplate for embedding", () => {
|
it("Should render Svg boilerplate for embedding", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.settings.embed = true;
|
pattern.settings.embed = true;
|
||||||
expect(pattern.render()).to.equalIgnoreSpaces(render.embed);
|
expect(pattern.render()).to.equalIgnoreSpaces(render.embed);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should render Svg part boilerplate", () => {
|
it("Should render Svg part boilerplate", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.render();
|
pattern.render();
|
||||||
pattern.parts.test = new pattern.Part();
|
pattern.parts.test = new pattern.Part();
|
||||||
expect(pattern.render()).to.equalIgnoreSpaces(render.part);
|
expect(pattern.render()).to.equalIgnoreSpaces(render.part);
|
||||||
|
@ -63,7 +63,7 @@ describe('Svg', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should render Svg path", () => {
|
it("Should render Svg path", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.render();
|
pattern.render();
|
||||||
pattern.parts.test = new pattern.Part();
|
pattern.parts.test = new pattern.Part();
|
||||||
let p = pattern.parts.test;
|
let p = pattern.parts.test;
|
||||||
|
@ -77,7 +77,7 @@ describe('Svg', () => {
|
||||||
expect(pattern.render()).to.equalIgnoreSpaces(render.path);
|
expect(pattern.render()).to.equalIgnoreSpaces(render.path);
|
||||||
});
|
});
|
||||||
it("Should not render Svg path when render property is false", () => {
|
it("Should not render Svg path when render property is false", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.render();
|
pattern.render();
|
||||||
pattern.parts.test = new pattern.Part();
|
pattern.parts.test = new pattern.Part();
|
||||||
let p = pattern.parts.test;
|
let p = pattern.parts.test;
|
||||||
|
@ -93,7 +93,7 @@ describe('Svg', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should render Svg text", () => {
|
it("Should render Svg text", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.render();
|
pattern.render();
|
||||||
pattern.parts.test = new pattern.Part();
|
pattern.parts.test = new pattern.Part();
|
||||||
let p = pattern.parts.test;
|
let p = pattern.parts.test;
|
||||||
|
@ -105,7 +105,7 @@ describe('Svg', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should render Svg multi-line text", () => {
|
it("Should render Svg multi-line text", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.render();
|
pattern.render();
|
||||||
pattern.parts.test = new pattern.Part();
|
pattern.parts.test = new pattern.Part();
|
||||||
let p = pattern.parts.test;
|
let p = pattern.parts.test;
|
||||||
|
@ -117,7 +117,7 @@ describe('Svg', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should render Svg multi-line text with default lineheight", () => {
|
it("Should render Svg multi-line text with default lineheight", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.render();
|
pattern.render();
|
||||||
pattern.parts.test = new pattern.Part();
|
pattern.parts.test = new pattern.Part();
|
||||||
let p = pattern.parts.test;
|
let p = pattern.parts.test;
|
||||||
|
@ -128,7 +128,7 @@ describe('Svg', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not render text when there is none", () => {
|
it("Should not render text when there is none", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.render();
|
pattern.render();
|
||||||
pattern.parts.test = new pattern.Part();
|
pattern.parts.test = new pattern.Part();
|
||||||
let p = pattern.parts.test;
|
let p = pattern.parts.test;
|
||||||
|
@ -137,7 +137,7 @@ describe('Svg', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should render Svg text on path", () => {
|
it("Should render Svg text on path", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.render();
|
pattern.render();
|
||||||
pattern.parts.test = new pattern.Part();
|
pattern.parts.test = new pattern.Part();
|
||||||
let p = pattern.parts.test;
|
let p = pattern.parts.test;
|
||||||
|
@ -153,7 +153,7 @@ describe('Svg', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should render Svg text on path, center aligned", () => {
|
it("Should render Svg text on path, center aligned", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.render();
|
pattern.render();
|
||||||
pattern.parts.test = new pattern.Part();
|
pattern.parts.test = new pattern.Part();
|
||||||
let p = pattern.parts.test;
|
let p = pattern.parts.test;
|
||||||
|
@ -169,7 +169,7 @@ describe('Svg', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should render Svg text on path, right aligned", () => {
|
it("Should render Svg text on path, right aligned", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.render();
|
pattern.render();
|
||||||
pattern.parts.test = new pattern.Part();
|
pattern.parts.test = new pattern.Part();
|
||||||
let p = pattern.parts.test;
|
let p = pattern.parts.test;
|
||||||
|
@ -185,7 +185,7 @@ describe('Svg', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should render an Svg circle", () => {
|
it("Should render an Svg circle", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.render();
|
pattern.render();
|
||||||
pattern.parts.test = new pattern.Part();
|
pattern.parts.test = new pattern.Part();
|
||||||
let p = pattern.parts.test;
|
let p = pattern.parts.test;
|
||||||
|
@ -194,7 +194,7 @@ describe('Svg', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should render an Svg snippet", () => {
|
it("Should render an Svg snippet", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.render();
|
pattern.render();
|
||||||
pattern.parts.test = new pattern.Part();
|
pattern.parts.test = new pattern.Part();
|
||||||
let p = pattern.parts.test;
|
let p = pattern.parts.test;
|
||||||
|
@ -207,7 +207,7 @@ describe('Svg', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should render a rotated Svg snippet", () => {
|
it("Should render a rotated Svg snippet", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.render();
|
pattern.render();
|
||||||
pattern.parts.test = new pattern.Part();
|
pattern.parts.test = new pattern.Part();
|
||||||
let p = pattern.parts.test;
|
let p = pattern.parts.test;
|
||||||
|
@ -220,7 +220,7 @@ describe('Svg', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should replaced double quotes in Svg text", () => {
|
it("Should replaced double quotes in Svg text", () => {
|
||||||
const pattern = new freesewing.Pattern()
|
const pattern = new Pattern()
|
||||||
pattern.render()
|
pattern.render()
|
||||||
expect(
|
expect(
|
||||||
pattern.svg.escapeText('This is a "test" message')
|
pattern.svg.escapeText('This is a "test" message')
|
||||||
|
@ -228,7 +228,7 @@ describe('Svg', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should scale an Svg snippet", () => {
|
it("Should scale an Svg snippet", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.render();
|
pattern.render();
|
||||||
pattern.parts.test = new pattern.Part();
|
pattern.parts.test = new pattern.Part();
|
||||||
let p = pattern.parts.test;
|
let p = pattern.parts.test;
|
||||||
|
@ -241,7 +241,7 @@ describe('Svg', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should run preRender hook", () => {
|
it("Should run preRender hook", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.on("preRender", svg => {
|
pattern.on("preRender", svg => {
|
||||||
svg.attributes.set("data-hook", "preRender");
|
svg.attributes.set("data-hook", "preRender");
|
||||||
});
|
});
|
||||||
|
@ -250,7 +250,7 @@ describe('Svg', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should run insertText hook", () => {
|
it("Should run insertText hook", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.on("insertText", (locale, text) => {
|
pattern.on("insertText", (locale, text) => {
|
||||||
return text.toUpperCase();
|
return text.toUpperCase();
|
||||||
});
|
});
|
||||||
|
@ -263,7 +263,7 @@ describe('Svg', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should run postRender hook", () => {
|
it("Should run postRender hook", () => {
|
||||||
let pattern = new freesewing.Pattern()
|
let pattern = new Pattern()
|
||||||
pattern.on("postRender", svg => {
|
pattern.on("postRender", svg => {
|
||||||
svg.svg = "test";
|
svg.svg = "test";
|
||||||
});
|
});
|
||||||
|
@ -271,7 +271,7 @@ describe('Svg', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should tab in and out", () => {
|
it("Should tab in and out", () => {
|
||||||
let pattern = new freesewing.Pattern()
|
let pattern = new Pattern()
|
||||||
pattern.render()
|
pattern.render()
|
||||||
const svg = pattern.svg
|
const svg = pattern.svg
|
||||||
svg.tabs = 2
|
svg.tabs = 2
|
||||||
|
|
|
@ -1,221 +1,250 @@
|
||||||
import chai from "chai"
|
import chai from "chai"
|
||||||
import freesewing from "./dist/index.mjs"
|
import {
|
||||||
|
Pattern,
|
||||||
|
Point,
|
||||||
|
isCoord,
|
||||||
|
capitalize,
|
||||||
|
beamsIntersect,
|
||||||
|
linesIntersect,
|
||||||
|
pointOnBeam,
|
||||||
|
pointOnLine,
|
||||||
|
pointOnCurve,
|
||||||
|
splitCurve,
|
||||||
|
beamIntersectsX,
|
||||||
|
beamIntersectsY,
|
||||||
|
units,
|
||||||
|
lineIntersectsCurve,
|
||||||
|
curveIntersectsX,
|
||||||
|
curveIntersectsY,
|
||||||
|
curvesIntersect,
|
||||||
|
circlesIntersect,
|
||||||
|
beamIntersectsCircle,
|
||||||
|
lineIntersectsCircle,
|
||||||
|
curveEdge,
|
||||||
|
stretchToScale,
|
||||||
|
round,
|
||||||
|
sampleStyle,
|
||||||
|
deg2rad,
|
||||||
|
rad2deg,
|
||||||
|
pctBasedOn,
|
||||||
|
Bezier,
|
||||||
|
generatePartTransform,
|
||||||
|
macroName,
|
||||||
|
} from "./dist/index.mjs"
|
||||||
|
|
||||||
const { expect } = chai
|
const { expect } = chai
|
||||||
const utils = freesewing.utils
|
|
||||||
const round = utils.round
|
|
||||||
|
|
||||||
describe('Utils', () => {
|
describe('Utils', () => {
|
||||||
it("Should return the correct macro name", () => {
|
it("Should return the correct macro name", () => {
|
||||||
expect(utils.macroName("test")).to.equal("_macro_test");
|
expect(macroName("test")).to.equal("_macro_test");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find the intersection of two endless line segments", () => {
|
it("Should find the intersection of two endless line segments", () => {
|
||||||
let a = new freesewing.Point(10, 20);
|
let a = new Point(10, 20);
|
||||||
let b = new freesewing.Point(20, 24);
|
let b = new Point(20, 24);
|
||||||
let c = new freesewing.Point(90, 19);
|
let c = new Point(90, 19);
|
||||||
let d = new freesewing.Point(19, 70);
|
let d = new Point(19, 70);
|
||||||
let X = freesewing.utils.beamsIntersect(a, b, c, d);
|
let X = beamsIntersect(a, b, c, d);
|
||||||
expect(round(X.x)).to.equal(60.49);
|
expect(round(X.x)).to.equal(60.49);
|
||||||
expect(round(X.y)).to.equal(40.2);
|
expect(round(X.y)).to.equal(40.2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should detect parallel lines", () => {
|
it("Should detect parallel lines", () => {
|
||||||
let a = new freesewing.Point(10, 20);
|
let a = new Point(10, 20);
|
||||||
let b = new freesewing.Point(20, 20);
|
let b = new Point(20, 20);
|
||||||
let c = new freesewing.Point(90, 40);
|
let c = new Point(90, 40);
|
||||||
let d = new freesewing.Point(19, 40);
|
let d = new Point(19, 40);
|
||||||
expect(freesewing.utils.beamsIntersect(a, b, c, d)).to.equal(false);
|
expect(beamsIntersect(a, b, c, d)).to.equal(false);
|
||||||
expect(freesewing.utils.linesIntersect(a, b, c, d)).to.equal(false);
|
expect(linesIntersect(a, b, c, d)).to.equal(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should detect vertical lines", () => {
|
it("Should detect vertical lines", () => {
|
||||||
let a = new freesewing.Point(10, 20);
|
let a = new Point(10, 20);
|
||||||
let b = new freesewing.Point(10, 90);
|
let b = new Point(10, 90);
|
||||||
let c = new freesewing.Point(90, 40);
|
let c = new Point(90, 40);
|
||||||
let d = new freesewing.Point(19, 40);
|
let d = new Point(19, 40);
|
||||||
let X = freesewing.utils.beamsIntersect(a, b, c, d);
|
let X = beamsIntersect(a, b, c, d);
|
||||||
expect(X.x).to.equal(10);
|
expect(X.x).to.equal(10);
|
||||||
expect(X.y).to.equal(40);
|
expect(X.y).to.equal(40);
|
||||||
X = freesewing.utils.beamsIntersect(c, d, a, b);
|
X = beamsIntersect(c, d, a, b);
|
||||||
expect(X.x).to.equal(10);
|
expect(X.x).to.equal(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should swap direction prior to finding beam intersection", () => {
|
it("Should swap direction prior to finding beam intersection", () => {
|
||||||
let a = new freesewing.Point(10, 20);
|
let a = new Point(10, 20);
|
||||||
let b = new freesewing.Point(0, 90);
|
let b = new Point(0, 90);
|
||||||
let c = new freesewing.Point(90, 40);
|
let c = new Point(90, 40);
|
||||||
let d = new freesewing.Point(19, 40);
|
let d = new Point(19, 40);
|
||||||
let X = freesewing.utils.beamsIntersect(a, b, c, d);
|
let X = beamsIntersect(a, b, c, d);
|
||||||
expect(round(X.x)).to.equal(7.14);
|
expect(round(X.x)).to.equal(7.14);
|
||||||
expect(round(X.y)).to.equal(40);
|
expect(round(X.y)).to.equal(40);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return false when two lines don't intersect", () => {
|
it("Should return false when two lines don't intersect", () => {
|
||||||
let a = new freesewing.Point(10, 20);
|
let a = new Point(10, 20);
|
||||||
let b = new freesewing.Point(20, 24);
|
let b = new Point(20, 24);
|
||||||
let c = new freesewing.Point(90, 19);
|
let c = new Point(90, 19);
|
||||||
let d = new freesewing.Point(19, 70);
|
let d = new Point(19, 70);
|
||||||
expect(freesewing.utils.linesIntersect(a, b, c, d)).to.equal(false);
|
expect(linesIntersect(a, b, c, d)).to.equal(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find the intersection of two line segments", () => {
|
it("Should find the intersection of two line segments", () => {
|
||||||
let a = new freesewing.Point(10, 10);
|
let a = new Point(10, 10);
|
||||||
let b = new freesewing.Point(90, 74);
|
let b = new Point(90, 74);
|
||||||
let c = new freesewing.Point(90, 19);
|
let c = new Point(90, 19);
|
||||||
let d = new freesewing.Point(11, 70);
|
let d = new Point(11, 70);
|
||||||
let X = freesewing.utils.linesIntersect(a, b, c, d);
|
let X = linesIntersect(a, b, c, d);
|
||||||
expect(round(X.x)).to.equal(51.95);
|
expect(round(X.x)).to.equal(51.95);
|
||||||
expect(round(X.y)).to.equal(43.56);
|
expect(round(X.y)).to.equal(43.56);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find the intersection of an endles line and a give X-value", () => {
|
it("Should find the intersection of an endles line and a give X-value", () => {
|
||||||
let a = new freesewing.Point(10, 10);
|
let a = new Point(10, 10);
|
||||||
let b = new freesewing.Point(90, 74);
|
let b = new Point(90, 74);
|
||||||
let X = freesewing.utils.beamIntersectsX(a, b, 69);
|
let X = beamIntersectsX(a, b, 69);
|
||||||
expect(X.x).to.equal(69);
|
expect(X.x).to.equal(69);
|
||||||
expect(X.y).to.equal(57.2);
|
expect(X.y).to.equal(57.2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find the intersection of an endles line and a give Y-value", () => {
|
it("Should find the intersection of an endles line and a give Y-value", () => {
|
||||||
let a = new freesewing.Point(10, 10);
|
let a = new Point(10, 10);
|
||||||
let b = new freesewing.Point(90, 74);
|
let b = new Point(90, 74);
|
||||||
let X = freesewing.utils.beamIntersectsY(a, b, 69);
|
let X = beamIntersectsY(a, b, 69);
|
||||||
expect(X.x).to.equal(83.75);
|
expect(X.x).to.equal(83.75);
|
||||||
expect(X.y).to.equal(69);
|
expect(X.y).to.equal(69);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should detect vertical lines never pass a give X-value", () => {
|
it("Should detect vertical lines never pass a give X-value", () => {
|
||||||
let a = new freesewing.Point(10, 10);
|
let a = new Point(10, 10);
|
||||||
let b = new freesewing.Point(10, 90);
|
let b = new Point(10, 90);
|
||||||
expect(freesewing.utils.beamIntersectsX(a, b, 69)).to.equal(false);
|
expect(beamIntersectsX(a, b, 69)).to.equal(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should detect horizontal lines never pass a give Y-value", () => {
|
it("Should detect horizontal lines never pass a give Y-value", () => {
|
||||||
let a = new freesewing.Point(10, 10);
|
let a = new Point(10, 10);
|
||||||
let b = new freesewing.Point(90, 10);
|
let b = new Point(90, 10);
|
||||||
expect(freesewing.utils.beamIntersectsY(a, b, 69)).to.equal(false);
|
expect(beamIntersectsY(a, b, 69)).to.equal(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find no intersections between a curve and a line", () => {
|
it("Should find no intersections between a curve and a line", () => {
|
||||||
let A = new freesewing.Point(10, 10);
|
let A = new Point(10, 10);
|
||||||
let Acp = new freesewing.Point(310, 40);
|
let Acp = new Point(310, 40);
|
||||||
let B = new freesewing.Point(110, 70);
|
let B = new Point(110, 70);
|
||||||
let Bcp = new freesewing.Point(-210, 40);
|
let Bcp = new Point(-210, 40);
|
||||||
let E = new freesewing.Point(-20, -20);
|
let E = new Point(-20, -20);
|
||||||
let D = new freesewing.Point(30, -85);
|
let D = new Point(30, -85);
|
||||||
|
|
||||||
let hit = freesewing.utils.lineIntersectsCurve(E, D, A, Acp, Bcp, B);
|
let hit = lineIntersectsCurve(E, D, A, Acp, Bcp, B);
|
||||||
expect(hit).to.equal(false);
|
expect(hit).to.equal(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find 1 intersection between a curve and a line", () => {
|
it("Should find 1 intersection between a curve and a line", () => {
|
||||||
let A = new freesewing.Point(10, 10);
|
let A = new Point(10, 10);
|
||||||
let Acp = new freesewing.Point(310, 40);
|
let Acp = new Point(310, 40);
|
||||||
let B = new freesewing.Point(110, 70);
|
let B = new Point(110, 70);
|
||||||
let Bcp = new freesewing.Point(-210, 40);
|
let Bcp = new Point(-210, 40);
|
||||||
let E = new freesewing.Point(20, 20);
|
let E = new Point(20, 20);
|
||||||
let D = new freesewing.Point(30, -85);
|
let D = new Point(30, -85);
|
||||||
|
|
||||||
let hit = freesewing.utils.lineIntersectsCurve(E, D, A, Acp, Bcp, B);
|
let hit = lineIntersectsCurve(E, D, A, Acp, Bcp, B);
|
||||||
expect(round(hit.x)).to.equal(20.85);
|
expect(round(hit.x)).to.equal(20.85);
|
||||||
expect(round(hit.y)).to.equal(11.11);
|
expect(round(hit.y)).to.equal(11.11);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find 3 intersections between a curve and a line", () => {
|
it("Should find 3 intersections between a curve and a line", () => {
|
||||||
let A = new freesewing.Point(10, 10);
|
let A = new Point(10, 10);
|
||||||
let Acp = new freesewing.Point(310, 40);
|
let Acp = new Point(310, 40);
|
||||||
let B = new freesewing.Point(110, 70);
|
let B = new Point(110, 70);
|
||||||
let Bcp = new freesewing.Point(-210, 40);
|
let Bcp = new Point(-210, 40);
|
||||||
let E = new freesewing.Point(20, -5);
|
let E = new Point(20, -5);
|
||||||
let D = new freesewing.Point(100, 85);
|
let D = new Point(100, 85);
|
||||||
|
|
||||||
let hits = freesewing.utils.lineIntersectsCurve(E, D, A, Acp, Bcp, B);
|
let hits = lineIntersectsCurve(E, D, A, Acp, Bcp, B);
|
||||||
expect(hits.length).to.equal(3);
|
expect(hits.length).to.equal(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find 9 intersections between two curves", () => {
|
it("Should find 9 intersections between two curves", () => {
|
||||||
let A = new freesewing.Point(10, 10);
|
let A = new Point(10, 10);
|
||||||
let Acp = new freesewing.Point(310, 40);
|
let Acp = new Point(310, 40);
|
||||||
let B = new freesewing.Point(110, 70);
|
let B = new Point(110, 70);
|
||||||
let Bcp = new freesewing.Point(-210, 40);
|
let Bcp = new Point(-210, 40);
|
||||||
let C = new freesewing.Point(20, -5);
|
let C = new Point(20, -5);
|
||||||
let Ccp = new freesewing.Point(60, 300);
|
let Ccp = new Point(60, 300);
|
||||||
let D = new freesewing.Point(100, 85);
|
let D = new Point(100, 85);
|
||||||
let Dcp = new freesewing.Point(70, -220);
|
let Dcp = new Point(70, -220);
|
||||||
|
|
||||||
let hits = freesewing.utils.curvesIntersect(A, Acp, Bcp, B, C, Ccp, Dcp, D);
|
let hits = curvesIntersect(A, Acp, Bcp, B, C, Ccp, Dcp, D);
|
||||||
expect(hits.length).to.equal(9);
|
expect(hits.length).to.equal(9);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find 1 intersection between two curves", () => {
|
it("Should find 1 intersection between two curves", () => {
|
||||||
let A = new freesewing.Point(10, 10);
|
let A = new Point(10, 10);
|
||||||
let Acp = new freesewing.Point(310, 40);
|
let Acp = new Point(310, 40);
|
||||||
let B = new freesewing.Point(110, 70);
|
let B = new Point(110, 70);
|
||||||
let Bcp = new freesewing.Point(-210, 40);
|
let Bcp = new Point(-210, 40);
|
||||||
let C = new freesewing.Point(20, -5);
|
let C = new Point(20, -5);
|
||||||
let Ccp = new freesewing.Point(-60, 300);
|
let Ccp = new Point(-60, 300);
|
||||||
let D = new freesewing.Point(-200, 85);
|
let D = new Point(-200, 85);
|
||||||
let Dcp = new freesewing.Point(-270, -220);
|
let Dcp = new Point(-270, -220);
|
||||||
|
|
||||||
let hit = freesewing.utils.curvesIntersect(A, Acp, Bcp, B, C, Ccp, Dcp, D);
|
let hit = curvesIntersect(A, Acp, Bcp, B, C, Ccp, Dcp, D);
|
||||||
expect(round(hit.x)).to.equal(15.58);
|
expect(round(hit.x)).to.equal(15.58);
|
||||||
expect(round(hit.y)).to.equal(10.56);
|
expect(round(hit.y)).to.equal(10.56);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find no intersection between two curves", () => {
|
it("Should find no intersection between two curves", () => {
|
||||||
let A = new freesewing.Point(10, 10);
|
let A = new Point(10, 10);
|
||||||
let Acp = new freesewing.Point(310, 40);
|
let Acp = new Point(310, 40);
|
||||||
let B = new freesewing.Point(110, 70);
|
let B = new Point(110, 70);
|
||||||
let Bcp = new freesewing.Point(-210, 40);
|
let Bcp = new Point(-210, 40);
|
||||||
let C = new freesewing.Point(20, -5);
|
let C = new Point(20, -5);
|
||||||
let Ccp = new freesewing.Point(-60, -300);
|
let Ccp = new Point(-60, -300);
|
||||||
let D = new freesewing.Point(-200, 85);
|
let D = new Point(-200, 85);
|
||||||
let Dcp = new freesewing.Point(-270, -220);
|
let Dcp = new Point(-270, -220);
|
||||||
|
|
||||||
let hit = freesewing.utils.curvesIntersect(A, Acp, Bcp, B, C, Ccp, Dcp, D);
|
let hit = curvesIntersect(A, Acp, Bcp, B, C, Ccp, Dcp, D);
|
||||||
expect(hit).to.equal(false);
|
expect(hit).to.equal(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should correctly format units", () => {
|
it("Should correctly format units", () => {
|
||||||
expect(freesewing.utils.units(123.456)).to.equal("12.35cm");
|
expect(units(123.456)).to.equal("12.35cm");
|
||||||
expect(freesewing.utils.units(123.456, "imperial")).to.equal('4.86"');
|
expect(units(123.456, "imperial")).to.equal('4.86"');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find a start or end point on beam", () => {
|
it("Should find a start or end point on beam", () => {
|
||||||
let A = new freesewing.Point(12, 34);
|
let A = new Point(12, 34);
|
||||||
let B = new freesewing.Point(56, 78);
|
let B = new Point(56, 78);
|
||||||
let checkA = new freesewing.Point(12, 34);
|
let checkA = new Point(12, 34);
|
||||||
let checkB = new freesewing.Point(56, 78);
|
let checkB = new Point(56, 78);
|
||||||
expect(freesewing.utils.pointOnBeam(A, B, checkA)).to.equal(true);
|
expect(pointOnBeam(A, B, checkA)).to.equal(true);
|
||||||
expect(freesewing.utils.pointOnBeam(A, B, checkB)).to.equal(true);
|
expect(pointOnBeam(A, B, checkB)).to.equal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find whether a point lies on a line segment", () => {
|
it("Should find whether a point lies on a line segment", () => {
|
||||||
let A = new freesewing.Point(12, 34);
|
let A = new Point(12, 34);
|
||||||
let B = new freesewing.Point(56, 78);
|
let B = new Point(56, 78);
|
||||||
let check1 = A.shiftTowards(B, 10);
|
let check1 = A.shiftTowards(B, 10);
|
||||||
let check2 = A.shiftTowards(B, 210);
|
let check2 = A.shiftTowards(B, 210);
|
||||||
expect(freesewing.utils.pointOnLine(A, B, check1)).to.equal(true);
|
expect(pointOnLine(A, B, check1)).to.equal(true);
|
||||||
expect(freesewing.utils.pointOnLine(A, B, check2)).to.equal(false);
|
expect(pointOnLine(A, B, check2)).to.equal(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find a start or end point on curve", () => {
|
it("Should find a start or end point on curve", () => {
|
||||||
let A = new freesewing.Point(12, 34);
|
let A = new Point(12, 34);
|
||||||
let Acp = new freesewing.Point(123, 4);
|
let Acp = new Point(123, 4);
|
||||||
let B = new freesewing.Point(56, 78);
|
let B = new Point(56, 78);
|
||||||
let Bcp = new freesewing.Point(5, 678);
|
let Bcp = new Point(5, 678);
|
||||||
let checkA = new freesewing.Point(12, 34);
|
let checkA = new Point(12, 34);
|
||||||
let checkB = new freesewing.Point(56, 78);
|
let checkB = new Point(56, 78);
|
||||||
expect(freesewing.utils.pointOnCurve(A, Acp, Bcp, B, checkA)).to.equal(true);
|
expect(pointOnCurve(A, Acp, Bcp, B, checkA)).to.equal(true);
|
||||||
expect(freesewing.utils.pointOnCurve(A, Acp, Bcp, B, checkB)).to.equal(true);
|
expect(pointOnCurve(A, Acp, Bcp, B, checkB)).to.equal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find the intersections of a beam and circle", () => {
|
it("Should find the intersections of a beam and circle", () => {
|
||||||
let A = new freesewing.Point(45, 45).attr("data-circle", 35);
|
let A = new Point(45, 45).attr("data-circle", 35);
|
||||||
let B = new freesewing.Point(5, 50);
|
let B = new Point(5, 50);
|
||||||
let C = new freesewing.Point(25, 30);
|
let C = new Point(25, 30);
|
||||||
let intersections = freesewing.utils.beamIntersectsCircle(
|
let intersections = beamIntersectsCircle(
|
||||||
A,
|
A,
|
||||||
A.attributes.get("data-circle"),
|
A.attributes.get("data-circle"),
|
||||||
B,
|
B,
|
||||||
|
@ -230,10 +259,10 @@ describe('Utils', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not find the intersections of this beam and circle", () => {
|
it("Should not find the intersections of this beam and circle", () => {
|
||||||
let A = new freesewing.Point(75, 75).attr("data-circle", 35);
|
let A = new Point(75, 75).attr("data-circle", 35);
|
||||||
let B = new freesewing.Point(5, 5);
|
let B = new Point(5, 5);
|
||||||
let C = new freesewing.Point(10, 5);
|
let C = new Point(10, 5);
|
||||||
let intersections = freesewing.utils.beamIntersectsCircle(
|
let intersections = beamIntersectsCircle(
|
||||||
A,
|
A,
|
||||||
A.attributes.get("data-circle"),
|
A.attributes.get("data-circle"),
|
||||||
B,
|
B,
|
||||||
|
@ -243,10 +272,10 @@ describe('Utils', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find one intersections between this beam and circle", () => {
|
it("Should find one intersections between this beam and circle", () => {
|
||||||
let A = new freesewing.Point(5, 5).attr("data-circle", 5);
|
let A = new Point(5, 5).attr("data-circle", 5);
|
||||||
let B = new freesewing.Point(0, 0);
|
let B = new Point(0, 0);
|
||||||
let C = new freesewing.Point(-10, 0);
|
let C = new Point(-10, 0);
|
||||||
let intersections = freesewing.utils.beamIntersectsCircle(
|
let intersections = beamIntersectsCircle(
|
||||||
A,
|
A,
|
||||||
A.attributes.get("data-circle"),
|
A.attributes.get("data-circle"),
|
||||||
B,
|
B,
|
||||||
|
@ -258,10 +287,10 @@ describe('Utils', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find one intersections between this tangent and circle", () => {
|
it("Should find one intersections between this tangent and circle", () => {
|
||||||
let A = new freesewing.Point(5, 5).attr("data-circle", 5);
|
let A = new Point(5, 5).attr("data-circle", 5);
|
||||||
let B = new freesewing.Point(0, 0);
|
let B = new Point(0, 0);
|
||||||
let C = new freesewing.Point(10, 0);
|
let C = new Point(10, 0);
|
||||||
let intersections = freesewing.utils.lineIntersectsCircle(
|
let intersections = lineIntersectsCircle(
|
||||||
A,
|
A,
|
||||||
A.attributes.get("data-circle"),
|
A.attributes.get("data-circle"),
|
||||||
B,
|
B,
|
||||||
|
@ -273,10 +302,10 @@ describe('Utils', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find one intersection between this line and circle", () => {
|
it("Should find one intersection between this line and circle", () => {
|
||||||
let A = new freesewing.Point(5, 5).attr("data-circle", 5);
|
let A = new Point(5, 5).attr("data-circle", 5);
|
||||||
let B = new freesewing.Point(5, 5);
|
let B = new Point(5, 5);
|
||||||
let C = new freesewing.Point(26, 25);
|
let C = new Point(26, 25);
|
||||||
let intersections = freesewing.utils.lineIntersectsCircle(
|
let intersections = lineIntersectsCircle(
|
||||||
A,
|
A,
|
||||||
A.attributes.get("data-circle"),
|
A.attributes.get("data-circle"),
|
||||||
B,
|
B,
|
||||||
|
@ -288,10 +317,10 @@ describe('Utils', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not find an intersections between this line and circle", () => {
|
it("Should not find an intersections between this line and circle", () => {
|
||||||
let A = new freesewing.Point(5, 5).attr("data-circle", 5);
|
let A = new Point(5, 5).attr("data-circle", 5);
|
||||||
let B = new freesewing.Point(0, 0);
|
let B = new Point(0, 0);
|
||||||
let C = new freesewing.Point(-10, 0);
|
let C = new Point(-10, 0);
|
||||||
let intersections = freesewing.utils.lineIntersectsCircle(
|
let intersections = lineIntersectsCircle(
|
||||||
A,
|
A,
|
||||||
A.attributes.get("data-circle"),
|
A.attributes.get("data-circle"),
|
||||||
B,
|
B,
|
||||||
|
@ -301,24 +330,24 @@ describe('Utils', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find two intersections between this line and circle", () => {
|
it("Should find two intersections between this line and circle", () => {
|
||||||
let A = new freesewing.Point(6, 7).attr("data-circle", 5);
|
let A = new Point(6, 7).attr("data-circle", 5);
|
||||||
let B = new freesewing.Point(0, 10);
|
let B = new Point(0, 10);
|
||||||
let C = new freesewing.Point(10, 0);
|
let C = new Point(10, 0);
|
||||||
let intersections1 = freesewing.utils.lineIntersectsCircle(
|
let intersections1 = lineIntersectsCircle(
|
||||||
A,
|
A,
|
||||||
A.attributes.get("data-circle"),
|
A.attributes.get("data-circle"),
|
||||||
B,
|
B,
|
||||||
C,
|
C,
|
||||||
"foo"
|
"foo"
|
||||||
);
|
);
|
||||||
let intersections2 = freesewing.utils.lineIntersectsCircle(
|
let intersections2 = lineIntersectsCircle(
|
||||||
A,
|
A,
|
||||||
A.attributes.get("data-circle"),
|
A.attributes.get("data-circle"),
|
||||||
B,
|
B,
|
||||||
C,
|
C,
|
||||||
"x"
|
"x"
|
||||||
);
|
);
|
||||||
let intersections3 = freesewing.utils.lineIntersectsCircle(
|
let intersections3 = lineIntersectsCircle(
|
||||||
A,
|
A,
|
||||||
A.attributes.get("data-circle"),
|
A.attributes.get("data-circle"),
|
||||||
B,
|
B,
|
||||||
|
@ -339,10 +368,10 @@ describe('Utils', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find the intersections of a line and circle", () => {
|
it("Should find the intersections of a line and circle", () => {
|
||||||
let A = new freesewing.Point(45, 45).attr("data-circle", 35);
|
let A = new Point(45, 45).attr("data-circle", 35);
|
||||||
let B = new freesewing.Point(5, 50);
|
let B = new Point(5, 50);
|
||||||
let C = new freesewing.Point(25, 30);
|
let C = new Point(25, 30);
|
||||||
let intersections = freesewing.utils.lineIntersectsCircle(
|
let intersections = lineIntersectsCircle(
|
||||||
A,
|
A,
|
||||||
A.attributes.get("data-circle"),
|
A.attributes.get("data-circle"),
|
||||||
B,
|
B,
|
||||||
|
@ -354,10 +383,10 @@ describe('Utils', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not find intersections of this line and circle", () => {
|
it("Should not find intersections of this line and circle", () => {
|
||||||
let A = new freesewing.Point(75, 75).attr("data-circle", 35);
|
let A = new Point(75, 75).attr("data-circle", 35);
|
||||||
let B = new freesewing.Point(5, 5);
|
let B = new Point(5, 5);
|
||||||
let C = new freesewing.Point(10, 5);
|
let C = new Point(10, 5);
|
||||||
let intersections = freesewing.utils.lineIntersectsCircle(
|
let intersections = lineIntersectsCircle(
|
||||||
A,
|
A,
|
||||||
A.attributes.get("data-circle"),
|
A.attributes.get("data-circle"),
|
||||||
B,
|
B,
|
||||||
|
@ -367,10 +396,10 @@ describe('Utils', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not find intersections of this line and circle", () => {
|
it("Should not find intersections of this line and circle", () => {
|
||||||
let A = new freesewing.Point(45, 45).attr("data-circle", 35);
|
let A = new Point(45, 45).attr("data-circle", 35);
|
||||||
let B = new freesewing.Point(40, 40);
|
let B = new Point(40, 40);
|
||||||
let C = new freesewing.Point(52, 50);
|
let C = new Point(52, 50);
|
||||||
let intersections = freesewing.utils.lineIntersectsCircle(
|
let intersections = lineIntersectsCircle(
|
||||||
A,
|
A,
|
||||||
A.attributes.get("data-circle"),
|
A.attributes.get("data-circle"),
|
||||||
B,
|
B,
|
||||||
|
@ -380,16 +409,16 @@ describe('Utils', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find intersections between circles", () => {
|
it("Should find intersections between circles", () => {
|
||||||
let A = new freesewing.Point(10, 10).attr("data-circle", 15);
|
let A = new Point(10, 10).attr("data-circle", 15);
|
||||||
let B = new freesewing.Point(30, 30).attr("data-circle", 35);
|
let B = new Point(30, 30).attr("data-circle", 35);
|
||||||
|
|
||||||
let intersections1 = freesewing.utils.circlesIntersect(
|
let intersections1 = circlesIntersect(
|
||||||
A,
|
A,
|
||||||
A.attributes.get("data-circle"),
|
A.attributes.get("data-circle"),
|
||||||
B,
|
B,
|
||||||
B.attributes.get("data-circle")
|
B.attributes.get("data-circle")
|
||||||
);
|
);
|
||||||
let intersections2 = freesewing.utils.circlesIntersect(
|
let intersections2 = circlesIntersect(
|
||||||
A,
|
A,
|
||||||
A.attributes.get("data-circle"),
|
A.attributes.get("data-circle"),
|
||||||
B,
|
B,
|
||||||
|
@ -409,10 +438,10 @@ describe('Utils', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not find intersections between non-overlapping circles", () => {
|
it("Should not find intersections between non-overlapping circles", () => {
|
||||||
let A = new freesewing.Point(10, 10).attr("data-circle", 15);
|
let A = new Point(10, 10).attr("data-circle", 15);
|
||||||
let B = new freesewing.Point(90, 90).attr("data-circle", 35);
|
let B = new Point(90, 90).attr("data-circle", 35);
|
||||||
|
|
||||||
let intersections = freesewing.utils.circlesIntersect(
|
let intersections = circlesIntersect(
|
||||||
A,
|
A,
|
||||||
A.attributes.get("data-circle"),
|
A.attributes.get("data-circle"),
|
||||||
B,
|
B,
|
||||||
|
@ -422,10 +451,10 @@ describe('Utils', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not find intersections between contained circles", () => {
|
it("Should not find intersections between contained circles", () => {
|
||||||
let A = new freesewing.Point(10, 10).attr("data-circle", 15);
|
let A = new Point(10, 10).attr("data-circle", 15);
|
||||||
let B = new freesewing.Point(10, 10).attr("data-circle", 35);
|
let B = new Point(10, 10).attr("data-circle", 35);
|
||||||
|
|
||||||
let intersections = freesewing.utils.circlesIntersect(
|
let intersections = circlesIntersect(
|
||||||
A,
|
A,
|
||||||
A.attributes.get("data-circle"),
|
A.attributes.get("data-circle"),
|
||||||
B,
|
B,
|
||||||
|
@ -435,10 +464,10 @@ describe('Utils', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not find intersections between identical circles", () => {
|
it("Should not find intersections between identical circles", () => {
|
||||||
let A = new freesewing.Point(10, 10).attr("data-circle", 35);
|
let A = new Point(10, 10).attr("data-circle", 35);
|
||||||
let B = new freesewing.Point(10, 10).attr("data-circle", 35);
|
let B = new Point(10, 10).attr("data-circle", 35);
|
||||||
|
|
||||||
let intersections = freesewing.utils.circlesIntersect(
|
let intersections = circlesIntersect(
|
||||||
A,
|
A,
|
||||||
A.attributes.get("data-circle"),
|
A.attributes.get("data-circle"),
|
||||||
B,
|
B,
|
||||||
|
@ -448,22 +477,22 @@ describe('Utils', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return scale for a given amount of stretch", () => {
|
it("Should return scale for a given amount of stretch", () => {
|
||||||
expect(freesewing.utils.stretchToScale(0)).to.equal(1);
|
expect(stretchToScale(0)).to.equal(1);
|
||||||
expect(freesewing.utils.stretchToScale(0.25)).to.equal(0.8);
|
expect(stretchToScale(0.25)).to.equal(0.8);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should capitalize a string", () => {
|
it("Should capitalize a string", () => {
|
||||||
expect(utils.capitalize("test")).to.equal("Test");
|
expect(capitalize("test")).to.equal("Test");
|
||||||
expect(utils.capitalize("Freesewing")).to.equal("Freesewing");
|
expect(capitalize("Freesewing")).to.equal("Freesewing");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should split a curve", () => {
|
it("Should split a curve", () => {
|
||||||
let a = new freesewing.Point(0, 0);
|
let a = new Point(0, 0);
|
||||||
let b = new freesewing.Point(50, 0);
|
let b = new Point(50, 0);
|
||||||
let c = new freesewing.Point(50, 100);
|
let c = new Point(50, 100);
|
||||||
let d = new freesewing.Point(100, 100);
|
let d = new Point(100, 100);
|
||||||
let X = new freesewing.Point(50, 50);
|
let X = new Point(50, 50);
|
||||||
let [c1, c2] = utils.splitCurve(a, b, c, d, X);
|
let [c1, c2] = splitCurve(a, b, c, d, X);
|
||||||
expect(round(c1.cp1.x)).to.equal(25);
|
expect(round(c1.cp1.x)).to.equal(25);
|
||||||
expect(round(c1.cp1.y)).to.equal(0);
|
expect(round(c1.cp1.y)).to.equal(0);
|
||||||
expect(round(c1.cp2.x)).to.equal(37.5);
|
expect(round(c1.cp2.x)).to.equal(37.5);
|
||||||
|
@ -475,48 +504,48 @@ describe('Utils', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find where a curve intersects a given X-value", () => {
|
it("Should find where a curve intersects a given X-value", () => {
|
||||||
let a = new freesewing.Point(0, 0);
|
let a = new Point(0, 0);
|
||||||
let b = new freesewing.Point(50, 0);
|
let b = new Point(50, 0);
|
||||||
let c = new freesewing.Point(50, 100);
|
let c = new Point(50, 100);
|
||||||
let d = new freesewing.Point(100, 100);
|
let d = new Point(100, 100);
|
||||||
let i = utils.curveIntersectsX(a, b, c, d, 30);
|
let i = curveIntersectsX(a, b, c, d, 30);
|
||||||
expect(round(i.x)).to.equal(30);
|
expect(round(i.x)).to.equal(30);
|
||||||
expect(round(i.y)).to.equal(16);
|
expect(round(i.y)).to.equal(16);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find where a curve intersects a given Y-value", () => {
|
it("Should find where a curve intersects a given Y-value", () => {
|
||||||
let a = new freesewing.Point(0, 0);
|
let a = new Point(0, 0);
|
||||||
let b = new freesewing.Point(50, 0);
|
let b = new Point(50, 0);
|
||||||
let c = new freesewing.Point(50, 100);
|
let c = new Point(50, 100);
|
||||||
let d = new freesewing.Point(100, 100);
|
let d = new Point(100, 100);
|
||||||
let i = utils.curveIntersectsY(a, b, c, d, 30);
|
let i = curveIntersectsY(a, b, c, d, 30);
|
||||||
expect(round(i.x)).to.equal(39.49);
|
expect(round(i.x)).to.equal(39.49);
|
||||||
expect(round(i.y)).to.equal(30);
|
expect(round(i.y)).to.equal(30);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Recreate issue #1206
|
// Recreate issue #1206
|
||||||
it("Should find intersecting beams when a line is almost vertical", () => {
|
it("Should find intersecting beams when a line is almost vertical", () => {
|
||||||
let a = new freesewing.Point(225.72, 241);
|
let a = new Point(225.72, 241);
|
||||||
let b = new freesewing.Point(225.71999999999997, 600);
|
let b = new Point(225.71999999999997, 600);
|
||||||
let i = utils.beamIntersectsY(a, b, 400);
|
let i = beamIntersectsY(a, b, 400);
|
||||||
expect(round(i.y)).to.equal(400);
|
expect(round(i.y)).to.equal(400);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should check for valid coordinate", () => {
|
it("Should check for valid coordinate", () => {
|
||||||
expect(utils.isCoord(23423.23)).to.equal(true);
|
expect(isCoord(23423.23)).to.equal(true);
|
||||||
expect(utils.isCoord(0)).to.equal(true);
|
expect(isCoord(0)).to.equal(true);
|
||||||
expect(utils.isCoord()).to.equal(false);
|
expect(isCoord()).to.equal(false);
|
||||||
expect(utils.isCoord(null)).to.equal(false);
|
expect(isCoord(null)).to.equal(false);
|
||||||
expect(utils.isCoord('hi')).to.equal(false);
|
expect(isCoord('hi')).to.equal(false);
|
||||||
expect(utils.isCoord(NaN)).to.equal(false);
|
expect(isCoord(NaN)).to.equal(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return the correct sample style", () => {
|
it("Should return the correct sample style", () => {
|
||||||
expect(utils.sampleStyle(0, 5)).to.equal("stroke: hsl(-66, 100%, 35%);")
|
expect(sampleStyle(0, 5)).to.equal("stroke: hsl(-66, 100%, 35%);")
|
||||||
expect(utils.sampleStyle(1, 5)).to.equal("stroke: hsl(0, 100%, 35%);")
|
expect(sampleStyle(1, 5)).to.equal("stroke: hsl(0, 100%, 35%);")
|
||||||
expect(utils.sampleStyle(2, 5)).to.equal("stroke: hsl(66, 100%, 35%);")
|
expect(sampleStyle(2, 5)).to.equal("stroke: hsl(66, 100%, 35%);")
|
||||||
expect(utils.sampleStyle(3, 5)).to.equal("stroke: hsl(132, 100%, 35%);")
|
expect(sampleStyle(3, 5)).to.equal("stroke: hsl(132, 100%, 35%);")
|
||||||
expect(utils.sampleStyle(4, 5)).to.equal("stroke: hsl(198, 100%, 35%);")
|
expect(sampleStyle(4, 5)).to.equal("stroke: hsl(198, 100%, 35%);")
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return the correct sample styles", () => {
|
it("Should return the correct sample styles", () => {
|
||||||
|
@ -527,21 +556,21 @@ describe('Utils', () => {
|
||||||
"stroke: pink;",
|
"stroke: pink;",
|
||||||
"stroke: orange;",
|
"stroke: orange;",
|
||||||
]
|
]
|
||||||
for (let i=0;i<5;i++) expect(utils.sampleStyle(i, 5, styles)).to.equal(styles[i])
|
for (let i=0;i<5;i++) expect(sampleStyle(i, 5, styles)).to.equal(styles[i])
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should convert degrees to radians", () => {
|
it("Should convert degrees to radians", () => {
|
||||||
expect(utils.deg2rad(0)).to.equal(0);
|
expect(deg2rad(0)).to.equal(0);
|
||||||
expect(round(utils.deg2rad(69))).to.equal(1.2);
|
expect(round(deg2rad(69))).to.equal(1.2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should convert radians to degrees", () => {
|
it("Should convert radians to degrees", () => {
|
||||||
expect(utils.rad2deg(0)).to.equal(0);
|
expect(rad2deg(0)).to.equal(0);
|
||||||
expect(round(utils.rad2deg(69))).to.equal(3953.41);
|
expect(round(rad2deg(69))).to.equal(3953.41);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should shoulder return two methods for pctBasedOn", () => {
|
it("Should shoulder return two methods for pctBasedOn", () => {
|
||||||
const result = utils.pctBasedOn('chest')
|
const result = pctBasedOn('chest')
|
||||||
expect(typeof result.toAbs).to.equal("function");
|
expect(typeof result.toAbs).to.equal("function");
|
||||||
expect(typeof result.fromAbs).to.equal("function");
|
expect(typeof result.fromAbs).to.equal("function");
|
||||||
const measurements = { chest: 1000 }
|
const measurements = { chest: 1000 }
|
||||||
|
@ -550,7 +579,7 @@ describe('Utils', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should generate a part transform", () => {
|
it("Should generate a part transform", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
pattern.settings.mode = "draft";
|
pattern.settings.mode = "draft";
|
||||||
let part = new pattern.Part();
|
let part = new pattern.Part();
|
||||||
let short = part.shorthand();
|
let short = part.shorthand();
|
||||||
|
@ -560,7 +589,7 @@ describe('Utils', () => {
|
||||||
.move(part.points.from)
|
.move(part.points.from)
|
||||||
.line(part.points.to);
|
.line(part.points.to);
|
||||||
part.stack();
|
part.stack();
|
||||||
const transform = utils.generatePartTransform(30,60,90,true,true,part)
|
const transform = generatePartTransform(30,60,90,true,true,part)
|
||||||
expect(transform.transform).to.equal(`translate(${30 + part.topLeft.x + part.bottomRight.x} ${60 + part.topLeft.y + part.bottomRight.y}) scale(-1 -1) rotate(90 ${part.topLeft.x + part.width/2} ${part.topLeft.y + part.height/2})`);
|
expect(transform.transform).to.equal(`translate(${30 + part.topLeft.x + part.bottomRight.x} ${60 + part.topLeft.y + part.bottomRight.y}) scale(-1 -1) rotate(90 ${part.topLeft.x + part.width/2} ${part.topLeft.y + part.height/2})`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue