@turf/line-slice
Advanced tools
Comparing version 3.10.3 to 3.10.4
@@ -0,0 +0,0 @@ var lineSlice = require('./'); |
@@ -0,0 +0,0 @@ /// <reference types="geojson" /> |
@@ -0,0 +0,0 @@ var linestring = require('@turf/helpers').lineString; |
{ | ||
"name": "@turf/line-slice", | ||
"version": "3.10.3", | ||
"version": "3.10.4", | ||
"description": "", | ||
@@ -29,5 +29,11 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@turf/helpers": "^3.10.3", | ||
"@turf/truncate": "^3.10.0", | ||
"benchmark": "^1.0.0", | ||
"eslint": "^3.16.1", | ||
"eslint-config-mourner": "^2.0.1", | ||
"load-json-file": "^2.0.0", | ||
"mkdirp": "^0.5.1", | ||
"tape": "^3.5.0", | ||
"@turf/helpers": "^3.10.3" | ||
"write-json-file": "^2.0.0" | ||
}, | ||
@@ -34,0 +40,0 @@ "dependencies": { |
@@ -0,0 +0,0 @@ # @turf/line-slice |
140
test.js
@@ -1,112 +0,44 @@ | ||
var test = require('tape'); | ||
var fs = require('fs'); | ||
var lineSlice = require('./'); | ||
var point = require('@turf/helpers').point; | ||
var featurecollection = require('@turf/helpers').featureCollection; | ||
var linestring = require('@turf/helpers').lineString; | ||
const test = require('tape'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const load = require('load-json-file'); | ||
const write = require('write-json-file'); | ||
const mkdirp = require('mkdirp'); | ||
const featureCollection = require('@turf/helpers').featureCollection; | ||
const truncate = require('@turf/truncate'); | ||
const lineSlice = require('./'); | ||
var route1 = JSON.parse(fs.readFileSync(__dirname + '/test/in/route1.geojson')); | ||
var route2 = JSON.parse(fs.readFileSync(__dirname + '/test/in/route2.geojson')); | ||
var line1 = JSON.parse(fs.readFileSync(__dirname + '/test/in/line1.geojson')); | ||
var vertical = JSON.parse(fs.readFileSync(__dirname + '/test/in/vertical.geojson')); | ||
const directories = { | ||
in: path.join(__dirname, 'test', 'in') + path.sep, | ||
out: path.join(__dirname, 'test', 'out') + path.sep | ||
}; | ||
test('turf-line-slice -- line1', function (t) { | ||
var start = point([-97.79617309570312,22.254624939561698]); | ||
var stop = point([-97.72750854492188,22.057641623615734]); | ||
var sliced = lineSlice(start, stop, line1); | ||
sliced.properties['stroke'] = '#f0f'; | ||
sliced.properties['stroke-width'] = 6; | ||
fs.writeFileSync(__dirname+ '/test/out/line1_out.geojson', | ||
JSON.stringify(featurecollection([ | ||
line1, start, stop, sliced | ||
]), null, 2)); | ||
t.end(); | ||
const fixtures = fs.readdirSync(directories.in).map(folder => { | ||
return { | ||
folder, | ||
linestring: load.sync(path.join(directories.in, folder, 'linestring.geojson')), | ||
start: load.sync(path.join(directories.in, folder, 'start.geojson')), | ||
stop: load.sync(path.join(directories.in, folder, 'stop.geojson')) | ||
}; | ||
}); | ||
test('turf-line-slice -- raw geometry', function (t) { | ||
var start = point([-97.79617309570312,22.254624939561698]); | ||
var stop = point([-97.72750854492188,22.057641623615734]); | ||
test('turf-line-slice', t => { | ||
for (const {folder, linestring, start, stop} of fixtures) { | ||
const output = path.join(directories.out, folder) + path.sep; | ||
var sliced = lineSlice(start, stop, line1.geometry); | ||
sliced.properties['stroke'] = '#f0f'; | ||
sliced.properties['stroke-width'] = 6; | ||
const sliced = truncate(lineSlice(start, stop, linestring)); | ||
sliced.properties['stroke'] = '#f0f'; | ||
sliced.properties['stroke-width'] = 6; | ||
fs.writeFileSync(__dirname+ '/test/out/line1_out.geojson', | ||
JSON.stringify(featurecollection([ | ||
line1, start, stop, sliced | ||
]), null, 2)); | ||
const results = featureCollection([linestring, start, stop, sliced]); | ||
if (process.env.REGEN) { | ||
mkdirp.sync(output); | ||
write.sync(output + 'sliced.geojson', sliced); | ||
write.sync(output + 'results.geojson', results); | ||
} | ||
const expected = load.sync(output + 'sliced.geojson'); | ||
t.end(); | ||
t.deepEquals(sliced, expected, folder); | ||
} | ||
t.end(); | ||
}); | ||
test('turf-line-slice -- line2', function (t) { | ||
var start = point([0,0.1]); | ||
var stop = point([.9,.8]); | ||
var line2 = linestring([[0,0], [1,1]]) | ||
var sliced = lineSlice(start, stop, line2); | ||
sliced.properties['stroke'] = '#f0f'; | ||
sliced.properties['stroke-width'] = 6; | ||
fs.writeFileSync(__dirname+ '/test/out/line2_out.geojson', | ||
JSON.stringify(featurecollection([ | ||
line2, start, stop, sliced | ||
]), null, 2)); | ||
t.end(); | ||
}); | ||
test('turf-line-slice -- route1', function (t) { | ||
var start = point([-79.0850830078125,37.60117623656667]); | ||
var stop = point([-77.7667236328125,38.65119833229951]); | ||
var sliced = lineSlice(start, stop, route1); | ||
sliced.properties['stroke'] = '#f0f'; | ||
sliced.properties['stroke-width'] = 6; | ||
fs.writeFileSync(__dirname+ '/test/out/route1_out.geojson', | ||
JSON.stringify(featurecollection([ | ||
route1, start, stop, sliced | ||
]), null, 2)); | ||
t.end(); | ||
}); | ||
test('turf-line-slice -- route2', function (t) { | ||
var start = point([-112.60660171508789,45.96021963947196]); | ||
var stop = point([-111.97265625,48.84302835299516]); | ||
var sliced = lineSlice(start, stop, route2); | ||
sliced.properties['stroke'] = '#f0f'; | ||
sliced.properties['stroke-width'] = 6; | ||
fs.writeFileSync(__dirname+ '/test/out/route2_out.geojson', | ||
JSON.stringify(featurecollection([ | ||
route2, start, stop, sliced | ||
]), null, 2)); | ||
t.end(); | ||
}); | ||
test('turf-line-slice -- vertical', function (t) { | ||
var start = point([-121.25447809696198, 38.70582415504791]); | ||
var stop = point([-121.25447809696198, 38.70634324369764]); | ||
var sliced = lineSlice(start, stop, vertical); | ||
sliced.properties['stroke'] = '#f0f'; | ||
sliced.properties['stroke-width'] = 6; | ||
t.equal(sliced.geometry.coordinates.length, 2, 'no duplicated coords'); | ||
t.notDeepEqual(sliced.geometry.coordinates[0], sliced.geometry.coordinates[1], 'vertical slice does not collapse to 1st coord'); | ||
fs.writeFileSync(__dirname+ '/test/out/vertical_out.geojson', | ||
JSON.stringify(featurecollection([ | ||
vertical, start, stop, sliced | ||
]), null, 2)); | ||
t.end(); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
10016
9
154
3