@turf/line-distance
Advanced tools
Comparing version 3.3.3 to 3.5.2-alpha.d2c36ee7
@@ -5,6 +5,6 @@ var distance = require('@turf/distance'); | ||
/** | ||
* Takes a {@link LineString|line} and measures its length in the specified units. | ||
* Takes a {@link LineString} or {@link Polygon} and measures its length in the specified units. | ||
* | ||
* @name lineDistance | ||
* @param {Feature<LineString>} line line to measure | ||
* @param {Feature<(LineString|Polygon)>|FeatureCollection<(LineString|Polygon)>} line line to measure | ||
* @param {String} [units=kilometers] can be degrees, radians, miles, or kilometers | ||
@@ -53,3 +53,3 @@ * @return {Number} length of the input line | ||
return d; | ||
} else if (line.type === 'MultiPolygon') { | ||
} else if (geometry.type === 'MultiPolygon') { | ||
d = 0; | ||
@@ -56,0 +56,0 @@ for (i = 0; i < geometry.coordinates.length; i++) { |
{ | ||
"name": "@turf/line-distance", | ||
"version": "3.3.3", | ||
"version": "3.5.2-alpha.d2c36ee7", | ||
"description": "turf-line-distance ---", | ||
@@ -32,5 +32,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"@turf/distance": "^3.3.3", | ||
"@turf/helpers": "^3.3.3" | ||
"@turf/distance": "^3.5.2-alpha.d2c36ee7", | ||
"@turf/helpers": "^3.5.2-alpha.d2c36ee7" | ||
} | ||
} |
@@ -5,7 +5,7 @@ # @turf/line-distance | ||
Takes a [line](http://geojson.org/geojson-spec.html#linestring) and measures its length in the specified units. | ||
Takes a [LineString](http://geojson.org/geojson-spec.html#linestring) or [Polygon](http://geojson.org/geojson-spec.html#polygon) and measures its length in the specified units. | ||
**Parameters** | ||
- `line` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<[LineString](http://geojson.org/geojson-spec.html#linestring)>** line to measure | ||
- `line` **([Feature](http://geojson.org/geojson-spec.html#feature-objects)<([LineString](http://geojson.org/geojson-spec.html#linestring) \| [Polygon](http://geojson.org/geojson-spec.html#polygon))> | [FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)<([LineString](http://geojson.org/geojson-spec.html#linestring) \| [Polygon](http://geojson.org/geojson-spec.html#polygon))>)** line to measure | ||
- `units` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** can be degrees, radians, miles, or kilometers (optional, default `kilometers`) | ||
@@ -41,2 +41,6 @@ | ||
<!-- This file is automatically generated. Please don't edit it directly: | ||
if you find an error, edit the source file (likely index.js), and re-run | ||
./scripts/generate-readmes in the turf project. --> | ||
--- | ||
@@ -43,0 +47,0 @@ |
47
test.js
@@ -8,17 +8,36 @@ var test = require('tape'); | ||
test('LineString', function (t) { | ||
t.equal(Math.round(lineDistance(route1, 'miles')), 202); | ||
t.true((lineDistance(route2, 'kilometers') - 742) < 1 && | ||
(lineDistance(route2, 'kilometers') - 742) > (-1) ); | ||
test('Geometry', function (t) { | ||
t.equal(Math.round(lineDistance(route1.geometry, 'miles')), 202); | ||
t.true((lineDistance(route2.geometry, 'kilometers') - 742) < 1 && (lineDistance(route2.geometry, 'kilometers') - 742) > (-1) ); | ||
t.end(); | ||
}); | ||
test('turf-line-distance with geometries', function (t) { | ||
t.equal(Math.round(lineDistance(route1.geometry, 'miles')), 202); | ||
t.true((lineDistance(route2.geometry, 'kilometers') - 742) < 1 && | ||
(lineDistance(route2.geometry, 'kilometers') - 742) > (-1) ); | ||
test('Point', function (t) { | ||
var point1 = { | ||
type: "Feature", | ||
geometry: {type: "Point", coordinates: [-75.343, 39.984]} | ||
}; | ||
t.throws(function() { | ||
lineDistance(point1, 'miles'); | ||
}); | ||
t.end(); | ||
}); | ||
test('MultiPoint', function (t) { | ||
var multiPoint1 = { | ||
type: "Feature", | ||
geometry: {type: "MultiPoint", coordinates: [[-75.343, 39.984], [-75.534, 39.123]]} | ||
}; | ||
t.throws(function() { | ||
lineDistance(multiPoint1, 'miles'); | ||
}); | ||
t.end(); | ||
}); | ||
test('LineString', function (t) { | ||
t.equal(Math.round(lineDistance(route1, 'miles')), 202); | ||
t.true((lineDistance(route2, 'kilometers') - 742) < 1 && (lineDistance(route2, 'kilometers') - 742) > (-1) ); | ||
t.end(); | ||
}); | ||
test('Polygon', function (t) { | ||
@@ -28,3 +47,3 @@ var feat = JSON.parse(fs.readFileSync(__dirname + '/test/polygon.geojson')); | ||
t.end(); | ||
}) | ||
}); | ||
@@ -35,4 +54,10 @@ test('MultiLineString', function (t) { | ||
t.end(); | ||
}) | ||
}); | ||
test('MultiPolygon', function (t) { | ||
var feat = JSON.parse(fs.readFileSync(__dirname + '/test/multipolygon.geojson')); | ||
t.equal(Math.round(1000 * lineDistance(feat, 'kilometers')), 8334); | ||
t.end(); | ||
}); | ||
test('FeatureCollection', function (t) { | ||
@@ -42,2 +67,2 @@ var feat = JSON.parse(fs.readFileSync(__dirname + '/test/featurecollection.geojson')); | ||
t.end(); | ||
}) | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
186
0
64
9886
7
1
1