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.2.0 to 2.3.0

20

cheap-ruler.js
(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){
'use strict';
'use strict'; /* @flow */
module.exports = cheapRuler;
function cheapRuler(lat, units) {
function cheapRuler(lat /*: number */, units /*: ?string */) {
return new CheapRuler(lat, units);
}
// unit multipliers for conversion from kilometers
var factors = {
miles: 1000 / 1609.344,
nauticalmiles: 1000 / 1852,
meters: 1000,
metres: 1000,
yards: 1000 / 0.9144,
feet: 1000 / 0.3048,
inches: 1000 / 0.0254
};
cheapRuler.fromTile = function (y, z, units) {

@@ -20,7 +31,4 @@ var n = Math.PI * (1 - 2 * (y + 0.5) / Math.pow(2, z));

var f = lat * Math.PI / 180;
var m = units ? factors[units] : 1;
// multiplier for unit conversion
var m = units === 'miles' ? 1.609344 :
units === 'meters' ? 1000 : 1;
// longitude correction

@@ -27,0 +35,0 @@ this.kx = m * (111.41513 * Math.cos(f) - 0.09455 * Math.cos(3 * f) + 0.00012 * Math.cos(5 * f));

@@ -1,9 +0,20 @@

'use strict';
'use strict'; /* @flow */
module.exports = cheapRuler;
function cheapRuler(lat, units) {
function cheapRuler(lat /*: number */, units /*: ?string */) {
return new CheapRuler(lat, units);
}
// unit multipliers for conversion from kilometers
var factors = {
miles: 1000 / 1609.344,
nauticalmiles: 1000 / 1852,
meters: 1000,
metres: 1000,
yards: 1000 / 0.9144,
feet: 1000 / 0.3048,
inches: 1000 / 0.0254
};
cheapRuler.fromTile = function (y, z, units) {

@@ -19,7 +30,4 @@ var n = Math.PI * (1 - 2 * (y + 0.5) / Math.pow(2, z));

var f = lat * Math.PI / 180;
var m = units ? factors[units] : 1;
// multiplier for unit conversion
var m = units === 'miles' ? 1.609344 :
units === 'meters' ? 1000 : 1;
// longitude correction

@@ -26,0 +34,0 @@ this.kx = m * (111.41513 * Math.cos(f) - 0.09455 * Math.cos(3 * f) + 0.00012 * Math.cos(5 * f));

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

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

@@ -1,6 +0,5 @@

# cheap-ruler [![Build Status](https://travis-ci.org/mapbox/cheap-ruler.svg?branch=master)](https://travis-ci.org/mapbox/cheap-ruler)
# 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)
A collection of fast approximations to common geographic measurements, along with some utility functions.
Useful for speeding up analysis scripts when measuring things on a city scale,
replacing [Turf](http://turfjs.org/) calls in key places.
A collection of very fast approximations to common geodesic measurements.
Useful for performance-sensitive code that measures things on a city scale.

@@ -15,3 +14,3 @@ The approximations are based on an [FCC-approved formula of ellipsoidal Earth projection](https://www.gpo.gov/fdsys/pkg/CFR-2005-title47-vol4/pdf/CFR-2005-title47-vol4-sec73-208.pdf).

Compared to corresponding Turf methods (using Node v5.10):
Compared to corresponding [Turf](http://turfjs.org/) methods (using Node v5.10):

@@ -38,3 +37,3 @@ - `distance`: ~26x faster

var ruler = cheapRuler(35.05, 'miles');
// ...
var distance = ruler.distance([30.51, 50.32], [30.52, 50.312]);

@@ -45,3 +44,6 @@ var lineLength = ruler.lineDistance(line.geometry.coordinates);

**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.
**Note**: to get the full performance benefit,
create a ruler object only once per a general area of calculation,
and then reuse it as much as possible.
Don't create a new ruler for every calculation.

@@ -53,3 +55,3 @@ ### Creating a ruler object

Creates a ruler object that will approximate measurements around the given latitude.
Units are either `kilometers` (default) or `miles`.
Units are one of: `kilometers` (default), `miles`, `nauticalmiles`, `meters`, `yards`, `feet`, `inches`.

@@ -56,0 +58,0 @@ #### cheapRuler.fromTile(y, z[, units])

@@ -35,2 +35,11 @@ 'use strict';

test('distance in miles', function (t) {
var d = ruler.distance([30.5, 32.8351], [30.51, 32.8451]);
var d2 = milesRuler.distance([30.5, 32.8351], [30.51, 32.8451]);
assertErr(t, d / d2, 1.609344, 1e-12, 'distance in miles');
t.pass('distance in miles');
t.end();
});
test('bearing', function (t) {

@@ -164,8 +173,8 @@ for (var i = 0; i < points.length - 1; i++) {

var actual = milesRuler.bufferPoint(points[i], 0.1);
assertErr(t, expected[0], actual[0], 3e-5, 'bufferPoint west');
assertErr(t, expected[1], actual[1], 3e-5, 'bufferPoint east');
assertErr(t, expected[2], actual[2], 3e-5, 'bufferPoint south');
assertErr(t, expected[3], actual[3], 3e-5, 'bufferPoint north');
assertErr(t, expected[0], actual[0], 2e-7, 'bufferPoint west');
assertErr(t, expected[1], actual[1], 2e-7, 'bufferPoint east');
assertErr(t, expected[2], actual[2], 2e-7, 'bufferPoint south');
assertErr(t, expected[3], actual[3], 2e-7, 'bufferPoint north');
}
t.pass('point buffer error within 3e-5');
t.pass('point buffer error within 2e-7');
t.end();

@@ -172,0 +181,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