Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bezier-js

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bezier-js - npm Package Compare versions

Comparing version 1.3.2 to 1.4.0

49

bezier.js

@@ -19,14 +19,15 @@ (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){

acos = Math.acos,
//asin = Math.asin,
atan2 = Math.atan2,
sqrt = Math.sqrt,
// cube root function yielding real roots
crt = function(v) { if(v<0) return -Math.pow(-v,1/3); return Math.pow(v,1/3); },
crt = function(v) { return (v<0) ? -Math.pow(-v,1/3) : Math.pow(v,1/3); },
// trig constants
pi = Math.PI,
tau = 2*pi,
quart = pi/2;
quart = pi/2,
// float precision significant decimal
epsilon = 0.000001,
// a zero coordinate, which is surprisingly useful
ZERO = {x:0,y:0,z:0};
// a zero coordinate, which is surprisingly useful
var ZERO = {x:0,y:0,z:0};
// Bezier utility functions

@@ -89,2 +90,3 @@ var utils = {

],
arcfn: function(t, derivativeFn) {

@@ -98,2 +100,12 @@ var d = derivativeFn(t);

},
between: function(v, m, M) {
return (m <= v && v <= M) || utils.approximately(v, m) || utils.approximately(v, M);
},
approximately: function(a,b,precision) {
precision = precision || epsilon;
return abs(a-b) <= precision;
},
length: function(derivativeFn) {

@@ -107,2 +119,3 @@ var z=0.5,sum=0,len=utils.Tvalues.length,i,t;

},
map: function(v, ds,de, ts,te) {

@@ -112,2 +125,3 @@ var d1 = de-ds, d2 = te-ts, v2 = v-ds, r = v2/d1;

},
lerp: function(r, v1, v2) {

@@ -123,2 +137,3 @@ var ret = {

},
pointToString: function(p) {

@@ -131,8 +146,11 @@ var s = p.x+"/"+p.y;

},
pointsToString: function(points) {
return "[" + points.map(utils.pointToString).join(", ") + "]";
},
copy: function(obj) {
return JSON.parse(JSON.stringify(obj));
},
angle: function(o,v1,v2) {

@@ -151,2 +169,3 @@ var dx1 = v1.x - o.x,

},
// round as string, to avoid rounding errors

@@ -158,2 +177,3 @@ round: function(v, d) {

},
dist: function(p1, p2) {

@@ -164,2 +184,3 @@ var dx = p1.x - p2.x,

},
lli8: function(x1,y1,x2,y2,x3,y3,x4,y4) {

@@ -172,2 +193,3 @@ var nx=(x1*y2-y1*x2)*(x3-x4)-(x1-x2)*(x3*y4-y3*x4),

},
lli4: function(p1,p2,p3,p4) {

@@ -180,5 +202,7 @@ var x1 = p1.x, y1 = p1.y,

},
lli: function(v1, v2) {
return utils.lli4(v1,v1.c,v2,v2.c);
},
makeline: function(p1,p2) {

@@ -188,2 +212,3 @@ var x1 = p1.x, y1 = p1.y, x2 = p2.x, y2 = p2.y, dx = (x2-x1)/3, dy = (y2-y1)/3;

},
findbbox: function(sections) {

@@ -203,2 +228,3 @@ var mx=99999999,my=mx,MX=-mx,MY=MX;

},
shapeintersections: function(s1, bbox1, s2, bbox2) {

@@ -225,2 +251,3 @@ if(!utils.bboxoverlap(bbox1, bbox2)) return [];

},
makeshape: function(forward, back) {

@@ -244,2 +271,3 @@ var bpl = back.points.length;

},
getminmax: function(curve, d, list) {

@@ -258,2 +286,3 @@ if(!list) return { min:0, max:0 };

},
align: function(points, line) {

@@ -271,2 +300,3 @@ var tx = line.p1.x,

},
roots: function(points, line) {

@@ -336,2 +366,3 @@ line = line || {p1:{x:0,y:0},p2:{x:1,y:0}};

},
droots: function(p) {

@@ -364,2 +395,3 @@ // quadratic roots are easy

},
bboxoverlap: function(b1,b2) {

@@ -376,2 +408,3 @@ var dims=['x','y'],len=dims.length,i,dim,l,t,d

},
expandbox: function(bbox, _bbox) {

@@ -391,2 +424,3 @@ if(_bbox.x.min < bbox.x.min) { bbox.x.min = _bbox.x.min; }

},
pairiteration: function(c1,c2) {

@@ -422,2 +456,3 @@ var c1b = c1.bbox(),

},
getccenter: function(p1,p2,p3) {

@@ -1118,3 +1153,3 @@ var dx1 = (p2.x - p1.x),

var p = self.get(t);
return (mx <= p.x && p.x <= MX && my <= p.y && p.y <= MY);
return utils.between(p.x, mx, MX) && utils.between(p.y, my, MY);
});

@@ -1121,0 +1156,0 @@ },

