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 2.4.0 to 2.4.1

1

bench/bench-along.js

@@ -22,2 +22,3 @@ 'use strict';

'ruler.along': function () {
var ruler = cheapRuler(32.8351);
for (var i = 0; i < lines.length; i++) {

@@ -24,0 +25,0 @@ ruler.along(lines[i], distances[i]);

3

bench/bench-area.js

@@ -9,4 +9,2 @@ 'use strict';

var ruler = cheapRuler(32.8351);
var polygons = [];

@@ -27,2 +25,3 @@

'ruler.area': function () {
var ruler = cheapRuler(32.8351);
for (var i = 0; i < polygons.length; i++) {

@@ -29,0 +28,0 @@ ruler.area(polygons[i]);

@@ -10,4 +10,2 @@ 'use strict';

var ruler = cheapRuler(32.8351);
runBench({

@@ -20,2 +18,3 @@ 'turf.bearing': function () {

'ruler.bearing': function () {
var ruler = cheapRuler(32.8351);
for (var i = 0; i < points.length - 1; i++) {

@@ -22,0 +21,0 @@ ruler.bearing(points[i], points[i + 1]);

@@ -10,4 +10,2 @@ 'use strict';

var ruler = cheapRuler(32.8351);
runBench({

@@ -20,2 +18,3 @@ 'turf.destination-based bbox': function () {

'ruler.bufferPoint': function () {
var ruler = cheapRuler(32.8351);
for (var i = 0; i < points.length; i++) {

@@ -22,0 +21,0 @@ ruler.bufferPoint(points[i], 0.01);

@@ -10,4 +10,2 @@ 'use strict';

var ruler = cheapRuler(32.8351);
runBench({

@@ -20,2 +18,3 @@ 'turf.destination': function () {

'ruler.destination': function () {
var ruler = cheapRuler(32.8351);
for (var i = 0; i < points.length; i++) {

@@ -22,0 +21,0 @@ ruler.destination(points[i], 1, (i % 360) - 180);

@@ -9,4 +9,2 @@ 'use strict';

var ruler = cheapRuler(32.8351);
runBench({

@@ -19,6 +17,17 @@ 'turf.lineDistance': function () {

'ruler.lineDistance': function () {
var ruler = cheapRuler(32.8351);
for (var i = 0; i < lines.length; i++) {
ruler.lineDistance(lines[i]);
}
},
'new ruler for every point': function () {
for (var i = 0; i < lines.length; i++) {
var sum = 0;
for (var j = 0; j < lines[i].length - 1; j++) {
var p1 = lines[i][j];
var p2 = lines[i][j + 1];
sum += cheapRuler((p1[1] + p2[1]) / 2).distance(p1, p2);
}
}
}
});

@@ -23,2 +23,3 @@ 'use strict';

'ruler.insideBBox': function () {
var ruler = cheapRuler(32.8351);
for (var i = 0; i < points.length; i++) {

@@ -25,0 +26,0 @@ ruler.insideBBox(points[i], bboxes[i]);

@@ -26,2 +26,3 @@ 'use strict';

'ruler.lineSliceAlong': function () {
var ruler = cheapRuler(32.8351);
for (var i = 0; i < lines.length; i++) {

@@ -28,0 +29,0 @@ ruler.lineSliceAlong(distances[i] * 0.3, distances[i] * 0.7, lines[i]);

@@ -29,2 +29,3 @@ 'use strict';

'ruler.lineSlice': function () {
var ruler = cheapRuler(32.8351);
for (var i = 0; i < lines.length; i++) {

@@ -31,0 +32,0 @@ ruler.lineSlice(endpoints[i].start, endpoints[i].stop, lines[i]);

@@ -9,3 +9,2 @@ 'use strict';

var ruler = cheapRuler(32.8351);
var p = [-96.9159, 32.8351];

@@ -20,2 +19,3 @@

'ruler.pointOnLine': function () {
var ruler = cheapRuler(32.8351);
for (var i = 0; i < lines.length; i++) {

@@ -22,0 +22,0 @@ ruler.pointOnLine(lines[i], p);

@@ -32,10 +32,12 @@ (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){

var f = lat * Math.PI / 180;
var m = units ? factors[units] : 1;
// longitude correction
this.kx = m * (111.41513 * Math.cos(f) - 0.09455 * Math.cos(3 * f) + 0.00012 * Math.cos(5 * f));
var cos = Math.cos(lat * Math.PI / 180);
var cos2 = 2 * cos * cos - 1;
var cos3 = 2 * cos * cos2 - cos;
var cos4 = 2 * cos * cos3 - cos2;
var cos5 = 2 * cos * cos4 - cos3;
// latitude correction
this.ky = m * (111.13209 - 0.56605 * Math.cos(2 * f) + 0.0012 * Math.cos(4 * f));
this.kx = m * (111.41513 * cos - 0.09455 * cos3 + 0.00012 * cos5); // longitude correction
this.ky = m * (111.13209 - 0.56605 * cos2 + 0.0012 * cos4); // latitude correction
}

@@ -42,0 +44,0 @@

@@ -17,10 +17,10 @@ 'use strict';

var distances = [1, 100, 500, 1000, 5000];
var distances = [1, 100, 500, 1000, 2000];
for (var i = 0; i < distances.length; i++) {
var dist = distances[i];
process.stdout.write('| ' + dist + 'km | ');
process.stdout.write('| ' + dist + 'mi | ');
for (var lat = 0; lat <= 80; lat += 10) {
var ruler = createRuler(lat);
var ruler = createRuler(lat, 'miles');

@@ -30,5 +30,5 @@ var p1 = ruler.destination([0, lat], dist / 2, 45);

var d = ruler.distance(p1, p2);
// var d = turf.distance(turf.point(p1), turf.point(p2));
// var d = turf.distance(turf.point(p1), turf.point(p2), 'miles');
// var d = fccDist(p1, p2, lat);
var d2 = vincenty.distVincenty(p1[1], p1[0], p2[1], p2[0]).distance / 1000;
var d2 = createRuler.units.miles * vincenty.distVincenty(p1[1], p1[0], p2[1], p2[0]).distance / 1000;
var err = Math.abs((d - d2) / d2);

@@ -35,0 +35,0 @@ var errStr = (Math.round(100 * 1e2 * err) / 1e2) + '%';

@@ -31,10 +31,12 @@ 'use strict'; /* @flow */

var f = lat * Math.PI / 180;
var m = units ? factors[units] : 1;
// longitude correction
this.kx = m * (111.41513 * Math.cos(f) - 0.09455 * Math.cos(3 * f) + 0.00012 * Math.cos(5 * f));
var cos = Math.cos(lat * Math.PI / 180);
var cos2 = 2 * cos * cos - 1;
var cos3 = 2 * cos * cos2 - cos;
var cos4 = 2 * cos * cos3 - cos2;
var cos5 = 2 * cos * cos4 - cos3;
// latitude correction
this.ky = m * (111.13209 - 0.56605 * Math.cos(2 * f) + 0.0012 * Math.cos(4 * f));
this.kx = m * (111.41513 * cos - 0.09455 * cos3 + 0.00012 * cos5); // longitude correction
this.ky = m * (111.13209 - 0.56605 * cos2 + 0.0012 * cos4); // latitude correction
}

@@ -41,0 +43,0 @@

{
"name": "cheap-ruler",
"version": "2.4.0",
"version": "2.4.1",
"description": "A collection of fast approximations to common geographic measurements.",

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

@@ -14,19 +14,19 @@ # cheap-ruler [![Build Status](https://travis-ci.org/mapbox/cheap-ruler.svg?branch=master)](https://travis-ci.org/mapbox/cheap-ruler) [![](https://img.shields.io/badge/simply-awesome-brightgreen.svg)](https://github.com/mourner/projects)

Compared to corresponding [Turf](http://turfjs.org/) methods (using Node v5.10):
Compared to corresponding [Turf](http://turfjs.org/) methods (using Node v6):
- `distance`: ~26x faster
- `bearing`: ~3.5x faster
- `destination`: ~6.4x faster
- `lineDistance`: ~26x faster
- `area`: ~3.6x faster
- `along`: ~21x faster
- `pointOnLine`: ~72x faster
- `lineSlice`: ~56x faster
- `distance`: ~31x faster
- `bearing`: ~3.6x faster
- `destination`: ~7.2x faster
- `lineDistance`: ~31x faster
- `area`: ~3.4x faster
- `along`: ~31x faster
- `pointOnLine`: ~78x faster
- `lineSlice`: ~60x faster
Additional utility methods:
- `lineSliceAlong`: ~268x faster than `turf.lineSlice(turf.along(...`
- `bufferPoint`: ~210x faster than creating a bounding box with two diagonal `turf.destination` calls
- `bufferBBox`: ~210x faster (likewise)
- `insideBBox`: ~24x faster than `turf.inside(turf.point(p), turf.bboxPolygon(bbox))`
- `lineSliceAlong`: ~285x faster than `turf.lineSlice(turf.along(...`
- `bufferPoint`: ~260x faster than creating a bounding box with two diagonal `turf.destination` calls
- `bufferBBox`: ~260x faster (likewise)
- `insideBBox`: ~19x faster than `turf.inside(turf.point(p), turf.bboxPolygon(bbox))`

@@ -33,0 +33,0 @@ ## Usage

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