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

cheap-ruler

Package Overview
Dependencies
Maintainers
15
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 3.0.1 to 3.0.2

1

cheap-ruler.d.ts

@@ -30,2 +30,3 @@ export type BBox = [number, number, number, number];

public along(line: Line, dist: number): Point;
public pointToSegmentDistance(p: Point, a: Point, b: Point): number;
public pointOnLine(line: Line, p: Point): {point: Point, index: number, t: number};

@@ -32,0 +33,0 @@ public lineSlice(start: Point, stop: Point, line: Line): Line;

20

cheap-ruler.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.CheapRuler = factory());
}(this, (function () { 'use strict';
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.CheapRuler = factory());
})(this, (function () { 'use strict';
/**
* Multipliers for converting between units.
*
* @example
* // convert 50 meters to yards
* 50 * cheapRuler.units.yards / cheapRuler.units.meters;
*/
var factors = {

@@ -75,2 +68,9 @@ kilometers: 1,

/**
* Multipliers for converting between units.
*
* @example
* // convert 50 meters to yards
* 50 * CheapRuler.units.yards / CheapRuler.units.meters;
*/
staticAccessors.units.get = function () {

@@ -464,2 +464,2 @@ return factors;

})));
}));

@@ -1,1 +0,1 @@

!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t=t||self).CheapRuler=n()}(this,(function(){"use strict";var t={kilometers:1,miles:1e3/1609.344,nauticalmiles:1e3/1852,meters:1e3,metres:1e3,yards:1e3/.9144,feet:1e3/.3048,inches:1e3/.0254},n=1/298.257223563,e=n*(2-n),i=Math.PI/180,r=function(n,r){if(void 0===n)throw new Error("No latitude given.");if(r&&!t[r])throw new Error("Unknown unit "+r+". Use one of: "+Object.keys(t).join(", "));var o=6378.137*i*(r?t[r]:1),s=Math.cos(n*i),h=1/(1-e*(1-s*s)),a=Math.sqrt(h);this.kx=o*a*s,this.ky=o*a*h*(1-e)},o={units:{configurable:!0}};function s(t,n){return t[0]===n[0]&&t[1]===n[1]}function h(t,n,e){var i=a(n[0]-t[0]),r=n[1]-t[1];return[t[0]+i*e,t[1]+r*e]}function a(t){for(;t<-180;)t+=360;for(;t>180;)t-=360;return t}return r.fromTile=function(t,n,e){var o=Math.PI*(1-2*(t+.5)/Math.pow(2,n)),s=Math.atan(.5*(Math.exp(o)-Math.exp(-o)))/i;return new r(s,e)},o.units.get=function(){return t},r.prototype.distance=function(t,n){var e=a(t[0]-n[0])*this.kx,i=(t[1]-n[1])*this.ky;return Math.sqrt(e*e+i*i)},r.prototype.bearing=function(t,n){var e=a(n[0]-t[0])*this.kx,r=(n[1]-t[1])*this.ky;return Math.atan2(e,r)/i},r.prototype.destination=function(t,n,e){var r=e*i;return this.offset(t,Math.sin(r)*n,Math.cos(r)*n)},r.prototype.offset=function(t,n,e){return[t[0]+n/this.kx,t[1]+e/this.ky]},r.prototype.lineDistance=function(t){for(var n=0,e=0;e<t.length-1;e++)n+=this.distance(t[e],t[e+1]);return n},r.prototype.area=function(t){for(var n=0,e=0;e<t.length;e++)for(var i=t[e],r=0,o=i.length,s=o-1;r<o;s=r++)n+=a(i[r][0]-i[s][0])*(i[r][1]+i[s][1])*(e?-1:1);return Math.abs(n)/2*this.kx*this.ky},r.prototype.along=function(t,n){var e=0;if(n<=0)return t[0];for(var i=0;i<t.length-1;i++){var r=t[i],o=t[i+1],s=this.distance(r,o);if((e+=s)>n)return h(r,o,(n-(e-s))/s)}return t[t.length-1]},r.prototype.pointToSegmentDistance=function(t,n,e){var i=n[0],r=n[1],o=a(e[0]-i)*this.kx,s=(e[1]-r)*this.ky,h=0;return 0===o&&0===s||((h=(a(t[0]-i)*this.kx*o+(t[1]-r)*this.ky*s)/(o*o+s*s))>1?(i=e[0],r=e[1]):h>0&&(i+=o/this.kx*h,r+=s/this.ky*h)),o=a(t[0]-i)*this.kx,s=(t[1]-r)*this.ky,Math.sqrt(o*o+s*s)},r.prototype.pointOnLine=function(t,n){for(var e,i,r,o,s=1/0,h=0;h<t.length-1;h++){var u=t[h][0],f=t[h][1],p=a(t[h+1][0]-u)*this.kx,c=(t[h+1][1]-f)*this.ky,y=0;0===p&&0===c||((y=(a(n[0]-u)*this.kx*p+(n[1]-f)*this.ky*c)/(p*p+c*c))>1?(u=t[h+1][0],f=t[h+1][1]):y>0&&(u+=p/this.kx*y,f+=c/this.ky*y));var k=(p=a(n[0]-u)*this.kx)*p+(c=(n[1]-f)*this.ky)*c;k<s&&(s=k,e=u,i=f,r=h,o=y)}return{point:[e,i],index:r,t:Math.max(0,Math.min(1,o))}},r.prototype.lineSlice=function(t,n,e){var i=this.pointOnLine(e,t),r=this.pointOnLine(e,n);if(i.index>r.index||i.index===r.index&&i.t>r.t){var o=i;i=r,r=o}var h=[i.point],a=i.index+1,u=r.index;!s(e[a],h[0])&&a<=u&&h.push(e[a]);for(var f=a+1;f<=u;f++)h.push(e[f]);return s(e[u],r.point)||h.push(r.point),h},r.prototype.lineSliceAlong=function(t,n,e){for(var i=0,r=[],o=0;o<e.length-1;o++){var s=e[o],a=e[o+1],u=this.distance(s,a);if((i+=u)>t&&0===r.length&&r.push(h(s,a,(t-(i-u))/u)),i>=n)return r.push(h(s,a,(n-(i-u))/u)),r;i>t&&r.push(a)}return r},r.prototype.bufferPoint=function(t,n){var e=n/this.ky,i=n/this.kx;return[t[0]-i,t[1]-e,t[0]+i,t[1]+e]},r.prototype.bufferBBox=function(t,n){var e=n/this.ky,i=n/this.kx;return[t[0]-i,t[1]-e,t[2]+i,t[3]+e]},r.prototype.insideBBox=function(t,n){return a(t[0]-n[0])>=0&&a(t[0]-n[2])<=0&&t[1]>=n[1]&&t[1]<=n[3]},Object.defineProperties(r,o),r}));
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t="undefined"!=typeof globalThis?globalThis:t||self).CheapRuler=n()}(this,(function(){"use strict";var t={kilometers:1,miles:1e3/1609.344,nauticalmiles:1e3/1852,meters:1e3,metres:1e3,yards:1e3/.9144,feet:1e3/.3048,inches:1e3/.0254},n=1/298.257223563,e=n*(2-n),i=Math.PI/180,r=function(n,r){if(void 0===n)throw new Error("No latitude given.");if(r&&!t[r])throw new Error("Unknown unit "+r+". Use one of: "+Object.keys(t).join(", "));var o=6378.137*i*(r?t[r]:1),s=Math.cos(n*i),h=1/(1-e*(1-s*s)),a=Math.sqrt(h);this.kx=o*a*s,this.ky=o*a*h*(1-e)},o={units:{configurable:!0}};function s(t,n){return t[0]===n[0]&&t[1]===n[1]}function h(t,n,e){var i=a(n[0]-t[0]),r=n[1]-t[1];return[t[0]+i*e,t[1]+r*e]}function a(t){for(;t<-180;)t+=360;for(;t>180;)t-=360;return t}return r.fromTile=function(t,n,e){var o=Math.PI*(1-2*(t+.5)/Math.pow(2,n)),s=Math.atan(.5*(Math.exp(o)-Math.exp(-o)))/i;return new r(s,e)},o.units.get=function(){return t},r.prototype.distance=function(t,n){var e=a(t[0]-n[0])*this.kx,i=(t[1]-n[1])*this.ky;return Math.sqrt(e*e+i*i)},r.prototype.bearing=function(t,n){var e=a(n[0]-t[0])*this.kx,r=(n[1]-t[1])*this.ky;return Math.atan2(e,r)/i},r.prototype.destination=function(t,n,e){var r=e*i;return this.offset(t,Math.sin(r)*n,Math.cos(r)*n)},r.prototype.offset=function(t,n,e){return[t[0]+n/this.kx,t[1]+e/this.ky]},r.prototype.lineDistance=function(t){for(var n=0,e=0;e<t.length-1;e++)n+=this.distance(t[e],t[e+1]);return n},r.prototype.area=function(t){for(var n=0,e=0;e<t.length;e++)for(var i=t[e],r=0,o=i.length,s=o-1;r<o;s=r++)n+=a(i[r][0]-i[s][0])*(i[r][1]+i[s][1])*(e?-1:1);return Math.abs(n)/2*this.kx*this.ky},r.prototype.along=function(t,n){var e=0;if(n<=0)return t[0];for(var i=0;i<t.length-1;i++){var r=t[i],o=t[i+1],s=this.distance(r,o);if((e+=s)>n)return h(r,o,(n-(e-s))/s)}return t[t.length-1]},r.prototype.pointToSegmentDistance=function(t,n,e){var i=n[0],r=n[1],o=a(e[0]-i)*this.kx,s=(e[1]-r)*this.ky,h=0;return 0===o&&0===s||((h=(a(t[0]-i)*this.kx*o+(t[1]-r)*this.ky*s)/(o*o+s*s))>1?(i=e[0],r=e[1]):h>0&&(i+=o/this.kx*h,r+=s/this.ky*h)),o=a(t[0]-i)*this.kx,s=(t[1]-r)*this.ky,Math.sqrt(o*o+s*s)},r.prototype.pointOnLine=function(t,n){for(var e,i,r,o,s=1/0,h=0;h<t.length-1;h++){var u=t[h][0],f=t[h][1],p=a(t[h+1][0]-u)*this.kx,c=(t[h+1][1]-f)*this.ky,y=0;0===p&&0===c||((y=(a(n[0]-u)*this.kx*p+(n[1]-f)*this.ky*c)/(p*p+c*c))>1?(u=t[h+1][0],f=t[h+1][1]):y>0&&(u+=p/this.kx*y,f+=c/this.ky*y));var k=(p=a(n[0]-u)*this.kx)*p+(c=(n[1]-f)*this.ky)*c;k<s&&(s=k,e=u,i=f,r=h,o=y)}return{point:[e,i],index:r,t:Math.max(0,Math.min(1,o))}},r.prototype.lineSlice=function(t,n,e){var i=this.pointOnLine(e,t),r=this.pointOnLine(e,n);if(i.index>r.index||i.index===r.index&&i.t>r.t){var o=i;i=r,r=o}var h=[i.point],a=i.index+1,u=r.index;!s(e[a],h[0])&&a<=u&&h.push(e[a]);for(var f=a+1;f<=u;f++)h.push(e[f]);return s(e[u],r.point)||h.push(r.point),h},r.prototype.lineSliceAlong=function(t,n,e){for(var i=0,r=[],o=0;o<e.length-1;o++){var s=e[o],a=e[o+1],u=this.distance(s,a);if((i+=u)>t&&0===r.length&&r.push(h(s,a,(t-(i-u))/u)),i>=n)return r.push(h(s,a,(n-(i-u))/u)),r;i>t&&r.push(a)}return r},r.prototype.bufferPoint=function(t,n){var e=n/this.ky,i=n/this.kx;return[t[0]-i,t[1]-e,t[0]+i,t[1]+e]},r.prototype.bufferBBox=function(t,n){var e=n/this.ky,i=n/this.kx;return[t[0]-i,t[1]-e,t[2]+i,t[3]+e]},r.prototype.insideBBox=function(t,n){return a(t[0]-n[0])>=0&&a(t[0]-n[2])<=0&&t[1]>=n[1]&&t[1]<=n[3]},Object.defineProperties(r,o),r}));
'use strict'; /* @flow */
/**
* Multipliers for converting between units.
*
* @example
* // convert 50 meters to yards
* 50 * cheapRuler.units.yards / cheapRuler.units.meters;
*/
const factors = {

@@ -56,2 +49,9 @@ kilometers: 1,

/**
* Multipliers for converting between units.
*
* @example
* // convert 50 meters to yards
* 50 * CheapRuler.units.yards / CheapRuler.units.meters;
*/
static get units() {

@@ -58,0 +58,0 @@ return factors;

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

@@ -13,14 +13,14 @@ "main": "cheap-ruler.js",

"@rollup/plugin-buble": "^0.21.3",
"@turf/turf": "^5.1.6",
"@turf/turf": "^6.5.0",
"benchmark": "^2.1.4",
"eslint": "^7.0.0",
"eslint": "^8.2.0",
"eslint-config-mourner": "^3.0.0",
"esm": "^3.2.25",
"node-vincenty": "0.0.6",
"nyc": "^15.0.1",
"rollup": "^2.10.2",
"rollup-plugin-terser": "^5.3.0",
"tape": "^5.0.0",
"ts-node": "^8.10.1",
"typescript": "^3.9.2"
"nyc": "^15.1.0",
"rollup": "^2.60.0",
"rollup-plugin-terser": "^7.0.2",
"tape": "^5.3.2",
"ts-node": "^10.4.0",
"typescript": "^4.4.4"
},

@@ -27,0 +27,0 @@ "scripts": {

@@ -110,3 +110,3 @@ # 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)

const distance = ruler.pointToSegmentDistance([-77.034076, 38.882017],
[-77.031669, 38.878605] [-77.029609, 38.881946]);
[-77.031669, 38.878605], [-77.029609, 38.881946]);
````

@@ -178,3 +178,3 @@

// convert 50 meters to yards
50 * cheapRuler.units.yards / cheapRuler.units.meters;
50 * CheapRuler.units.yards / CheapRuler.units.meters;
```

@@ -188,6 +188,6 @@

// get distance between points in feet
const distanceInFeet = ruler.distance(a, b) * cheapRuler.units.feet;
const distanceInFeet = ruler.distance(a, b) * CheapRuler.units.feet;
// make a bbox from a point with a 200 inch buffer
const box = ruler.bufferPoint(p, 200 / cheapRuler.units.inches);
const box = ruler.bufferPoint(p, 200 / CheapRuler.units.inches);
```

@@ -198,4 +198,4 @@

- NPM: `npm install cheap-ruler`
- [Browser build on CDN](https://unpkg.com/cheap-ruler@2.5.1/cheap-ruler.js)
- [Browser build on CDN (minified)](https://unpkg.com/cheap-ruler@2.5.1/cheap-ruler.min.js)
- [Browser build on CDN](https://unpkg.com/cheap-ruler@3.0.1/cheap-ruler.js)
- [Browser build on CDN (minified)](https://unpkg.com/cheap-ruler@3.0.1/cheap-ruler.min.js)

@@ -219,2 +219,3 @@ ## Precision

- [cheap-ruler-cpp](https://github.com/mapbox/cheap-ruler-cpp) – C++ port of this library
- [cheap-ruler-rs](https://github.com/vipera/cheap-ruler-rs) – Rust port of this library
- [flat-projection](https://github.com/Turbo87/flat-projection-rs) – Rust library based on the same concept
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