@@ -18,14 +18,15 @@ /**

acos = Math.acos,
//asin = Math.asin,
atan2 = Math.atan2,
sqrt = Math.sqrt,
// cube root function yielding real roots
crt = function(v) { if(v<0) return -Math.pow(-v,1/3); return Math.pow(v,1/3); },
crt = function(v) { return (v<0) ? -Math.pow(-v,1/3) : Math.pow(v,1/3); },
// trig constants
pi = Math.PI,
tau = 2*pi,
quart = pi/2;
quart = pi/2,
// float precision significant decimal
epsilon = 0.000001,
// a zero coordinate, which is surprisingly useful
ZERO = {x:0,y:0,z:0};
// a zero coordinate, which is surprisingly useful
var ZERO = {x:0,y:0,z:0};
// Bezier utility functions

@@ -88,2 +89,3 @@ var utils = {

],
arcfn: function(t, derivativeFn) {

@@ -97,2 +99,12 @@ var d = derivativeFn(t);

},
between: function(v, m, M) {
return (m <= v && v <= M) || utils.approximately(v, m) || utils.approximately(v, M);
},
approximately: function(a,b,precision) {
precision = precision || epsilon;
return abs(a-b) <= precision;
},
length: function(derivativeFn) {

@@ -106,2 +118,3 @@ var z=0.5,sum=0,len=utils.Tvalues.length,i,t;

},
map: function(v, ds,de, ts,te) {

@@ -111,2 +124,3 @@ var d1 = de-ds, d2 = te-ts, v2 = v-ds, r = v2/d1;

},
lerp: function(r, v1, v2) {

@@ -122,2 +136,3 @@ var ret = {

},
pointToString: function(p) {

@@ -130,8 +145,11 @@ var s = p.x+"/"+p.y;

},
pointsToString: function(points) {
return "[" + points.map(utils.pointToString).join(", ") + "]";
},
copy: function(obj) {
return JSON.parse(JSON.stringify(obj));
},
angle: function(o,v1,v2) {

@@ -150,2 +168,3 @@ var dx1 = v1.x - o.x,

},
// round as string, to avoid rounding errors

@@ -157,2 +176,3 @@ round: function(v, d) {

},
dist: function(p1, p2) {

@@ -163,2 +183,3 @@ var dx = p1.x - p2.x,

},
lli8: function(x1,y1,x2,y2,x3,y3,x4,y4) {

@@ -171,2 +192,3 @@ var nx=(x1*y2-y1*x2)*(x3-x4)-(x1-x2)*(x3*y4-y3*x4),

},
lli4: function(p1,p2,p3,p4) {

@@ -179,5 +201,7 @@ var x1 = p1.x, y1 = p1.y,

},
lli: function(v1, v2) {
return utils.lli4(v1,v1.c,v2,v2.c);
},
makeline: function(p1,p2) {

@@ -187,2 +211,3 @@ var x1 = p1.x, y1 = p1.y, x2 = p2.x, y2 = p2.y, dx = (x2-x1)/3, dy = (y2-y1)/3;

},
findbbox: function(sections) {

@@ -202,2 +227,3 @@ var mx=99999999,my=mx,MX=-mx,MY=MX;

},
shapeintersections: function(s1, bbox1, s2, bbox2) {

@@ -224,2 +250,3 @@ if(!utils.bboxoverlap(bbox1, bbox2)) return [];

},
makeshape: function(forward, back) {

@@ -243,2 +270,3 @@ var bpl = back.points.length;

},
getminmax: function(curve, d, list) {

@@ -257,2 +285,3 @@ if(!list) return { min:0, max:0 };

},
align: function(points, line) {

@@ -270,2 +299,3 @@ var tx = line.p1.x,

},
roots: function(points, line) {

@@ -335,2 +365,3 @@ line = line || {p1:{x:0,y:0},p2:{x:1,y:0}};

},
droots: function(p) {

@@ -363,2 +394,3 @@ // quadratic roots are easy

},
bboxoverlap: function(b1,b2) {

@@ -375,2 +407,3 @@ var dims=['x','y'],len=dims.length,i,dim,l,t,d

},
expandbox: function(bbox, _bbox) {

@@ -390,2 +423,3 @@ if(_bbox.x.min < bbox.x.min) { bbox.x.min = _bbox.x.min; }

},
pairiteration: function(c1,c2) {

@@ -421,2 +455,3 @@ var c1b = c1.bbox(),

},
getccenter: function(p1,p2,p3) {

@@ -1117,3 +1152,3 @@ var dx1 = (p2.x - p1.x),

var p = self.get(t);
return (mx <= p.x && p.x <= MX && my <= p.y && p.y <= MY);
return utils.between(p.x, mx, MX) && utils.between(p.y, my, MY);
});

@@ -1120,0 +1155,0 @@ },

2

package.json
{
"name": "bezier-js",
"version": "1.3.2",
"version": "1.4.0",
"description": "A javascript library for working with Bezier curves",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

var Bezier = require("./lib");
var utils = Bezier.getUtils();
var assert = require("chai").use(require("chai-stats")).assert;

@@ -114,1 +115,37 @@

});
var test_bezier = [0, 1.74, .21, 1.67, .28, 1.32, .28, .86];
var test_line = { p1: { x: -.56, y: .95}, p2: { x: .57, y: .95 } };
assert(new Bezier(test_bezier).intersects(test_line).length !== 0);
// test for numerical precision despite rounding errors after the
// significant decimal.
(function() {
var p = [
{x:0, y:1.74},
{x:0.21, y:1.67},
{x:0.28, y:1.32},
{x:0.28, y:0.86}
],
t = 0.9336954111478684,
mt = 1-t,
mt2 = mt*mt,
t2 = t*t,
a = mt2*mt,
b = mt2*t*3,
c = mt*t2*3,
d = t*t2,
np = {
x: a*p[0].x + b*p[1].x + c*p[2].x + d*p[3].x,
y: a*p[0].y + b*p[1].y + c*p[2].y + d*p[3].y
},
my = 0.95,
MY = 0.95;
assert(utils.between(np.y,my,MY), true, "y inside range, despite IEEE rounding");
}());
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc