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

cheap-ruler

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cheap-ruler - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

bench/bench-along.js

27

cheap-ruler.js

@@ -130,2 +130,29 @@ (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.cheapRuler = 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){

return [minX, minY];
},
along: function (line, dist) {
var sum = 0;
if (dist <= 0) return line[0];
for (var i = 0; i < line.length - 1; i++) {
var p0 = line[i];
var p = line[i + 1];
var d = this.distance(p0, p);
sum += d;
if (sum > dist) {
var t = (dist - (sum - d)) / d;
var dx = p[0] - p0[0];
var dy = p[1] - p0[1];
return [
p0[0] + dx * t,
p0[1] + dy * t
];
}
}
return line[line.length - 1];
}

@@ -132,0 +159,0 @@ };

@@ -129,3 +129,30 @@ 'use strict';

return [minX, minY];
},
along: function (line, dist) {
var sum = 0;
if (dist <= 0) return line[0];
for (var i = 0; i < line.length - 1; i++) {
var p0 = line[i];
var p = line[i + 1];
var d = this.distance(p0, p);
sum += d;
if (sum > dist) {
var t = (dist - (sum - d)) / d;
var dx = p[0] - p0[0];
var dy = p[1] - p0[1];
return [
p0[0] + dx * t,
p0[1] + dy * t
];
}
}
return line[line.length - 1];
}
};

2

package.json
{
"name": "cheap-ruler",
"version": "1.2.0",
"version": "1.3.0",
"description": "A collection of fast approximations to common geographic measurements.",

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

@@ -44,5 +44,5 @@ # cheap-ruler [![Build Status](https://travis-ci.org/mapbox/cheap-ruler.svg?branch=master)](https://travis-ci.org/mapbox/cheap-ruler)

#### lineDistance(points)
#### lineDistance(line)
Given an array of points, returns the total line distance.
Given a line (an array of points), returns the total line distance.
20–25 times faster than `turf.lineDistance`.

@@ -73,5 +73,10 @@

Returns the closest point on the line from the given point. Line is an array of points.
Returns the closest point on the line from the given point.
80–90 times faster than `turf.pointOnLine`.
#### along(line, dist)
Returns the point at a specified distance along the line.
20-25 times faster than `turf.along`.
#### bufferPoint(p, buffer)

@@ -93,1 +98,6 @@

Returns true if the given point is inside in the given bounding box, otherwise false.
## Install
- NPM: `npm install chep-ruler`
- Browser build: https://npmcdn.com/cheap-ruler@1.2.0/cheap-ruler.js

@@ -38,2 +38,15 @@ 'use strict';

test('along', function (t) {
for (var i = 0; i < lines.length; i++) {
var line = turf.linestring(lines[i]);
var dist = turf.lineDistance(line) / 2;
var expected = turf.along(line, dist, 'kilometers').geometry.coordinates;
var actual = ruler.along(lines[i], dist);
assertErr(t, expected[0], actual[0], 2e-7, 'along longitude');
assertErr(t, expected[1], actual[1], 2e-7, 'along latitude');
}
t.pass('lineDistance within 0.1%');
t.end();
});
test('area', function (t) {

@@ -40,0 +53,0 @@ for (var i = 0; i < lines.length; i++) {

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