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.1.0 to 1.2.0

bench/bench-area.js

16

index.js

@@ -40,2 +40,16 @@ 'use strict';

area: function (polygon) {
var sum = 0;
for (var i = 0; i < polygon.length; i++) {
var ring = polygon[i];
for (var j = 0, len = ring.length, k = len - 1; j < len; k = j++) {
sum += (ring[j][0] - ring[k][0]) * (ring[j][1] + ring[k][1]) * (i ? -1 : 1);
}
}
return (Math.abs(sum) / 2) * this.e * this.d * this.d;
},
bearing: function (a, b) {

@@ -79,3 +93,3 @@ var dx = (b[0] - a[0]) * this.e;

pointOnLine(line, p) {
pointOnLine: function (line, p) {
var minDist = Infinity;

@@ -82,0 +96,0 @@ var minX, minY;

7

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

@@ -9,2 +9,3 @@ "main": "index.js",

"benchmark": "^2.1.0",
"browserify": "^13.0.0",
"eslint": "^2.7.0",

@@ -17,3 +18,5 @@ "eslint-config-mourner": "^2.0.1",

"pretest": "eslint index.js bench test/test.js",
"test": "tape test/test.js"
"test": "tape test/test.js",
"build": "browserify index.js -s cheapRuler > cheap-ruler.js",
"prepublish": "npm run build"
},

@@ -20,0 +23,0 @@ "eslintConfig": {

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

For a city scale (a few dozen miles) and far away from poles,
the results are typically within 0.1% of corresponding Turf functions.
**Note**: to get the full performance benefit, create the ruler object once per an area of calculation (such as a tile), and then reuse it as much as possible.

@@ -39,15 +42,35 @@

Given two points of the form `[x, y]`, returns the distance. Typically within 0.1% of `turf.distance` values (on small distances and far away from poles), but 20–25 times faster.
Given two points of the form `[x, y]`, returns the distance.
20–25 times faster than `turf.distance`.
#### lineDistance(points)
Given an array of points, returns the total line distance. Typically within 0.1% of `turf.lineDistance` values but 20–25 times faster.
Given an array of points, returns the total line distance.
20–25 times faster than `turf.lineDistance`.
#### area(polygon)
Given a polygon (an array of rings, where each ring is an array of points), returns the area.
3–4 times faster than `turf.area`. Note that it returns the value in the specified units
(square kilometers by default) rather than square meters as in `turf.area`.
```js
var area = ruler.area([[
[-67.031, 50.458],
[-67.031, 50.534],
[-66.929, 50.534],
[-66.929, 50.458],
[-67.031, 50.458]
]]);
```
#### bearing(a, b)
Returns the bearing between two points in angles. Typically within 0.01% of `turf.bearing` but 3–4 times faster.
Returns the bearing between two points in angles.
3–4 times faster than `turf.bearing`.
#### pointOnLine(line, p)
Returns the closest point on the line from the given point. Line is an array of points. 80-90 times faster than `turf.pointOnLine`.
Returns the closest point on the line from the given point. Line is an array of points.
80–90 times faster than `turf.pointOnLine`.

@@ -57,3 +80,3 @@ #### bufferPoint(p, buffer)

Given a point, returns a bounding box object (`[w, s, e, n]`) created from the given point buffered by a given distance.
This is about _200 times faster_ than creating a bounding box with two diagonal `turf.destination` calls.
About _200 times faster_ than creating a bounding box with two diagonal `turf.destination` calls.

@@ -60,0 +83,0 @@ ```js

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

test('area', function (t) {
for (var i = 0; i < lines.length; i++) {
if (lines[i].length < 3) continue;
var poly = turf.polygon([lines[i].concat([lines[i][0]])]);
var expected = turf.area(poly) / 1e6;
var actual = ruler.area([lines[i]]);
assertErr(t, expected, actual, 0.0002, 'area');
}
t.pass('area within 0.02%');
t.end();
});
test('bearing', function (t) {

@@ -40,0 +52,0 @@ for (var i = 0; i < points.length - 1; i++) {

Sorry, the diff of this file is not supported yet

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