From 6a11cf3dcf60eaa66c6be9b5d390ab77f586af0f Mon Sep 17 00:00:00 2001 From: Denis Date: Fri, 11 Aug 2017 11:28:03 -0400 Subject: [PATCH 1/6] Add FeatureCollection mutate tests (not failing) --- packages/turf-transform-scale/test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/turf-transform-scale/test.js b/packages/turf-transform-scale/test.js index 3c710eea25..2ed4246f5b 100644 --- a/packages/turf-transform-scale/test.js +++ b/packages/turf-transform-scale/test.js @@ -95,6 +95,22 @@ test('scale -- mutated input', t => { t.end(); }); +test('scale -- mutated FeatureCollection', t => { + const line = featureCollection([ + lineString([[10, 10], [12, 15]]), + lineString([[15, 15], [22, 35]]), + lineString([[30, 30], [42, 45]]) + ]); + const lineBefore = JSON.parse(JSON.stringify(line)); + scale(line, 1.5); + t.deepEqual(line, lineBefore, 'mutate = undefined - input should NOT be mutated'); + scale(line, 1.5, 'centroid', false); + t.deepEqual(line, lineBefore, 'mutate = false - input should NOT be mutated'); + scale(line, 1.5, 'centroid', 'nonBoolean'); + t.deepEqual(line, lineBefore, 'non-boolean mutate - input should NOT be mutated'); + t.end(); +}); + test('scale -- geometry support', t => { const pt = point([10, 10]); const line = lineString([[10, 10], [12, 15]]); From 0679acffa62fab073cf599b3f380f7f4e36f23c9 Mon Sep 17 00:00:00 2001 From: Denis Date: Fri, 11 Aug 2017 11:40:53 -0400 Subject: [PATCH 2/6] Add test case for issue #895 --- packages/turf-transform-scale/package.json | 1 + packages/turf-transform-scale/test.js | 13 + .../test/out/issue-#895.geojson | 2462 +++++++++++++++++ packages/turf-transform-scale/yarn.lock | 79 + 4 files changed, 2555 insertions(+) create mode 100644 packages/turf-transform-scale/test/out/issue-#895.geojson diff --git a/packages/turf-transform-scale/package.json b/packages/turf-transform-scale/package.json index c769674f7d..6cd1975033 100644 --- a/packages/turf-transform-scale/package.json +++ b/packages/turf-transform-scale/package.json @@ -37,6 +37,7 @@ }, "homepage": "https://github.com/Turfjs/turf", "devDependencies": { + "@turf/hex-grid": "^4.6.1", "@turf/truncate": "^4.6.0", "benchmark": "^2.1.4", "load-json-file": "^2.0.0", diff --git a/packages/turf-transform-scale/test.js b/packages/turf-transform-scale/test.js index 2ed4246f5b..5df73a66fa 100644 --- a/packages/turf-transform-scale/test.js +++ b/packages/turf-transform-scale/test.js @@ -4,6 +4,7 @@ const path = require('path'); const load = require('load-json-file'); const write = require('write-json-file'); const center = require('@turf/center'); +const hexGrid = require('@turf/hex-grid'); const truncate = require('@turf/truncate'); const turfBBox = require('@turf/bbox'); const centroid = require('@turf/centroid'); @@ -111,6 +112,18 @@ test('scale -- mutated FeatureCollection', t => { t.end(); }); +test('scale -- Issue #895', t => { + const grid = hexGrid([-122.930, 45.385, -122.294, 45.772], 5, 'miles'); + featureEach(grid, (feature, index) => { + const factor = (index % 2 === 0) ? 0.4 : 0.6; + scale(feature, factor, 'centroid', true); + }); + const output = directories.out + 'issue-#895.geojson'; + if (process.env.REGEN) write.sync(output, grid); + t.deepEqual(grid, load.sync(output)); + t.end(); +}); + test('scale -- geometry support', t => { const pt = point([10, 10]); const line = lineString([[10, 10], [12, 15]]); diff --git a/packages/turf-transform-scale/test/out/issue-#895.geojson b/packages/turf-transform-scale/test/out/issue-#895.geojson new file mode 100644 index 0000000000..84656f6399 --- /dev/null +++ b/packages/turf-transform-scale/test/out/issue-#895.geojson @@ -0,0 +1,2462 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.91380467738384, + 45.40620972018069 + ], + [ + -122.91173924238899, + 45.418739922349374 + ], + [ + -122.93240735497511, + 45.418739922349374 + ], + [ + -122.94274485192756, + 45.40620972018069 + ], + [ + -122.932410793943, + 45.393679518012014 + ], + [ + -122.91173580342115, + 45.393679518012014 + ], + [ + -122.91380467738384, + 45.40620972018069 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.90346890076114, + 45.46886073102407 + ], + [ + -122.90657135803406, + 45.48765603427709 + ], + [ + -122.9375752393301, + 45.48765603427709 + ], + [ + -122.95308062855025, + 45.46886073102407 + ], + [ + -122.93757868582816, + 45.45006542777106 + ], + [ + -122.90656791153594, + 45.45006542777106 + ], + [ + -122.90346890076114, + 45.46886073102407 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.91380467738384, + 45.531511741867455 + ], + [ + -122.91173924993092, + 45.54404194403613 + ], + [ + -122.93240734743324, + 45.54404194403613 + ], + [ + -122.94274485192756, + 45.531511741867455 + ], + [ + -122.93241080147766, + 45.51898153969878 + ], + [ + -122.91173579588644, + 45.51898153969878 + ], + [ + -122.91380467738384, + 45.531511741867455 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.90346890076114, + 45.594162752710844 + ], + [ + -122.90657136559389, + 45.61295805596385 + ], + [ + -122.93757523177021, + 45.61295805596385 + ], + [ + -122.95308062855025, + 45.594162752710844 + ], + [ + -122.9375786933785, + 45.57536744945783 + ], + [ + -122.90656790398566, + 45.57536744945783 + ], + [ + -122.90346890076114, + 45.594162752710844 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.91380467738384, + 45.656813763554226 + ], + [ + -122.91173925750655, + 45.66934396572291 + ], + [ + -122.9324073398576, + 45.66934396572291 + ], + [ + -122.94274485192756, + 45.656813763554226 + ], + [ + -122.93241080904596, + 45.64428356138555 + ], + [ + -122.9117357883182, + 45.64428356138555 + ], + [ + -122.91380467738384, + 45.656813763554226 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.90346890076114, + 45.719464774397615 + ], + [ + -122.9065713731876, + 45.73826007765063 + ], + [ + -122.93757522417656, + 45.73826007765063 + ], + [ + -122.95308062855025, + 45.719464774397615 + ], + [ + -122.9375787009626, + 45.70066947114461 + ], + [ + -122.90656789640155, + 45.70066947114461 + ], + [ + -122.90346890076114, + 45.719464774397615 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.91380467738384, + 45.782115785241 + ], + [ + -122.91173926511613, + 45.79464598740967 + ], + [ + -122.93240733224798, + 45.79464598740967 + ], + [ + -122.94274485192756, + 45.782115785241 + ], + [ + -122.93241081664814, + 45.76958558307232 + ], + [ + -122.91173578071596, + 45.76958558307232 + ], + [ + -122.91380467738384, + 45.782115785241 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.82595057609063, + 45.37488421475899 + ], + [ + -122.82905302771564, + 45.39367951801201 + ], + [ + -122.86005692030744, + 45.39367951801201 + ], + [ + -122.87556230387975, + 45.37488421475899 + ], + [ + -122.86006035551691, + 45.356088911505985 + ], + [ + -122.82904959250618, + 45.356088911505985 + ], + [ + -122.82595057609063, + 45.37488421475899 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.83628635271339, + 45.43753522560238 + ], + [ + -122.8342209196008, + 45.45006542777106 + ], + [ + -122.85488902842229, + 45.45006542777106 + ], + [ + -122.86522652725705, + 45.43753522560238 + ], + [ + -122.85489247115305, + 45.425005023433705 + ], + [ + -122.8342174768701, + 45.425005023433705 + ], + [ + -122.83628635271339, + 45.43753522560238 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.82595057609063, + 45.500186236445764 + ], + [ + -122.8290530352503, + 45.51898153969878 + ], + [ + -122.86005691277279, + 45.51898153969878 + ], + [ + -122.87556230387975, + 45.500186236445764 + ], + [ + -122.86006036304207, + 45.48139093319275 + ], + [ + -122.82904958498102, + 45.48139093319275 + ], + [ + -122.82595057609063, + 45.500186236445764 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.83628635271339, + 45.56283724728916 + ], + [ + -122.83422092715114, + 45.575367449457836 + ], + [ + -122.85488902087195, + 45.575367449457836 + ], + [ + -122.86522652725705, + 45.56283724728916 + ], + [ + -122.85489247869606, + 45.55030704512048 + ], + [ + -122.83421746932703, + 45.55030704512048 + ], + [ + -122.83628635271339, + 45.56283724728916 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.82595057609063, + 45.62548825813253 + ], + [ + -122.8290530428186, + 45.64428356138555 + ], + [ + -122.86005690520449, + 45.64428356138555 + ], + [ + -122.87556230387975, + 45.62548825813253 + ], + [ + -122.86006037060082, + 45.60669295487952 + ], + [ + -122.82904957742227, + 45.60669295487952 + ], + [ + -122.82595057609063, + 45.62548825813253 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.83628635271339, + 45.68813926897593 + ], + [ + -122.83422093473519, + 45.70066947114461 + ], + [ + -122.8548890132879, + 45.70066947114461 + ], + [ + -122.86522652725705, + 45.68813926897593 + ], + [ + -122.85489248627277, + 45.67560906680725 + ], + [ + -122.83421746175031, + 45.67560906680725 + ], + [ + -122.83628635271339, + 45.68813926897593 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.82595057609063, + 45.750790279819306 + ], + [ + -122.82905305042084, + 45.76958558307232 + ], + [ + -122.8600568976023, + 45.76958558307232 + ], + [ + -122.87556230387975, + 45.750790279819306 + ], + [ + -122.8600603781934, + 45.7319949765663 + ], + [ + -122.82904956982969, + 45.7319949765663 + ], + [ + -122.82595057609063, + 45.750790279819306 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.75876802804288, + 45.40620972018069 + ], + [ + -122.75670259304798, + 45.418739922349374 + ], + [ + -122.7773707056341, + 45.418739922349374 + ], + [ + -122.78770820258649, + 45.40620972018069 + ], + [ + -122.77737414460199, + 45.393679518012014 + ], + [ + -122.75669915408008, + 45.393679518012014 + ], + [ + -122.75876802804288, + 45.40620972018069 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.74843225142013, + 45.46886073102407 + ], + [ + -122.75153470869299, + 45.48765603427709 + ], + [ + -122.78253858998903, + 45.48765603427709 + ], + [ + -122.79804397920924, + 45.46886073102407 + ], + [ + -122.78254203648714, + 45.45006542777106 + ], + [ + -122.75153126219493, + 45.45006542777106 + ], + [ + -122.74843225142013, + 45.46886073102407 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.75876802804288, + 45.531511741867455 + ], + [ + -122.7567026005899, + 45.54404194403613 + ], + [ + -122.77737069809223, + 45.54404194403613 + ], + [ + -122.78770820258649, + 45.531511741867455 + ], + [ + -122.77737415213664, + 45.51898153969878 + ], + [ + -122.75669914654543, + 45.51898153969878 + ], + [ + -122.75876802804288, + 45.531511741867455 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.74843225142013, + 45.594162752710844 + ], + [ + -122.75153471625288, + 45.61295805596385 + ], + [ + -122.7825385824292, + 45.61295805596385 + ], + [ + -122.79804397920924, + 45.594162752710844 + ], + [ + -122.78254204403743, + 45.57536744945783 + ], + [ + -122.75153125464465, + 45.57536744945783 + ], + [ + -122.74843225142013, + 45.594162752710844 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.75876802804288, + 45.656813763554226 + ], + [ + -122.75670260816554, + 45.66934396572291 + ], + [ + -122.77737069051653, + 45.66934396572291 + ], + [ + -122.78770820258649, + 45.656813763554226 + ], + [ + -122.77737415970495, + 45.64428356138555 + ], + [ + -122.75669913897713, + 45.64428356138555 + ], + [ + -122.75876802804288, + 45.656813763554226 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.74843225142013, + 45.719464774397615 + ], + [ + -122.75153472384659, + 45.73826007765063 + ], + [ + -122.78253857483548, + 45.73826007765063 + ], + [ + -122.79804397920924, + 45.719464774397615 + ], + [ + -122.78254205162153, + 45.70066947114461 + ], + [ + -122.75153124706054, + 45.70066947114461 + ], + [ + -122.74843225142013, + 45.719464774397615 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.75876802804288, + 45.782115785241 + ], + [ + -122.75670261577511, + 45.79464598740967 + ], + [ + -122.77737068290696, + 45.79464598740967 + ], + [ + -122.78770820258649, + 45.782115785241 + ], + [ + -122.77737416730713, + 45.76958558307232 + ], + [ + -122.75669913137494, + 45.76958558307232 + ], + [ + -122.75876802804288, + 45.782115785241 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.67091392674962, + 45.37488421475899 + ], + [ + -122.67401637837463, + 45.39367951801201 + ], + [ + -122.70502027096637, + 45.39367951801201 + ], + [ + -122.72052565453873, + 45.37488421475899 + ], + [ + -122.7050237061759, + 45.356088911505985 + ], + [ + -122.67401294316517, + 45.356088911505985 + ], + [ + -122.67091392674962, + 45.37488421475899 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.68124970337232, + 45.43753522560238 + ], + [ + -122.67918427025978, + 45.45006542777106 + ], + [ + -122.69985237908122, + 45.45006542777106 + ], + [ + -122.71018987791604, + 45.43753522560238 + ], + [ + -122.69985582181198, + 45.425005023433705 + ], + [ + -122.67918082752902, + 45.425005023433705 + ], + [ + -122.68124970337232, + 45.43753522560238 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.67091392674962, + 45.500186236445764 + ], + [ + -122.67401638590928, + 45.51898153969878 + ], + [ + -122.70502026343178, + 45.51898153969878 + ], + [ + -122.72052565453873, + 45.500186236445764 + ], + [ + -122.70502371370105, + 45.48139093319275 + ], + [ + -122.67401293563995, + 45.48139093319275 + ], + [ + -122.67091392674962, + 45.500186236445764 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.68124970337232, + 45.56283724728916 + ], + [ + -122.67918427781012, + 45.575367449457836 + ], + [ + -122.69985237153094, + 45.575367449457836 + ], + [ + -122.71018987791604, + 45.56283724728916 + ], + [ + -122.69985582935504, + 45.55030704512048 + ], + [ + -122.67918081998602, + 45.55030704512048 + ], + [ + -122.68124970337232, + 45.56283724728916 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.67091392674962, + 45.62548825813253 + ], + [ + -122.67401639347759, + 45.64428356138555 + ], + [ + -122.70502025586347, + 45.64428356138555 + ], + [ + -122.72052565453873, + 45.62548825813253 + ], + [ + -122.7050237212598, + 45.60669295487952 + ], + [ + -122.67401292808125, + 45.60669295487952 + ], + [ + -122.67091392674962, + 45.62548825813253 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.68124970337232, + 45.68813926897593 + ], + [ + -122.67918428539417, + 45.70066947114461 + ], + [ + -122.69985236394689, + 45.70066947114461 + ], + [ + -122.71018987791604, + 45.68813926897593 + ], + [ + -122.69985583693176, + 45.67560906680725 + ], + [ + -122.67918081240924, + 45.67560906680725 + ], + [ + -122.68124970337232, + 45.68813926897593 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.67091392674962, + 45.750790279819306 + ], + [ + -122.67401640107977, + 45.76958558307232 + ], + [ + -122.70502024826123, + 45.76958558307232 + ], + [ + -122.72052565453873, + 45.750790279819306 + ], + [ + -122.70502372885232, + 45.7319949765663 + ], + [ + -122.67401292048868, + 45.7319949765663 + ], + [ + -122.67091392674962, + 45.750790279819306 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.60373137870181, + 45.40620972018069 + ], + [ + -122.60166594370696, + 45.418739922349374 + ], + [ + -122.62233405629303, + 45.418739922349374 + ], + [ + -122.63267155324547, + 45.40620972018069 + ], + [ + -122.62233749526092, + 45.393679518012014 + ], + [ + -122.60166250473901, + 45.393679518012014 + ], + [ + -122.60373137870181, + 45.40620972018069 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.59339560207906, + 45.46886073102407 + ], + [ + -122.59649805935192, + 45.48765603427709 + ], + [ + -122.62750194064802, + 45.48765603427709 + ], + [ + -122.64300732986817, + 45.46886073102407 + ], + [ + -122.62750538714613, + 45.45006542777106 + ], + [ + -122.59649461285386, + 45.45006542777106 + ], + [ + -122.59339560207906, + 45.46886073102407 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.60373137870181, + 45.531511741867455 + ], + [ + -122.60166595124883, + 45.54404194403613 + ], + [ + -122.62233404875116, + 45.54404194403613 + ], + [ + -122.63267155324547, + 45.531511741867455 + ], + [ + -122.62233750279557, + 45.51898153969878 + ], + [ + -122.60166249720436, + 45.51898153969878 + ], + [ + -122.60373137870181, + 45.531511741867455 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.59339560207906, + 45.594162752710844 + ], + [ + -122.5964980669118, + 45.61295805596385 + ], + [ + -122.62750193308818, + 45.61295805596385 + ], + [ + -122.64300732986817, + 45.594162752710844 + ], + [ + -122.62750539469641, + 45.57536744945783 + ], + [ + -122.59649460530358, + 45.57536744945783 + ], + [ + -122.59339560207906, + 45.594162752710844 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.60373137870181, + 45.656813763554226 + ], + [ + -122.60166595882447, + 45.66934396572291 + ], + [ + -122.62233404117552, + 45.66934396572291 + ], + [ + -122.63267155324547, + 45.656813763554226 + ], + [ + -122.62233751036388, + 45.64428356138555 + ], + [ + -122.60166248963606, + 45.64428356138555 + ], + [ + -122.60373137870181, + 45.656813763554226 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.59339560207906, + 45.719464774397615 + ], + [ + -122.59649807450552, + 45.73826007765063 + ], + [ + -122.62750192549447, + 45.73826007765063 + ], + [ + -122.64300732986817, + 45.719464774397615 + ], + [ + -122.62750540228046, + 45.70066947114461 + ], + [ + -122.59649459771947, + 45.70066947114461 + ], + [ + -122.59339560207906, + 45.719464774397615 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.60373137870181, + 45.782115785241 + ], + [ + -122.60166596643404, + 45.79464598740967 + ], + [ + -122.62233403356595, + 45.79464598740967 + ], + [ + -122.63267155324547, + 45.782115785241 + ], + [ + -122.62233751796612, + 45.76958558307232 + ], + [ + -122.60166248203387, + 45.76958558307232 + ], + [ + -122.60373137870181, + 45.782115785241 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.5158772774086, + 45.37488421475899 + ], + [ + -122.51897972903356, + 45.39367951801201 + ], + [ + -122.54998362162536, + 45.39367951801201 + ], + [ + -122.56548900519772, + 45.37488421475899 + ], + [ + -122.54998705683482, + 45.356088911505985 + ], + [ + -122.5189762938241, + 45.356088911505985 + ], + [ + -122.5158772774086, + 45.37488421475899 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.5262130540313, + 45.43753522560238 + ], + [ + -122.52414762091877, + 45.45006542777106 + ], + [ + -122.54481572974021, + 45.45006542777106 + ], + [ + -122.55515322857491, + 45.43753522560238 + ], + [ + -122.54481917247097, + 45.425005023433705 + ], + [ + -122.52414417818801, + 45.425005023433705 + ], + [ + -122.5262130540313, + 45.43753522560238 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.5158772774086, + 45.500186236445764 + ], + [ + -122.51897973656821, + 45.51898153969878 + ], + [ + -122.5499836140907, + 45.51898153969878 + ], + [ + -122.56548900519772, + 45.500186236445764 + ], + [ + -122.54998706436004, + 45.48139093319275 + ], + [ + -122.51897628629894, + 45.48139093319275 + ], + [ + -122.5158772774086, + 45.500186236445764 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.5262130540313, + 45.56283724728916 + ], + [ + -122.52414762846905, + 45.575367449457836 + ], + [ + -122.54481572218992, + 45.575367449457836 + ], + [ + -122.55515322857491, + 45.56283724728916 + ], + [ + -122.54481918001397, + 45.55030704512048 + ], + [ + -122.52414417064495, + 45.55030704512048 + ], + [ + -122.5262130540313, + 45.56283724728916 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.5158772774086, + 45.62548825813253 + ], + [ + -122.51897974413657, + 45.64428356138555 + ], + [ + -122.5499836065224, + 45.64428356138555 + ], + [ + -122.56548900519772, + 45.62548825813253 + ], + [ + -122.54998707191874, + 45.60669295487952 + ], + [ + -122.51897627874018, + 45.60669295487952 + ], + [ + -122.5158772774086, + 45.62548825813253 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.5262130540313, + 45.68813926897593 + ], + [ + -122.52414763605316, + 45.70066947114461 + ], + [ + -122.54481571460582, + 45.70066947114461 + ], + [ + -122.55515322857491, + 45.68813926897593 + ], + [ + -122.54481918759075, + 45.67560906680725 + ], + [ + -122.52414416306823, + 45.67560906680725 + ], + [ + -122.5262130540313, + 45.68813926897593 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.5158772774086, + 45.750790279819306 + ], + [ + -122.5189797517387, + 45.76958558307232 + ], + [ + -122.54998359892022, + 45.76958558307232 + ], + [ + -122.56548900519772, + 45.750790279819306 + ], + [ + -122.54998707951131, + 45.7319949765663 + ], + [ + -122.51897627114766, + 45.7319949765663 + ], + [ + -122.5158772774086, + 45.750790279819306 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.4486947293608, + 45.40620972018069 + ], + [ + -122.44662929436589, + 45.418739922349374 + ], + [ + -122.46729740695201, + 45.418739922349374 + ], + [ + -122.47763490390446, + 45.40620972018069 + ], + [ + -122.46730084591991, + 45.393679518012014 + ], + [ + -122.446625855398, + 45.393679518012014 + ], + [ + -122.4486947293608, + 45.40620972018069 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.43835895273804, + 45.46886073102407 + ], + [ + -122.4414614100109, + 45.48765603427709 + ], + [ + -122.472465291307, + 45.48765603427709 + ], + [ + -122.48797068052716, + 45.46886073102407 + ], + [ + -122.47246873780512, + 45.45006542777106 + ], + [ + -122.44145796351285, + 45.45006542777106 + ], + [ + -122.43835895273804, + 45.46886073102407 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.4486947293608, + 45.531511741867455 + ], + [ + -122.44662930190782, + 45.54404194403613 + ], + [ + -122.46729739941009, + 45.54404194403613 + ], + [ + -122.47763490390446, + 45.531511741867455 + ], + [ + -122.46730085345456, + 45.51898153969878 + ], + [ + -122.44662584786334, + 45.51898153969878 + ], + [ + -122.4486947293608, + 45.531511741867455 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.43835895273804, + 45.594162752710844 + ], + [ + -122.44146141757074, + 45.61295805596385 + ], + [ + -122.47246528374717, + 45.61295805596385 + ], + [ + -122.48797068052716, + 45.594162752710844 + ], + [ + -122.4724687453554, + 45.57536744945783 + ], + [ + -122.4414579559625, + 45.57536744945783 + ], + [ + -122.43835895273804, + 45.594162752710844 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.4486947293608, + 45.656813763554226 + ], + [ + -122.44662930948346, + 45.66934396572291 + ], + [ + -122.46729739183445, + 45.66934396572291 + ], + [ + -122.47763490390446, + 45.656813763554226 + ], + [ + -122.46730086102286, + 45.64428356138555 + ], + [ + -122.44662584029504, + 45.64428356138555 + ], + [ + -122.4486947293608, + 45.656813763554226 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.43835895273804, + 45.719464774397615 + ], + [ + -122.4414614251645, + 45.73826007765063 + ], + [ + -122.47246527615346, + 45.73826007765063 + ], + [ + -122.48797068052716, + 45.719464774397615 + ], + [ + -122.47246875293945, + 45.70066947114461 + ], + [ + -122.44145794837846, + 45.70066947114461 + ], + [ + -122.43835895273804, + 45.719464774397615 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.4486947293608, + 45.782115785241 + ], + [ + -122.44662931709297, + 45.79464598740967 + ], + [ + -122.46729738422488, + 45.79464598740967 + ], + [ + -122.47763490390446, + 45.782115785241 + ], + [ + -122.46730086862505, + 45.76958558307232 + ], + [ + -122.44662583269286, + 45.76958558307232 + ], + [ + -122.4486947293608, + 45.782115785241 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.36084062806754, + 45.37488421475899 + ], + [ + -122.3639430796926, + 45.39367951801201 + ], + [ + -122.39494697228434, + 45.39367951801201 + ], + [ + -122.41045235585665, + 45.37488421475899 + ], + [ + -122.39495040749381, + 45.356088911505985 + ], + [ + -122.36393964448308, + 45.356088911505985 + ], + [ + -122.36084062806754, + 45.37488421475899 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.37117640469023, + 45.43753522560238 + ], + [ + -122.3691109715777, + 45.45006542777106 + ], + [ + -122.3897790803992, + 45.45006542777106 + ], + [ + -122.40011657923395, + 45.43753522560238 + ], + [ + -122.38978252312995, + 45.425005023433705 + ], + [ + -122.36910752884694, + 45.425005023433705 + ], + [ + -122.37117640469023, + 45.43753522560238 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.36084062806754, + 45.500186236445764 + ], + [ + -122.3639430872272, + 45.51898153969878 + ], + [ + -122.39494696474969, + 45.51898153969878 + ], + [ + -122.41045235585665, + 45.500186236445764 + ], + [ + -122.39495041501903, + 45.48139093319275 + ], + [ + -122.36393963695792, + 45.48139093319275 + ], + [ + -122.36084062806754, + 45.500186236445764 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.37117640469023, + 45.56283724728916 + ], + [ + -122.36911097912804, + 45.575367449457836 + ], + [ + -122.38977907284885, + 45.575367449457836 + ], + [ + -122.40011657923395, + 45.56283724728916 + ], + [ + -122.38978253067296, + 45.55030704512048 + ], + [ + -122.36910752130393, + 45.55030704512048 + ], + [ + -122.37117640469023, + 45.56283724728916 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.36084062806754, + 45.62548825813253 + ], + [ + -122.36394309479556, + 45.64428356138555 + ], + [ + -122.39494695718139, + 45.64428356138555 + ], + [ + -122.41045235585665, + 45.62548825813253 + ], + [ + -122.39495042257772, + 45.60669295487952 + ], + [ + -122.36393962939917, + 45.60669295487952 + ], + [ + -122.36084062806754, + 45.62548825813253 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.37117640469023, + 45.68813926897593 + ], + [ + -122.36911098671214, + 45.70066947114461 + ], + [ + -122.38977906526475, + 45.70066947114461 + ], + [ + -122.40011657923395, + 45.68813926897593 + ], + [ + -122.38978253824973, + 45.67560906680725 + ], + [ + -122.36910751372722, + 45.67560906680725 + ], + [ + -122.37117640469023, + 45.68813926897593 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.36084062806754, + 45.750790279819306 + ], + [ + -122.36394310239774, + 45.76958558307232 + ], + [ + -122.39494694957921, + 45.76958558307232 + ], + [ + -122.41045235585665, + 45.750790279819306 + ], + [ + -122.3949504301703, + 45.7319949765663 + ], + [ + -122.3639396218066, + 45.7319949765663 + ], + [ + -122.36084062806754, + 45.750790279819306 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.29365808001972, + 45.40620972018069 + ], + [ + -122.29159264502488, + 45.418739922349374 + ], + [ + -122.312260757611, + 45.418739922349374 + ], + [ + -122.32259825456345, + 45.40620972018069 + ], + [ + -122.3122641965789, + 45.393679518012014 + ], + [ + -122.29158920605698, + 45.393679518012014 + ], + [ + -122.29365808001972, + 45.40620972018069 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.28332230339703, + 45.46886073102407 + ], + [ + -122.28642476066989, + 45.48765603427709 + ], + [ + -122.31742864196599, + 45.48765603427709 + ], + [ + -122.33293403118614, + 45.46886073102407 + ], + [ + -122.31743208846405, + 45.45006542777106 + ], + [ + -122.28642131417183, + 45.45006542777106 + ], + [ + -122.28332230339703, + 45.46886073102407 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.29365808001972, + 45.531511741867455 + ], + [ + -122.2915926525668, + 45.54404194403613 + ], + [ + -122.31226075006907, + 45.54404194403613 + ], + [ + -122.32259825456345, + 45.531511741867455 + ], + [ + -122.31226420411355, + 45.51898153969878 + ], + [ + -122.29158919852233, + 45.51898153969878 + ], + [ + -122.29365808001972, + 45.531511741867455 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.28332230339703, + 45.594162752710844 + ], + [ + -122.28642476822978, + 45.61295805596385 + ], + [ + -122.3174286344061, + 45.61295805596385 + ], + [ + -122.33293403118614, + 45.594162752710844 + ], + [ + -122.31743209601439, + 45.57536744945783 + ], + [ + -122.28642130662149, + 45.57536744945783 + ], + [ + -122.28332230339703, + 45.594162752710844 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.29365808001972, + 45.656813763554226 + ], + [ + -122.29159266014244, + 45.66934396572291 + ], + [ + -122.31226074249344, + 45.66934396572291 + ], + [ + -122.32259825456345, + 45.656813763554226 + ], + [ + -122.31226421168185, + 45.64428356138555 + ], + [ + -122.29158919095403, + 45.64428356138555 + ], + [ + -122.29365808001972, + 45.656813763554226 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.28332230339703, + 45.719464774397615 + ], + [ + -122.28642477582343, + 45.73826007765063 + ], + [ + -122.31742862681244, + 45.73826007765063 + ], + [ + -122.33293403118614, + 45.719464774397615 + ], + [ + -122.31743210359843, + 45.70066947114461 + ], + [ + -122.28642129903744, + 45.70066947114461 + ], + [ + -122.28332230339703, + 45.719464774397615 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.29365808001972, + 45.782115785241 + ], + [ + -122.29159266775201, + 45.79464598740967 + ], + [ + -122.31226073488386, + 45.79464598740967 + ], + [ + -122.32259825456345, + 45.782115785241 + ], + [ + -122.31226421928403, + 45.76958558307232 + ], + [ + -122.29158918335185, + 45.76958558307232 + ], + [ + -122.29365808001972, + 45.782115785241 + ] + ] + ] + } + } + ] +} diff --git a/packages/turf-transform-scale/yarn.lock b/packages/turf-transform-scale/yarn.lock index f4f129e438..39566934f2 100644 --- a/packages/turf-transform-scale/yarn.lock +++ b/packages/turf-transform-scale/yarn.lock @@ -2,6 +2,81 @@ # yarn lockfile v1 +"@turf/bbox@^4.6.0": + version "4.6.0" + resolved "https://registry.yarnpkg.com/@turf/bbox/-/bbox-4.6.0.tgz#8c7f68cdd2bee9178de4d9f9bfbcee4235db5fc3" + dependencies: + "@turf/meta" "^4.6.0" + +"@turf/center@^4.6.1": + version "4.6.1" + resolved "https://registry.yarnpkg.com/@turf/center/-/center-4.6.1.tgz#d9ed7a7e098f6ac1ff5189a05ee752b60d7ac681" + dependencies: + "@turf/bbox" "^4.6.0" + "@turf/helpers" "^4.6.0" + +"@turf/centroid@^4.6.1": + version "4.6.1" + resolved "https://registry.yarnpkg.com/@turf/centroid/-/centroid-4.6.1.tgz#6ffe203746aa33dec17d41c22aa5691342e46496" + dependencies: + "@turf/helpers" "^4.6.0" + "@turf/meta" "^4.6.0" + +"@turf/distance@^4.6.0": + version "4.6.0" + resolved "https://registry.yarnpkg.com/@turf/distance/-/distance-4.6.0.tgz#6410b9b4ea7e44e4a99be33018d9daab031946e0" + dependencies: + "@turf/helpers" "^4.6.0" + "@turf/invariant" "^4.6.0" + +"@turf/helpers@^4.6.0": + version "4.6.0" + resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-4.6.0.tgz#12398733b8ae28420df6166fa44c7ee8ffd6414c" + +"@turf/hex-grid@^4.6.1": + version "4.6.1" + resolved "https://registry.yarnpkg.com/@turf/hex-grid/-/hex-grid-4.6.1.tgz#211ee084cad9c5ba60ceb36a2994e4bf6962f746" + dependencies: + "@turf/distance" "^4.6.0" + "@turf/helpers" "^4.6.0" + +"@turf/invariant@^4.6.0": + version "4.6.0" + resolved "https://registry.yarnpkg.com/@turf/invariant/-/invariant-4.6.0.tgz#ba61401d537543f81ccfc588e12bb0d8e653dd80" + +"@turf/meta@^4.6.0": + version "4.6.0" + resolved "https://registry.yarnpkg.com/@turf/meta/-/meta-4.6.0.tgz#0d3f9a218e58d1c5e5deedf467c3321dd61203f3" + +"@turf/rhumb-bearing@^4.6.0": + version "4.6.0" + resolved "https://registry.yarnpkg.com/@turf/rhumb-bearing/-/rhumb-bearing-4.6.0.tgz#550821a34317f274e4eb90363ec32ce2ea94c2a9" + dependencies: + "@turf/invariant" "^4.6.0" + geodesy "1.1.1" + +"@turf/rhumb-destination@^4.6.0": + version "4.6.0" + resolved "https://registry.yarnpkg.com/@turf/rhumb-destination/-/rhumb-destination-4.6.0.tgz#d21d3c76fa7b7312e5b1f3b40083aefb99879a86" + dependencies: + "@turf/helpers" "^4.6.0" + "@turf/invariant" "^4.6.0" + geodesy "1.1.1" + +"@turf/rhumb-distance@^4.6.0": + version "4.6.0" + resolved "https://registry.yarnpkg.com/@turf/rhumb-distance/-/rhumb-distance-4.6.0.tgz#2a4fbb510f0be2a2cc8f50e9f3e59fac2ec590fb" + dependencies: + "@turf/helpers" "^4.6.0" + "@turf/invariant" "^4.6.0" + geodesy "1.1.1" + +"@turf/truncate@^4.6.0": + version "4.6.0" + resolved "https://registry.yarnpkg.com/@turf/truncate/-/truncate-4.6.0.tgz#903ad5ed34c0b851b93529975eb8e2eb769a561f" + dependencies: + "@turf/meta" "^4.6.0" + balanced-match@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" @@ -84,6 +159,10 @@ function-bind@^1.0.2, function-bind@^1.1.0, function-bind@~1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.0.tgz#16176714c801798e4e8f2cf7f7529467bb4a5771" +geodesy@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/geodesy/-/geodesy-1.1.1.tgz#918c414a5cc247c8128332b7624050c467e98a5d" + glob@~7.1.2: version "7.1.2" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15" From c228734f91c47ad55f78a8eeeba8261d073209a9 Mon Sep 17 00:00:00 2001 From: Denis Date: Fri, 11 Aug 2017 12:05:21 -0400 Subject: [PATCH 3/6] Fix #895 --- packages/turf-transform-scale/index.js | 20 +- packages/turf-transform-scale/package.json | 1 + .../test/out/issue-#895.geojson | 252 +++++++++--------- packages/turf-transform-scale/yarn.lock | 4 + 4 files changed, 145 insertions(+), 132 deletions(-) diff --git a/packages/turf-transform-scale/index.js b/packages/turf-transform-scale/index.js index 72ffc2d174..3843ea5c24 100644 --- a/packages/turf-transform-scale/index.js +++ b/packages/turf-transform-scale/index.js @@ -1,4 +1,5 @@ var meta = require('@turf/meta'); +var clone = require('@turf/clone'); var center = require('@turf/center'); var helpers = require('@turf/helpers'); var centroid = require('@turf/centroid'); @@ -12,6 +13,7 @@ var coordEach = meta.coordEach; var featureEach = meta.featureEach; var getCoord = invariant.getCoord; var getCoords = invariant.getCoords; +var getGeomType = invariant.getGeomType; /** @@ -39,17 +41,17 @@ module.exports = function (geojson, factor, origin, mutate) { var originIsPoint = Array.isArray(origin) || typeof origin === 'object'; // Clone geojson to avoid side effects - if (mutate !== true) geojson = JSON.parse(JSON.stringify(geojson)); + if (mutate !== true) geojson = clone(geojson); // Scale each Feature separately if (geojson.type === 'FeatureCollection' && !originIsPoint) { featureEach(geojson, function (feature, index) { - geojson.features[index] = scale(feature, factor, origin); + geojson.features[index] = scale(feature, factor, origin, mutate); }); return geojson; } // Scale Feature/Geometry - return scale(geojson, factor, origin); + return scale(geojson, factor, origin, mutate); }; /** @@ -59,18 +61,24 @@ module.exports = function (geojson, factor, origin, mutate) { * @param {Feature|Geometry} geojson GeoJSON Feature/Geometry * @param {number} factor of scaling, positive or negative values greater than 0 * @param {string|Geometry|Feature|Array} [origin="centroid"] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid) + * @param {boolean} [mutate=false] allows GeoJSON input to be mutated * @returns {Feature|Geometry} scaled GeoJSON Feature/Geometry */ -function scale(geojson, factor, origin) { +function scale(geojson, factor, origin, mutate) { // Default params - var isPoint = (geojson.type === 'Point' || geojson.geometry && geojson.geometry.type === 'Point'); + var geomType = getGeomType(geojson); + var isPoint = geomType === 'Point'; + var isPolygon = geomType === 'Polygon' || geomType === 'MultiPolygon'; origin = defineOrigin(geojson, origin); // Shortcut no-scaling if (factor === 1 || isPoint) return geojson; // Scale each coordinate - coordEach(geojson, function (coord) { + coordEach(geojson, function (coord, coordIndex, featureIndex, featureSubIndex) { + // Ignore scaling on first coordinate of Polygons (Issue #895) + if (isPolygon && mutate === true && featureSubIndex === 0) return; + var originalDistance = rhumbDistance(origin, coord); var bearing = rhumbBearing(origin, coord); var newDistance = originalDistance * factor; diff --git a/packages/turf-transform-scale/package.json b/packages/turf-transform-scale/package.json index 6cd1975033..937ddef7db 100644 --- a/packages/turf-transform-scale/package.json +++ b/packages/turf-transform-scale/package.json @@ -48,6 +48,7 @@ "@turf/bbox": "^4.6.0", "@turf/center": "^4.6.1", "@turf/centroid": "^4.6.1", + "@turf/clone": "^4.6.1", "@turf/helpers": "^4.6.0", "@turf/invariant": "^4.6.0", "@turf/meta": "^4.6.0", diff --git a/packages/turf-transform-scale/test/out/issue-#895.geojson b/packages/turf-transform-scale/test/out/issue-#895.geojson index 84656f6399..75e04f7ca6 100644 --- a/packages/turf-transform-scale/test/out/issue-#895.geojson +++ b/packages/turf-transform-scale/test/out/issue-#895.geojson @@ -9,7 +9,7 @@ "coordinates": [ [ [ - -122.91380467738384, + -122.9014017454366, 45.40620972018069 ], [ @@ -33,7 +33,7 @@ 45.393679518012014 ], [ - -122.91380467738384, + -122.9014017454366, 45.40620972018069 ] ] @@ -48,7 +48,7 @@ "coordinates": [ [ [ - -122.90346890076114, + -122.89106596881385, 45.46886073102407 ], [ @@ -72,7 +72,7 @@ 45.45006542777106 ], [ - -122.90346890076114, + -122.89106596881385, 45.46886073102407 ] ] @@ -87,7 +87,7 @@ "coordinates": [ [ [ - -122.91380467738384, + -122.9014017454366, 45.531511741867455 ], [ @@ -111,7 +111,7 @@ 45.51898153969878 ], [ - -122.91380467738384, + -122.9014017454366, 45.531511741867455 ] ] @@ -126,7 +126,7 @@ "coordinates": [ [ [ - -122.90346890076114, + -122.89106596881385, 45.594162752710844 ], [ @@ -150,7 +150,7 @@ 45.57536744945783 ], [ - -122.90346890076114, + -122.89106596881385, 45.594162752710844 ] ] @@ -165,7 +165,7 @@ "coordinates": [ [ [ - -122.91380467738384, + -122.9014017454366, 45.656813763554226 ], [ @@ -189,7 +189,7 @@ 45.64428356138555 ], [ - -122.91380467738384, + -122.9014017454366, 45.656813763554226 ] ] @@ -204,7 +204,7 @@ "coordinates": [ [ [ - -122.90346890076114, + -122.89106596881385, 45.719464774397615 ], [ @@ -228,7 +228,7 @@ 45.70066947114461 ], [ - -122.90346890076114, + -122.89106596881385, 45.719464774397615 ] ] @@ -243,7 +243,7 @@ "coordinates": [ [ [ - -122.91380467738384, + -122.9014017454366, 45.782115785241 ], [ @@ -267,7 +267,7 @@ 45.76958558307232 ], [ - -122.91380467738384, + -122.9014017454366, 45.782115785241 ] ] @@ -282,7 +282,7 @@ "coordinates": [ [ [ - -122.82595057609063, + -122.81354764414334, 45.37488421475899 ], [ @@ -306,7 +306,7 @@ 45.356088911505985 ], [ - -122.82595057609063, + -122.81354764414334, 45.37488421475899 ] ] @@ -321,7 +321,7 @@ "coordinates": [ [ [ - -122.83628635271339, + -122.82388342076604, 45.43753522560238 ], [ @@ -345,7 +345,7 @@ 45.425005023433705 ], [ - -122.83628635271339, + -122.82388342076604, 45.43753522560238 ] ] @@ -360,7 +360,7 @@ "coordinates": [ [ [ - -122.82595057609063, + -122.81354764414334, 45.500186236445764 ], [ @@ -384,7 +384,7 @@ 45.48139093319275 ], [ - -122.82595057609063, + -122.81354764414334, 45.500186236445764 ] ] @@ -399,7 +399,7 @@ "coordinates": [ [ [ - -122.83628635271339, + -122.82388342076604, 45.56283724728916 ], [ @@ -423,7 +423,7 @@ 45.55030704512048 ], [ - -122.83628635271339, + -122.82388342076604, 45.56283724728916 ] ] @@ -438,7 +438,7 @@ "coordinates": [ [ [ - -122.82595057609063, + -122.81354764414334, 45.62548825813253 ], [ @@ -462,7 +462,7 @@ 45.60669295487952 ], [ - -122.82595057609063, + -122.81354764414334, 45.62548825813253 ] ] @@ -477,7 +477,7 @@ "coordinates": [ [ [ - -122.83628635271339, + -122.82388342076604, 45.68813926897593 ], [ @@ -501,7 +501,7 @@ 45.67560906680725 ], [ - -122.83628635271339, + -122.82388342076604, 45.68813926897593 ] ] @@ -516,7 +516,7 @@ "coordinates": [ [ [ - -122.82595057609063, + -122.81354764414334, 45.750790279819306 ], [ @@ -540,7 +540,7 @@ 45.7319949765663 ], [ - -122.82595057609063, + -122.81354764414334, 45.750790279819306 ] ] @@ -555,7 +555,7 @@ "coordinates": [ [ [ - -122.75876802804288, + -122.74636509609559, 45.40620972018069 ], [ @@ -579,7 +579,7 @@ 45.393679518012014 ], [ - -122.75876802804288, + -122.74636509609559, 45.40620972018069 ] ] @@ -594,7 +594,7 @@ "coordinates": [ [ [ - -122.74843225142013, + -122.73602931947283, 45.46886073102407 ], [ @@ -618,7 +618,7 @@ 45.45006542777106 ], [ - -122.74843225142013, + -122.73602931947283, 45.46886073102407 ] ] @@ -633,7 +633,7 @@ "coordinates": [ [ [ - -122.75876802804288, + -122.74636509609559, 45.531511741867455 ], [ @@ -657,7 +657,7 @@ 45.51898153969878 ], [ - -122.75876802804288, + -122.74636509609559, 45.531511741867455 ] ] @@ -672,7 +672,7 @@ "coordinates": [ [ [ - -122.74843225142013, + -122.73602931947283, 45.594162752710844 ], [ @@ -696,7 +696,7 @@ 45.57536744945783 ], [ - -122.74843225142013, + -122.73602931947283, 45.594162752710844 ] ] @@ -711,7 +711,7 @@ "coordinates": [ [ [ - -122.75876802804288, + -122.74636509609559, 45.656813763554226 ], [ @@ -735,7 +735,7 @@ 45.64428356138555 ], [ - -122.75876802804288, + -122.74636509609559, 45.656813763554226 ] ] @@ -750,7 +750,7 @@ "coordinates": [ [ [ - -122.74843225142013, + -122.73602931947283, 45.719464774397615 ], [ @@ -774,7 +774,7 @@ 45.70066947114461 ], [ - -122.74843225142013, + -122.73602931947283, 45.719464774397615 ] ] @@ -789,7 +789,7 @@ "coordinates": [ [ [ - -122.75876802804288, + -122.74636509609559, 45.782115785241 ], [ @@ -813,7 +813,7 @@ 45.76958558307232 ], [ - -122.75876802804288, + -122.74636509609559, 45.782115785241 ] ] @@ -828,7 +828,7 @@ "coordinates": [ [ [ - -122.67091392674962, + -122.65851099480233, 45.37488421475899 ], [ @@ -852,7 +852,7 @@ 45.356088911505985 ], [ - -122.67091392674962, + -122.65851099480233, 45.37488421475899 ] ] @@ -867,7 +867,7 @@ "coordinates": [ [ [ - -122.68124970337232, + -122.66884677142502, 45.43753522560238 ], [ @@ -891,7 +891,7 @@ 45.425005023433705 ], [ - -122.68124970337232, + -122.66884677142502, 45.43753522560238 ] ] @@ -906,7 +906,7 @@ "coordinates": [ [ [ - -122.67091392674962, + -122.65851099480233, 45.500186236445764 ], [ @@ -930,7 +930,7 @@ 45.48139093319275 ], [ - -122.67091392674962, + -122.65851099480233, 45.500186236445764 ] ] @@ -945,7 +945,7 @@ "coordinates": [ [ [ - -122.68124970337232, + -122.66884677142502, 45.56283724728916 ], [ @@ -969,7 +969,7 @@ 45.55030704512048 ], [ - -122.68124970337232, + -122.66884677142502, 45.56283724728916 ] ] @@ -984,7 +984,7 @@ "coordinates": [ [ [ - -122.67091392674962, + -122.65851099480233, 45.62548825813253 ], [ @@ -1008,7 +1008,7 @@ 45.60669295487952 ], [ - -122.67091392674962, + -122.65851099480233, 45.62548825813253 ] ] @@ -1023,7 +1023,7 @@ "coordinates": [ [ [ - -122.68124970337232, + -122.66884677142502, 45.68813926897593 ], [ @@ -1047,7 +1047,7 @@ 45.67560906680725 ], [ - -122.68124970337232, + -122.66884677142502, 45.68813926897593 ] ] @@ -1062,7 +1062,7 @@ "coordinates": [ [ [ - -122.67091392674962, + -122.65851099480233, 45.750790279819306 ], [ @@ -1086,7 +1086,7 @@ 45.7319949765663 ], [ - -122.67091392674962, + -122.65851099480233, 45.750790279819306 ] ] @@ -1101,7 +1101,7 @@ "coordinates": [ [ [ - -122.60373137870181, + -122.59132844675452, 45.40620972018069 ], [ @@ -1125,7 +1125,7 @@ 45.393679518012014 ], [ - -122.60373137870181, + -122.59132844675452, 45.40620972018069 ] ] @@ -1140,7 +1140,7 @@ "coordinates": [ [ [ - -122.59339560207906, + -122.58099267013176, 45.46886073102407 ], [ @@ -1164,7 +1164,7 @@ 45.45006542777106 ], [ - -122.59339560207906, + -122.58099267013176, 45.46886073102407 ] ] @@ -1179,7 +1179,7 @@ "coordinates": [ [ [ - -122.60373137870181, + -122.59132844675452, 45.531511741867455 ], [ @@ -1203,7 +1203,7 @@ 45.51898153969878 ], [ - -122.60373137870181, + -122.59132844675452, 45.531511741867455 ] ] @@ -1218,7 +1218,7 @@ "coordinates": [ [ [ - -122.59339560207906, + -122.58099267013176, 45.594162752710844 ], [ @@ -1242,7 +1242,7 @@ 45.57536744945783 ], [ - -122.59339560207906, + -122.58099267013176, 45.594162752710844 ] ] @@ -1257,7 +1257,7 @@ "coordinates": [ [ [ - -122.60373137870181, + -122.59132844675452, 45.656813763554226 ], [ @@ -1281,7 +1281,7 @@ 45.64428356138555 ], [ - -122.60373137870181, + -122.59132844675452, 45.656813763554226 ] ] @@ -1296,7 +1296,7 @@ "coordinates": [ [ [ - -122.59339560207906, + -122.58099267013176, 45.719464774397615 ], [ @@ -1320,7 +1320,7 @@ 45.70066947114461 ], [ - -122.59339560207906, + -122.58099267013176, 45.719464774397615 ] ] @@ -1335,7 +1335,7 @@ "coordinates": [ [ [ - -122.60373137870181, + -122.59132844675452, 45.782115785241 ], [ @@ -1359,7 +1359,7 @@ 45.76958558307232 ], [ - -122.60373137870181, + -122.59132844675452, 45.782115785241 ] ] @@ -1374,7 +1374,7 @@ "coordinates": [ [ [ - -122.5158772774086, + -122.50347434546131, 45.37488421475899 ], [ @@ -1398,7 +1398,7 @@ 45.356088911505985 ], [ - -122.5158772774086, + -122.50347434546131, 45.37488421475899 ] ] @@ -1413,7 +1413,7 @@ "coordinates": [ [ [ - -122.5262130540313, + -122.51381012208401, 45.43753522560238 ], [ @@ -1437,7 +1437,7 @@ 45.425005023433705 ], [ - -122.5262130540313, + -122.51381012208401, 45.43753522560238 ] ] @@ -1452,7 +1452,7 @@ "coordinates": [ [ [ - -122.5158772774086, + -122.50347434546131, 45.500186236445764 ], [ @@ -1476,7 +1476,7 @@ 45.48139093319275 ], [ - -122.5158772774086, + -122.50347434546131, 45.500186236445764 ] ] @@ -1491,7 +1491,7 @@ "coordinates": [ [ [ - -122.5262130540313, + -122.51381012208401, 45.56283724728916 ], [ @@ -1515,7 +1515,7 @@ 45.55030704512048 ], [ - -122.5262130540313, + -122.51381012208401, 45.56283724728916 ] ] @@ -1530,7 +1530,7 @@ "coordinates": [ [ [ - -122.5158772774086, + -122.50347434546131, 45.62548825813253 ], [ @@ -1554,7 +1554,7 @@ 45.60669295487952 ], [ - -122.5158772774086, + -122.50347434546131, 45.62548825813253 ] ] @@ -1569,7 +1569,7 @@ "coordinates": [ [ [ - -122.5262130540313, + -122.51381012208401, 45.68813926897593 ], [ @@ -1593,7 +1593,7 @@ 45.67560906680725 ], [ - -122.5262130540313, + -122.51381012208401, 45.68813926897593 ] ] @@ -1608,7 +1608,7 @@ "coordinates": [ [ [ - -122.5158772774086, + -122.50347434546131, 45.750790279819306 ], [ @@ -1632,7 +1632,7 @@ 45.7319949765663 ], [ - -122.5158772774086, + -122.50347434546131, 45.750790279819306 ] ] @@ -1647,7 +1647,7 @@ "coordinates": [ [ [ - -122.4486947293608, + -122.4362917974135, 45.40620972018069 ], [ @@ -1671,7 +1671,7 @@ 45.393679518012014 ], [ - -122.4486947293608, + -122.4362917974135, 45.40620972018069 ] ] @@ -1686,7 +1686,7 @@ "coordinates": [ [ [ - -122.43835895273804, + -122.42595602079075, 45.46886073102407 ], [ @@ -1710,7 +1710,7 @@ 45.45006542777106 ], [ - -122.43835895273804, + -122.42595602079075, 45.46886073102407 ] ] @@ -1725,7 +1725,7 @@ "coordinates": [ [ [ - -122.4486947293608, + -122.4362917974135, 45.531511741867455 ], [ @@ -1749,7 +1749,7 @@ 45.51898153969878 ], [ - -122.4486947293608, + -122.4362917974135, 45.531511741867455 ] ] @@ -1764,7 +1764,7 @@ "coordinates": [ [ [ - -122.43835895273804, + -122.42595602079075, 45.594162752710844 ], [ @@ -1788,7 +1788,7 @@ 45.57536744945783 ], [ - -122.43835895273804, + -122.42595602079075, 45.594162752710844 ] ] @@ -1803,7 +1803,7 @@ "coordinates": [ [ [ - -122.4486947293608, + -122.4362917974135, 45.656813763554226 ], [ @@ -1827,7 +1827,7 @@ 45.64428356138555 ], [ - -122.4486947293608, + -122.4362917974135, 45.656813763554226 ] ] @@ -1842,7 +1842,7 @@ "coordinates": [ [ [ - -122.43835895273804, + -122.42595602079075, 45.719464774397615 ], [ @@ -1866,7 +1866,7 @@ 45.70066947114461 ], [ - -122.43835895273804, + -122.42595602079075, 45.719464774397615 ] ] @@ -1881,7 +1881,7 @@ "coordinates": [ [ [ - -122.4486947293608, + -122.4362917974135, 45.782115785241 ], [ @@ -1905,7 +1905,7 @@ 45.76958558307232 ], [ - -122.4486947293608, + -122.4362917974135, 45.782115785241 ] ] @@ -1920,7 +1920,7 @@ "coordinates": [ [ [ - -122.36084062806754, + -122.34843769612024, 45.37488421475899 ], [ @@ -1944,7 +1944,7 @@ 45.356088911505985 ], [ - -122.36084062806754, + -122.34843769612024, 45.37488421475899 ] ] @@ -1959,7 +1959,7 @@ "coordinates": [ [ [ - -122.37117640469023, + -122.358773472743, 45.43753522560238 ], [ @@ -1983,7 +1983,7 @@ 45.425005023433705 ], [ - -122.37117640469023, + -122.358773472743, 45.43753522560238 ] ] @@ -1998,7 +1998,7 @@ "coordinates": [ [ [ - -122.36084062806754, + -122.34843769612024, 45.500186236445764 ], [ @@ -2022,7 +2022,7 @@ 45.48139093319275 ], [ - -122.36084062806754, + -122.34843769612024, 45.500186236445764 ] ] @@ -2037,7 +2037,7 @@ "coordinates": [ [ [ - -122.37117640469023, + -122.358773472743, 45.56283724728916 ], [ @@ -2061,7 +2061,7 @@ 45.55030704512048 ], [ - -122.37117640469023, + -122.358773472743, 45.56283724728916 ] ] @@ -2076,7 +2076,7 @@ "coordinates": [ [ [ - -122.36084062806754, + -122.34843769612024, 45.62548825813253 ], [ @@ -2100,7 +2100,7 @@ 45.60669295487952 ], [ - -122.36084062806754, + -122.34843769612024, 45.62548825813253 ] ] @@ -2115,7 +2115,7 @@ "coordinates": [ [ [ - -122.37117640469023, + -122.358773472743, 45.68813926897593 ], [ @@ -2139,7 +2139,7 @@ 45.67560906680725 ], [ - -122.37117640469023, + -122.358773472743, 45.68813926897593 ] ] @@ -2154,7 +2154,7 @@ "coordinates": [ [ [ - -122.36084062806754, + -122.34843769612024, 45.750790279819306 ], [ @@ -2178,7 +2178,7 @@ 45.7319949765663 ], [ - -122.36084062806754, + -122.34843769612024, 45.750790279819306 ] ] @@ -2193,7 +2193,7 @@ "coordinates": [ [ [ - -122.29365808001972, + -122.28125514807243, 45.40620972018069 ], [ @@ -2217,7 +2217,7 @@ 45.393679518012014 ], [ - -122.29365808001972, + -122.28125514807243, 45.40620972018069 ] ] @@ -2232,7 +2232,7 @@ "coordinates": [ [ [ - -122.28332230339703, + -122.27091937144974, 45.46886073102407 ], [ @@ -2256,7 +2256,7 @@ 45.45006542777106 ], [ - -122.28332230339703, + -122.27091937144974, 45.46886073102407 ] ] @@ -2271,7 +2271,7 @@ "coordinates": [ [ [ - -122.29365808001972, + -122.28125514807243, 45.531511741867455 ], [ @@ -2295,7 +2295,7 @@ 45.51898153969878 ], [ - -122.29365808001972, + -122.28125514807243, 45.531511741867455 ] ] @@ -2310,7 +2310,7 @@ "coordinates": [ [ [ - -122.28332230339703, + -122.27091937144974, 45.594162752710844 ], [ @@ -2334,7 +2334,7 @@ 45.57536744945783 ], [ - -122.28332230339703, + -122.27091937144974, 45.594162752710844 ] ] @@ -2349,7 +2349,7 @@ "coordinates": [ [ [ - -122.29365808001972, + -122.28125514807243, 45.656813763554226 ], [ @@ -2373,7 +2373,7 @@ 45.64428356138555 ], [ - -122.29365808001972, + -122.28125514807243, 45.656813763554226 ] ] @@ -2388,7 +2388,7 @@ "coordinates": [ [ [ - -122.28332230339703, + -122.27091937144974, 45.719464774397615 ], [ @@ -2412,7 +2412,7 @@ 45.70066947114461 ], [ - -122.28332230339703, + -122.27091937144974, 45.719464774397615 ] ] @@ -2427,7 +2427,7 @@ "coordinates": [ [ [ - -122.29365808001972, + -122.28125514807243, 45.782115785241 ], [ @@ -2451,7 +2451,7 @@ 45.76958558307232 ], [ - -122.29365808001972, + -122.28125514807243, 45.782115785241 ] ] diff --git a/packages/turf-transform-scale/yarn.lock b/packages/turf-transform-scale/yarn.lock index 39566934f2..e3ac19e177 100644 --- a/packages/turf-transform-scale/yarn.lock +++ b/packages/turf-transform-scale/yarn.lock @@ -22,6 +22,10 @@ "@turf/helpers" "^4.6.0" "@turf/meta" "^4.6.0" +"@turf/clone@^4.6.1": + version "4.6.1" + resolved "https://registry.yarnpkg.com/@turf/clone/-/clone-4.6.1.tgz#e4136d9dca48a7065a61454009275c63a9f68121" + "@turf/distance@^4.6.0": version "4.6.0" resolved "https://registry.yarnpkg.com/@turf/distance/-/distance-4.6.0.tgz#6410b9b4ea7e44e4a99be33018d9daab031946e0" From ec599cdb6f45c5fa664304a90dd3c073534d39fa Mon Sep 17 00:00:00 2001 From: stebogit Date: Sun, 13 Aug 2017 02:12:21 -0700 Subject: [PATCH 4/6] fixed #895 in hex-grid: cloned last vertex in turf-hex-grid; reverted changes in transform-scale; fixed JDoc types; --- packages/turf-hex-grid/index.js | 2 +- packages/turf-transform-scale/index.js | 20 +++++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/packages/turf-hex-grid/index.js b/packages/turf-hex-grid/index.js index 8d1abfaf4b..c754fb61ad 100644 --- a/packages/turf-hex-grid/index.js +++ b/packages/turf-hex-grid/index.js @@ -115,7 +115,7 @@ function hexagon(center, rx, ry) { vertices.push([x, y]); } //first and last vertex must be the same - vertices.push(vertices[0]); + vertices.push(vertices[0].slice()); return polygon([vertices]); } diff --git a/packages/turf-transform-scale/index.js b/packages/turf-transform-scale/index.js index 3843ea5c24..80f507198b 100644 --- a/packages/turf-transform-scale/index.js +++ b/packages/turf-transform-scale/index.js @@ -46,39 +46,33 @@ module.exports = function (geojson, factor, origin, mutate) { // Scale each Feature separately if (geojson.type === 'FeatureCollection' && !originIsPoint) { featureEach(geojson, function (feature, index) { - geojson.features[index] = scale(feature, factor, origin, mutate); + geojson.features[index] = scale(feature, factor, origin); }); return geojson; } // Scale Feature/Geometry - return scale(geojson, factor, origin, mutate); + return scale(geojson, factor, origin); }; /** * Scale Feature/Geometry * * @private - * @param {Feature|Geometry} geojson GeoJSON Feature/Geometry + * @param {GeoJSON} geojson GeoJSON Feature/Geometry * @param {number} factor of scaling, positive or negative values greater than 0 * @param {string|Geometry|Feature|Array} [origin="centroid"] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid) - * @param {boolean} [mutate=false] allows GeoJSON input to be mutated - * @returns {Feature|Geometry} scaled GeoJSON Feature/Geometry + * @returns {GeoJSON} scaled GeoJSON object */ -function scale(geojson, factor, origin, mutate) { +function scale(geojson, factor, origin) { // Default params - var geomType = getGeomType(geojson); - var isPoint = geomType === 'Point'; - var isPolygon = geomType === 'Polygon' || geomType === 'MultiPolygon'; + var isPoint = getGeomType(geojson) === 'Point'; origin = defineOrigin(geojson, origin); // Shortcut no-scaling if (factor === 1 || isPoint) return geojson; // Scale each coordinate - coordEach(geojson, function (coord, coordIndex, featureIndex, featureSubIndex) { - // Ignore scaling on first coordinate of Polygons (Issue #895) - if (isPolygon && mutate === true && featureSubIndex === 0) return; - + coordEach(geojson, function (coord) { var originalDistance = rhumbDistance(origin, coord); var bearing = rhumbBearing(origin, coord); var newDistance = originalDistance * factor; From 405f47ff43812a0c3d657fb3631d728d0aa69d4a Mon Sep 17 00:00:00 2001 From: Denis Date: Mon, 14 Aug 2017 11:14:27 -0400 Subject: [PATCH 5/6] Update JSDocs --- packages/turf-transform-scale/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/turf-transform-scale/index.js b/packages/turf-transform-scale/index.js index 80f507198b..b9cc3aad94 100644 --- a/packages/turf-transform-scale/index.js +++ b/packages/turf-transform-scale/index.js @@ -58,10 +58,10 @@ module.exports = function (geojson, factor, origin, mutate) { * Scale Feature/Geometry * * @private - * @param {GeoJSON} geojson GeoJSON Feature/Geometry + * @param {Feature|Geometry} geojson GeoJSON Feature/Geometry * @param {number} factor of scaling, positive or negative values greater than 0 * @param {string|Geometry|Feature|Array} [origin="centroid"] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid) - * @returns {GeoJSON} scaled GeoJSON object + * @returns {Feature|Geometry} scaled GeoJSON Feature/Geometry */ function scale(geojson, factor, origin) { // Default params From 671b34d9284d014c86c721a37ebbd0a533acfdec Mon Sep 17 00:00:00 2001 From: Denis Date: Mon, 14 Aug 2017 11:16:39 -0400 Subject: [PATCH 6/6] Rename geojson to feature (prevents any confusion) --- packages/turf-transform-scale/index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/turf-transform-scale/index.js b/packages/turf-transform-scale/index.js index b9cc3aad94..4e4c552e20 100644 --- a/packages/turf-transform-scale/index.js +++ b/packages/turf-transform-scale/index.js @@ -58,21 +58,21 @@ module.exports = function (geojson, factor, origin, mutate) { * Scale Feature/Geometry * * @private - * @param {Feature|Geometry} geojson GeoJSON Feature/Geometry + * @param {Feature|Geometry} feature GeoJSON Feature/Geometry * @param {number} factor of scaling, positive or negative values greater than 0 * @param {string|Geometry|Feature|Array} [origin="centroid"] Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid) * @returns {Feature|Geometry} scaled GeoJSON Feature/Geometry */ -function scale(geojson, factor, origin) { +function scale(feature, factor, origin) { // Default params - var isPoint = getGeomType(geojson) === 'Point'; - origin = defineOrigin(geojson, origin); + var isPoint = getGeomType(feature) === 'Point'; + origin = defineOrigin(feature, origin); // Shortcut no-scaling - if (factor === 1 || isPoint) return geojson; + if (factor === 1 || isPoint) return feature; // Scale each coordinate - coordEach(geojson, function (coord) { + coordEach(feature, function (coord) { var originalDistance = rhumbDistance(origin, coord); var bearing = rhumbBearing(origin, coord); var newDistance = originalDistance * factor; @@ -82,7 +82,7 @@ function scale(geojson, factor, origin) { if (coord.length === 3) coord[2] *= factor; }); - return geojson; + return feature; } /**