From c81d1ef5ecd16f51ac397e14bd96f5a8110eeba7 Mon Sep 17 00:00:00 2001 From: Rowan Winsemius Date: Tue, 12 Jun 2018 23:57:45 +1000 Subject: [PATCH 1/2] Center-of-mass fix. Resolves #1385 --- packages/turf-center-of-mass/index.ts | 4 ++-- packages/turf-center-of-mass/test.js | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/turf-center-of-mass/index.ts b/packages/turf-center-of-mass/index.ts index d0abd8b617..61377d0d5b 100644 --- a/packages/turf-center-of-mass/index.ts +++ b/packages/turf-center-of-mass/index.ts @@ -1,7 +1,7 @@ import convex from '@turf/convex'; import centroid from '@turf/centroid'; import { point, Properties, AllGeoJSON, Feature, Point } from '@turf/helpers'; -import { getType } from '@turf/invariant'; +import { getType, getCoord } from '@turf/invariant'; import { coordEach } from '@turf/meta'; /** @@ -25,7 +25,7 @@ function centerOfMass

(geojson: any, options: { } = {}): Feature { switch (getType(geojson)) { case 'Point': - return geojson; + return point(getCoord(geojson), options.properties); case 'Polygon': var coords = []; coordEach(geojson, function (coord) { diff --git a/packages/turf-center-of-mass/test.js b/packages/turf-center-of-mass/test.js index 7cdda486aa..c8349d43c4 100644 --- a/packages/turf-center-of-mass/test.js +++ b/packages/turf-center-of-mass/test.js @@ -58,6 +58,13 @@ test('center of mass -- no area', t => { t.end(); }); +test('center of mass -- point', t => { + const p = point([0, 0]); + const pt = centerOfMass(p); + t.deepEqual(pt, point([0, 0]), 'point returns pt'); + t.end(); +}); + test('center of mass -- properties', t => { const line = lineString([[0, 0], [1, 1]]); const pt = centerOfMass(line, {properties: {foo: 'bar'}}); From a72fa53d2f001951ca0bb6a35967ad56e0604df7 Mon Sep 17 00:00:00 2001 From: Rowan Winsemius Date: Wed, 13 Jun 2018 00:01:11 +1000 Subject: [PATCH 2/2] Additional test for input geom point --- packages/turf-center-of-mass/test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/turf-center-of-mass/test.js b/packages/turf-center-of-mass/test.js index c8349d43c4..a20d9251d9 100644 --- a/packages/turf-center-of-mass/test.js +++ b/packages/turf-center-of-mass/test.js @@ -65,6 +65,13 @@ test('center of mass -- point', t => { t.end(); }); +test('center of mass -- point geom', t => { + const geomPoint = {type: 'Point', coordinates: [0, 0]}; + const pt = centerOfMass(geomPoint); + t.deepEqual(pt, point([0, 0]), 'point geom returns pt'); + t.end(); +}); + test('center of mass -- properties', t => { const line = lineString([[0, 0], [1, 1]]); const pt = centerOfMass(line, {properties: {foo: 'bar'}});