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

point-at-length

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

point-at-length - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

52

index.js

@@ -44,4 +44,4 @@ var parse = require('parse-svg-path');

var t = j / n;
var x = xof(p, t);
var y = yof(p, t);
var x = xof_C(p, t);
var y = yof_C(p, t);
len += dist(cur[0], cur[1], x, y);

@@ -66,2 +66,31 @@

}
else if (p[0] === 'Q') {
prev[0] = cur[0];
prev[1] = cur[1];
prev[2] = len;
var n = 100;
for (var j = 0; j <= n; j++) {
var t = j / n;
var x = xof_Q(p, t);
var y = yof_Q(p, t);
len += dist(cur[0], cur[1], x, y);
cur[0] = x;
cur[1] = y;
if (typeof pos === 'number' && len >= pos) {
var dv = (len - pos) / (len - prev[2]);
var npos = [
cur[0] * (1 - dv) + prev[0] * dv,
cur[1] * (1 - dv) + prev[1] * dv
];
return { length: len, pos: npos };
}
prev[0] = cur[0];
prev[1] = cur[1];
prev[2] = len;
}
}
else if (p[0] === 'L') {

@@ -78,3 +107,3 @@ len += dist(cur[0], cur[1], p[1], p[2]);

cur[0] = p[1];
cur[0] = p[2];
cur[1] = p[2];
prev[0] = cur[0];

@@ -87,3 +116,3 @@ prev[1] = cur[1];

function xof (p, t) {
function xof_C (p, t) {
return Math.pow((1-t), 3) * cur[0]

@@ -95,3 +124,3 @@ + 3 * Math.pow((1-t), 2) * t * p[1]

}
function yof (p, t) {
function yof_C (p, t) {
return Math.pow((1-t), 3) * cur[1]

@@ -103,2 +132,15 @@ + 3 * Math.pow((1-t), 2) * t * p[2]

}
function xof_Q (p, t) {
return Math.pow((1-t), 2) * cur[0]
+ 2 * (1-t) * t * p[1]
+ Math.pow(t, 2) * p[3]
;
}
function yof_Q (p, t) {
return Math.pow((1-t), 2) * cur[1]
+ 2 * (1-t) * t * p[2]
+ Math.pow(t, 2) * p[4]
;
}
};

@@ -105,0 +147,0 @@

2

package.json
{
"name": "point-at-length",
"version": "1.0.0",
"version": "1.0.1",
"description": "compute a point from an svg path string",

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

@@ -71,2 +71,3 @@ var test = require('tape');

var pt = points(ptsstr);
var accuracy = [];

@@ -78,5 +79,14 @@ for (var i = 0; i < expected.length; i++) {

var rx = ref[0], ry = ref[1];
accuracy.push(x / rx, y / ry);
t.ok(cmp(x, rx, 0.1), x + ' ~~ ' + rx + ' ±10%');
t.ok(cmp(y, ry, 0.1), y + ' ~~ ' + ry + ' ±10%');
}
var sum = 0;
for (var i = 0; i < accuracy.length; i++) {
sum += accuracy[i];
}
console.log('mean accuracy:',
Math.floor(sum / accuracy.length * 100 * 100) / 100, '%'
);
});

@@ -83,0 +93,0 @@

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