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

line-interpolate-points

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

line-interpolate-points - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

31

index.js

@@ -5,2 +5,5 @@ /**

* length of a potentially multi-segment line.
*
* Note: this module's function documentation frequently refers to a `Point`
* object, which is simply an array of two numbers (the x- and y- coordinates).
*/

@@ -16,4 +19,4 @@

function distance( pt1, pt2 ){
var deltaX = pt1.x - pt2.x;
var deltaY = pt1.y - pt2.y;
var deltaX = pt1[0] - pt2[0];
var deltaY = pt1[1] - pt2[1];
return Math.sqrt( deltaX * deltaX + deltaY * deltaY );

@@ -57,13 +60,13 @@ }

var remainingDist = nextDist - currDist;
var ctrlPtsDeltaX = ctrlPoints[ prevCtrlPtInd + 1 ].x -
ctrlPoints[ prevCtrlPtInd ].x;
var ctrlPtsDeltaY = ctrlPoints[ prevCtrlPtInd + 1 ].y -
ctrlPoints[ prevCtrlPtInd ].y;
var ctrlPtsDeltaX = ctrlPoints[ prevCtrlPtInd + 1 ][0] -
ctrlPoints[ prevCtrlPtInd ][0];
var ctrlPtsDeltaY = ctrlPoints[ prevCtrlPtInd + 1 ][1] -
ctrlPoints[ prevCtrlPtInd ][1];
var ctrlPtsDist = ctrlPtDists[ prevCtrlPtInd + 1 ] -
ctrlPtDists[ prevCtrlPtInd ];
currPoint = {
x: currPoint.x + ( ctrlPtsDeltaX / ctrlPtsDist ) * remainingDist,
y: currPoint.y + ( ctrlPtsDeltaY / ctrlPtsDist ) * remainingDist
};
currPoint = [
currPoint[0] + ( ctrlPtsDeltaX / ctrlPtsDist ) * remainingDist,
currPoint[1] + ( ctrlPtsDeltaY / ctrlPtsDist ) * remainingDist
];
interpPoints.push( currPoint );

@@ -79,10 +82,2 @@

/**
* A simple 2D point object.
*/
function Point( x, y ){
this.x = x;
this.y = y;
}
module.exports = interpolateLineRange;
{
"name": "line-interpolate-points",
"version": "0.0.3",
"version": "0.0.4",
"description": "Exposes a function to interpolate any number of points along a multi-segment line (LineString).",

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

@@ -17,3 +17,3 @@ [![NPM](https://nodei.co/npm/line-interpolate-points.png?downloads=true&stars=true)](https://nodei.co/npm/line-interpolate-points/)

```javascript
> var interpolateLineRange = require( 'line-points-interpolator' )
> var interpolateLineRange = require( 'line-interpolate-points' )
> interpolateLineRange( [ { x: 3, y: 10 }, { x: 4, y: 10 } ], 2 )

@@ -20,0 +20,0 @@ [ { x: 3, y: 10 },

/**
* @file
* @file Unit tests for the package.
*/

@@ -13,21 +13,21 @@

test( 'interpolates point coordinates correctly', function ( t ){
var actual = interpolateLineRange([
{ x: 0, y: 0 },
{ x: 100, y: 150 },
{ x: 120, y: 100 },
{ x: 300, y: 400 }
], 11);
var actual = interpolateLineRange( [
[ 0, 0 ],
[ 100, 150 ],
[ 120, 100 ],
[ 300, 400 ]
], 11 );
var expected = [
{ x: 0, y: 0 },
{ x: 32.39373293672607, y: 48.590599405089094 },
{ x: 64.78746587345213, y: 97.18119881017819 },
{ x: 97.18119881017819, y: 145.77179821526727 },
{ x: 119.80142422763696, y: 100.49643943090761 },
{ x: 149.77075714219484, y: 149.61792857032475 },
{ x: 179.81660571375585, y: 199.6943428562598 },
{ x: 209.86245428531686, y: 249.77075714219484 },
{ x: 239.90830285687787, y: 299.84717142812985 },
{ x: 269.9541514284389, y: 349.92358571406487 },
{ x: 300, y: 400 }
[ 0, 0 ],
[ 32.39373293672607, 48.590599405089094 ],
[ 64.78746587345213, 97.18119881017819 ],
[ 97.18119881017819, 145.77179821526727 ],
[ 119.80142422763696, 100.49643943090761 ],
[ 149.77075714219484, 149.61792857032475 ],
[ 179.81660571375585, 199.6943428562598 ],
[ 209.86245428531686, 249.77075714219484 ],
[ 239.90830285687787, 299.84717142812985 ],
[ 269.9541514284389, 349.92358571406487 ],
[ 300, 400 ]
];

@@ -39,10 +39,10 @@

);
for(var pt = 0; pt < actual.length; pt++){
for( var pt = 0; pt < actual.length; pt++ ){
t.true(
Math.floor(actual[pt].x) == Math.floor(expected[pt].x),
util.format('x-coordinate %d matches.', pt)
Math.floor( actual[ pt ][ 0 ] ) == Math.floor( expected[ pt ][ 0 ] ),
util.format( 'x-coordinate %d matches.', pt )
);
t.true(
Math.floor(actual[pt].y) == Math.floor(expected[pt].y),
util.format('y-coordinate %d matches.', pt)
Math.floor( actual[ pt ][ 1 ] ) == Math.floor( expected[ pt ][1 ] ),
util.format( 'y-coordinate %d matches.', pt )
);

@@ -54,5 +54,5 @@ }

module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('index: ' + name, testFunction);
module.exports.all = function ( tape, common ) {
function test( name, testFunction ) {
return tape( name, testFunction );
}

@@ -62,5 +62,5 @@

if( module.exports.tests.hasOwnProperty( testCase ) ){
module.exports.tests[testCase](test, common);
module.exports.tests[ testCase ]( test, common );
}
}
};
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