Comparing version 1.0.10 to 1.0.11
@@ -513,6 +513,7 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Bezier = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
if(len!==6 && len!==8 && len!==9 && len!==12) { | ||
console.log(coords); | ||
throw new Error("This Bezier curve library only supports quadratic and cubic curves (in 2d and 3d)"); | ||
if (arguments.length !== 1) { | ||
throw new Error("Only new Bezier(point[]) is accepted for 4th and higher order curves"); | ||
} | ||
} | ||
var _3d = (len === 9 || len === 12); | ||
var _3d = (len === 9 || len === 12 || typeof args[0].z !== "undefined"); | ||
this._3d = _3d; | ||
@@ -519,0 +520,0 @@ var points = []; |
@@ -147,2 +147,24 @@ function bindDrawFunctions(idx) { | ||
drawHull: function(hull, offset) { | ||
ctx.beginPath(); | ||
if(hull.length === 6) { | ||
ctx.moveTo(hull[0].x, hull[0].y); | ||
ctx.lineTo(hull[1].x, hull[1].y); | ||
ctx.lineTo(hull[2].x, hull[2].y); | ||
ctx.moveTo(hull[3].x, hull[3].y); | ||
ctx.lineTo(hull[4].x, hull[4].y); | ||
} else { | ||
ctx.moveTo(hull[0].x, hull[0].y); | ||
ctx.lineTo(hull[1].x, hull[1].y); | ||
ctx.lineTo(hull[2].x, hull[2].y); | ||
ctx.lineTo(hull[3].x, hull[3].y); | ||
ctx.moveTo(hull[4].x, hull[4].y); | ||
ctx.lineTo(hull[5].x, hull[5].y); | ||
ctx.lineTo(hull[6].x, hull[6].y); | ||
ctx.moveTo(hull[7].x, hull[7].y); | ||
ctx.lineTo(hull[8].x, hull[8].y); | ||
} | ||
ctx.stroke(); | ||
}, | ||
drawShape: function(shape, offset) { | ||
@@ -149,0 +171,0 @@ offset = offset || { x:0, y:0 }; |
@@ -512,6 +512,7 @@ /** | ||
if(len!==6 && len!==8 && len!==9 && len!==12) { | ||
console.log(coords); | ||
throw new Error("This Bezier curve library only supports quadratic and cubic curves (in 2d and 3d)"); | ||
if (arguments.length !== 1) { | ||
throw new Error("Only new Bezier(point[]) is accepted for 4th and higher order curves"); | ||
} | ||
} | ||
var _3d = (len === 9 || len === 12); | ||
var _3d = (len === 9 || len === 12 || typeof args[0].z !== "undefined"); | ||
this._3d = _3d; | ||
@@ -518,0 +519,0 @@ var points = []; |
{ | ||
"name": "bezier-js", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"description": "A javascript library for working with Bezier curves", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
85
test.js
@@ -8,25 +8,24 @@ var Bezier = require("./lib"); | ||
Bezier.fromSVG("M 0 0 Q 0.5 1 1 0") | ||
] | ||
.forEach(function(b) { | ||
assert.equal(b.toString(), "[0/0, 0.5/1, 1/0]"); | ||
assert.almostEqual(b.length(), 1.4789428575453212); | ||
assert.deepAlmostEqual(b.dpoints, [ | ||
[{x:1, y:2}, {x:1, y:-2}], | ||
[{x:0, y:-4}] | ||
]); | ||
].forEach(function(b) { | ||
assert.equal(b.toString(), "[0/0, 0.5/1, 1/0]"); | ||
assert.almostEqual(b.length(), 1.4789428575453212); | ||
assert.deepAlmostEqual(b.dpoints, [ | ||
[{x:1, y:2}, {x:1, y:-2}], | ||
[{x:0, y:-4}] | ||
]); | ||
assert.deepAlmostEqual(b.derivative(0), {x:1, y:2}); | ||
assert.deepAlmostEqual(b.derivative(0.5), {x:1, y:0}); | ||
assert.deepAlmostEqual(b.derivative(1), {x:1, y:-2}); | ||
assert.deepAlmostEqual(b.derivative(0), {x:1, y:2}); | ||
assert.deepAlmostEqual(b.derivative(0.5), {x:1, y:0}); | ||
assert.deepAlmostEqual(b.derivative(1), {x:1, y:-2}); | ||
assert.deepAlmostEqual(b.normal(0), {x:-0.8944271909999159, y:0.4472135954999579}); | ||
assert.deepAlmostEqual(b.normal(0.5), {x:-0, y:1}); | ||
assert.deepAlmostEqual(b.normal(1), {x:0.8944271909999159, y:0.4472135954999579}); | ||
assert.deepAlmostEqual(b.normal(0), {x:-0.8944271909999159, y:0.4472135954999579}); | ||
assert.deepAlmostEqual(b.normal(0.5), {x:-0, y:1}); | ||
assert.deepAlmostEqual(b.normal(1), {x:0.8944271909999159, y:0.4472135954999579}); | ||
assert.deepAlmostEqual(b.inflections(), {x:[], y:[0.5], values:[0.5]}); | ||
assert.deepAlmostEqual(b.bbox(), { | ||
x:{min:0, mid:0.5, max:1, size:1}, | ||
y:{min:0, mid:0.25, max:0.5, size:0.5} | ||
}); | ||
assert.deepAlmostEqual(b.inflections(), {x:[], y:[0.5], values:[0.5]}); | ||
assert.deepAlmostEqual(b.bbox(), { | ||
x:{min:0, mid:0.5, max:1, size:1}, | ||
y:{min:0, mid:0.25, max:0.5, size:0.5} | ||
}); | ||
}); | ||
@@ -43,27 +42,25 @@ // SVG relative quadratic check | ||
Bezier.fromSVG("m 0 0 C 0 1 1 1 1 0") | ||
] | ||
.forEach(function(b) { | ||
assert.equal(b.toString(), "[0/0, 0/1, 1/1, 1/0]"); | ||
assert.almostEqual(b.length(), 2); | ||
assert.deepAlmostEqual(b.dpoints, [ | ||
[{x:0, y:3}, {x:3, y:0}, {x:0, y:-3}], | ||
[{x:6, y:-6}, {x:-6, y:-6}], | ||
[{x:-12, y:0}] | ||
]); | ||
].forEach(function(b) { | ||
assert.equal(b.toString(), "[0/0, 0/1, 1/1, 1/0]"); | ||
assert.almostEqual(b.length(), 2); | ||
assert.deepAlmostEqual(b.dpoints, [ | ||
[{x:0, y:3}, {x:3, y:0}, {x:0, y:-3}], | ||
[{x:6, y:-6}, {x:-6, y:-6}], | ||
[{x:-12, y:0}] | ||
]); | ||
assert.deepAlmostEqual(b.derivative(0), {x:0, y:3}); | ||
assert.deepAlmostEqual(b.derivative(0.5), {x:1.5, y:0}); | ||
assert.deepAlmostEqual(b.derivative(1), {x:0, y:-3}); | ||
assert.deepAlmostEqual(b.derivative(0), {x:0, y:3}); | ||
assert.deepAlmostEqual(b.derivative(0.5), {x:1.5, y:0}); | ||
assert.deepAlmostEqual(b.derivative(1), {x:0, y:-3}); | ||
assert.deepAlmostEqual(b.normal(0), {x:-1, y:0}); | ||
assert.deepAlmostEqual(b.normal(0.5), {x:-0, y:1}); | ||
assert.deepAlmostEqual(b.normal(1), {x:1, y:0}); | ||
assert.deepAlmostEqual(b.normal(0), {x:-1, y:0}); | ||
assert.deepAlmostEqual(b.normal(0.5), {x:-0, y:1}); | ||
assert.deepAlmostEqual(b.normal(1), {x:1, y:0}); | ||
assert.deepAlmostEqual(b.inflections(), {x:[0, 0.5, 1], y:[0.5], values:[0, 0.5, 0.5, 1]}); | ||
assert.deepAlmostEqual(b.bbox(), { | ||
x:{min:0, mid:0.5, max:1, size:1}, | ||
y:{min:0, mid:0.375, max:0.75, size:0.75} | ||
}); | ||
assert.deepAlmostEqual(b.inflections(), {x:[0, 0.5, 1], y:[0.5], values:[0, 0.5, 0.5, 1]}); | ||
assert.deepAlmostEqual(b.bbox(), { | ||
x:{min:0, mid:0.5, max:1, size:1}, | ||
y:{min:0, mid:0.375, max:0.75, size:0.75} | ||
}); | ||
}); | ||
@@ -75,1 +72,9 @@ // SVG relative cubic check | ||
); | ||
// high order curves | ||
[ | ||
new Bezier([{x:0,y:0}, {x:0,y:1}, {x:1,y:1}, {x:1,y:2}, {x:2,y:2}]), | ||
].forEach(function(b) { | ||
assert.equal(b.toString(), "[0/0, 0/1, 1/1, 1/2, 2/2]"); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
142315
3243