@turf/line-slice-along
Advanced tools
Comparing version 6.2.0-alpha.2 to 6.2.0-alpha.3
@@ -30,56 +30,57 @@ import bearing from '@turf/bearing'; | ||
function lineSliceAlong(line, startDist, stopDist, options) { | ||
// Optional parameters | ||
options = options || {}; | ||
if (!isObject(options)) throw new Error('options is invalid'); | ||
// Optional parameters | ||
options = options || {}; | ||
if (!isObject(options)) throw new Error("options is invalid"); | ||
var coords; | ||
var slice = []; | ||
var coords; | ||
var slice = []; | ||
// Validation | ||
if (line.type === 'Feature') coords = line.geometry.coordinates; | ||
else if (line.type === 'LineString') coords = line.coordinates; | ||
else throw new Error('input must be a LineString Feature or Geometry'); | ||
var origCoordsLength = coords.length; | ||
var travelled = 0; | ||
var overshot, direction, interpolated; | ||
for (var i = 0; i < coords.length; i++) { | ||
if (startDist >= travelled && i === coords.length - 1) break; | ||
else if (travelled > startDist && slice.length === 0) { | ||
overshot = startDist - travelled; | ||
if (!overshot) { | ||
slice.push(coords[i]); | ||
return lineString(slice); | ||
} | ||
direction = bearing(coords[i], coords[i - 1]) - 180; | ||
interpolated = destination(coords[i], overshot, direction, options); | ||
slice.push(interpolated.geometry.coordinates); | ||
} | ||
// Validation | ||
if (line.type === "Feature") coords = line.geometry.coordinates; | ||
else if (line.type === "LineString") coords = line.coordinates; | ||
else throw new Error("input must be a LineString Feature or Geometry"); | ||
var origCoordsLength = coords.length; | ||
var travelled = 0; | ||
var overshot, direction, interpolated; | ||
for (var i = 0; i < coords.length; i++) { | ||
if (startDist >= travelled && i === coords.length - 1) break; | ||
else if (travelled > startDist && slice.length === 0) { | ||
overshot = startDist - travelled; | ||
if (!overshot) { | ||
slice.push(coords[i]); | ||
return lineString(slice); | ||
} | ||
direction = bearing(coords[i], coords[i - 1]) - 180; | ||
interpolated = destination(coords[i], overshot, direction, options); | ||
slice.push(interpolated.geometry.coordinates); | ||
} | ||
if (travelled >= stopDist) { | ||
overshot = stopDist - travelled; | ||
if (!overshot) { | ||
slice.push(coords[i]); | ||
return lineString(slice); | ||
} | ||
direction = bearing(coords[i], coords[i - 1]) - 180; | ||
interpolated = destination(coords[i], overshot, direction, options); | ||
slice.push(interpolated.geometry.coordinates); | ||
return lineString(slice); | ||
} | ||
if (travelled >= stopDist) { | ||
overshot = stopDist - travelled; | ||
if (!overshot) { | ||
slice.push(coords[i]); | ||
return lineString(slice); | ||
} | ||
direction = bearing(coords[i], coords[i - 1]) - 180; | ||
interpolated = destination(coords[i], overshot, direction, options); | ||
slice.push(interpolated.geometry.coordinates); | ||
return lineString(slice); | ||
} | ||
if (travelled >= startDist) { | ||
slice.push(coords[i]); | ||
} | ||
if (travelled >= startDist) { | ||
slice.push(coords[i]); | ||
} | ||
if (i === coords.length - 1) { | ||
return lineString(slice); | ||
} | ||
travelled += distance(coords[i], coords[i + 1], options); | ||
if (i === coords.length - 1) { | ||
return lineString(slice); | ||
} | ||
if (travelled < startDist && coords.length === origCoordsLength) throw new Error('Start position is beyond line'); | ||
return lineString(coords[coords.length - 1]); | ||
travelled += distance(coords[i], coords[i + 1], options); | ||
} | ||
if (travelled < startDist && coords.length === origCoordsLength) | ||
throw new Error("Start position is beyond line"); | ||
return lineString(coords[coords.length - 1]); | ||
} | ||
export default lineSliceAlong; |
@@ -34,57 +34,57 @@ 'use strict'; | ||
function lineSliceAlong(line, startDist, stopDist, options) { | ||
// Optional parameters | ||
options = options || {}; | ||
if (!helpers.isObject(options)) throw new Error('options is invalid'); | ||
// Optional parameters | ||
options = options || {}; | ||
if (!helpers.isObject(options)) throw new Error("options is invalid"); | ||
var coords; | ||
var slice = []; | ||
var coords; | ||
var slice = []; | ||
// Validation | ||
if (line.type === 'Feature') coords = line.geometry.coordinates; | ||
else if (line.type === 'LineString') coords = line.coordinates; | ||
else throw new Error('input must be a LineString Feature or Geometry'); | ||
var origCoordsLength = coords.length; | ||
var travelled = 0; | ||
var overshot, direction, interpolated; | ||
for (var i = 0; i < coords.length; i++) { | ||
if (startDist >= travelled && i === coords.length - 1) break; | ||
else if (travelled > startDist && slice.length === 0) { | ||
overshot = startDist - travelled; | ||
if (!overshot) { | ||
slice.push(coords[i]); | ||
return helpers.lineString(slice); | ||
} | ||
direction = bearing(coords[i], coords[i - 1]) - 180; | ||
interpolated = destination(coords[i], overshot, direction, options); | ||
slice.push(interpolated.geometry.coordinates); | ||
} | ||
// Validation | ||
if (line.type === "Feature") coords = line.geometry.coordinates; | ||
else if (line.type === "LineString") coords = line.coordinates; | ||
else throw new Error("input must be a LineString Feature or Geometry"); | ||
var origCoordsLength = coords.length; | ||
var travelled = 0; | ||
var overshot, direction, interpolated; | ||
for (var i = 0; i < coords.length; i++) { | ||
if (startDist >= travelled && i === coords.length - 1) break; | ||
else if (travelled > startDist && slice.length === 0) { | ||
overshot = startDist - travelled; | ||
if (!overshot) { | ||
slice.push(coords[i]); | ||
return helpers.lineString(slice); | ||
} | ||
direction = bearing(coords[i], coords[i - 1]) - 180; | ||
interpolated = destination(coords[i], overshot, direction, options); | ||
slice.push(interpolated.geometry.coordinates); | ||
} | ||
if (travelled >= stopDist) { | ||
overshot = stopDist - travelled; | ||
if (!overshot) { | ||
slice.push(coords[i]); | ||
return helpers.lineString(slice); | ||
} | ||
direction = bearing(coords[i], coords[i - 1]) - 180; | ||
interpolated = destination(coords[i], overshot, direction, options); | ||
slice.push(interpolated.geometry.coordinates); | ||
return helpers.lineString(slice); | ||
} | ||
if (travelled >= stopDist) { | ||
overshot = stopDist - travelled; | ||
if (!overshot) { | ||
slice.push(coords[i]); | ||
return helpers.lineString(slice); | ||
} | ||
direction = bearing(coords[i], coords[i - 1]) - 180; | ||
interpolated = destination(coords[i], overshot, direction, options); | ||
slice.push(interpolated.geometry.coordinates); | ||
return helpers.lineString(slice); | ||
} | ||
if (travelled >= startDist) { | ||
slice.push(coords[i]); | ||
} | ||
if (travelled >= startDist) { | ||
slice.push(coords[i]); | ||
} | ||
if (i === coords.length - 1) { | ||
return helpers.lineString(slice); | ||
} | ||
travelled += distance(coords[i], coords[i + 1], options); | ||
if (i === coords.length - 1) { | ||
return helpers.lineString(slice); | ||
} | ||
if (travelled < startDist && coords.length === origCoordsLength) throw new Error('Start position is beyond line'); | ||
return helpers.lineString(coords[coords.length - 1]); | ||
travelled += distance(coords[i], coords[i + 1], options); | ||
} | ||
if (travelled < startDist && coords.length === origCoordsLength) | ||
throw new Error("Start position is beyond line"); | ||
return helpers.lineString(coords[coords.length - 1]); | ||
} | ||
module.exports = lineSliceAlong; | ||
module.exports.default = lineSliceAlong; |
@@ -1,2 +0,2 @@ | ||
import { Units, LineString, Feature} from '@turf/helpers' | ||
import { Units, LineString, Feature } from "@turf/helpers"; | ||
@@ -7,8 +7,8 @@ /** | ||
export default function lineSliceAlong( | ||
line: Feature<LineString> | LineString, | ||
startDist: number, | ||
stopDist: number, | ||
options?: { | ||
units?: Units | ||
} | ||
line: Feature<LineString> | LineString, | ||
startDist: number, | ||
stopDist: number, | ||
options?: { | ||
units?: Units; | ||
} | ||
): Feature<LineString>; |
{ | ||
"name": "@turf/line-slice-along", | ||
"version": "6.2.0-alpha.2", | ||
"version": "6.2.0-alpha.3", | ||
"description": "turf line-slice-along module", | ||
@@ -25,2 +25,6 @@ "author": "Turf Authors", | ||
"module": "dist/es/index.js", | ||
"exports": { | ||
"import": "./dist/es/index.js", | ||
"require": "./dist/js/index.js" | ||
}, | ||
"types": "index.d.ts", | ||
@@ -33,12 +37,11 @@ "sideEffects": false, | ||
"scripts": { | ||
"bench": "npm-run-all prepare bench:run", | ||
"bench:run": "node bench.js", | ||
"bench": "node -r esm bench.js", | ||
"build": "rollup -c ../../rollup.config.js && echo '{\"type\":\"module\"}' > dist/es/package.json", | ||
"docs": "node ../../scripts/generate-readmes", | ||
"posttest": "node -r esm ../../scripts/validate-es5-dependencies.js", | ||
"prepare": "rollup -c ../../rollup.config.js", | ||
"test": "npm-run-all prepare test:*", | ||
"test": "npm-run-all test:*", | ||
"test:tape": "node -r esm test.js" | ||
}, | ||
"devDependencies": { | ||
"@turf/along": "^6.2.0-alpha.2", | ||
"@turf/along": "^6.2.0-alpha.3", | ||
"benchmark": "*", | ||
@@ -51,8 +54,8 @@ "load-json-file": "*", | ||
"dependencies": { | ||
"@turf/bearing": "^6.2.0-alpha.2", | ||
"@turf/destination": "^6.2.0-alpha.2", | ||
"@turf/distance": "^6.2.0-alpha.2", | ||
"@turf/helpers": "^6.2.0-alpha.2" | ||
"@turf/bearing": "^6.2.0-alpha.3", | ||
"@turf/destination": "^6.2.0-alpha.3", | ||
"@turf/distance": "^6.2.0-alpha.3", | ||
"@turf/helpers": "^6.2.0-alpha.3" | ||
}, | ||
"gitHead": "23d5cb91d77e0c1e2e903a2252f525797f1d0d09" | ||
"gitHead": "dce9edfc705352e8cb9e0083c9330ba0e8d77409" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8
241
14663