Skip to content

Commit

Permalink
Updated the turf-convex doc to tell that Features are accepted (Turfj…
Browse files Browse the repository at this point in the history
…s#442)

* Updated the turf-convex doc to tell that Features are accepted as well as a FeatureCollection

* Test added for turf-convex with a Polygon Feature.

* Used the generate-readmes script to generate README.md files
  • Loading branch information
aurelien-defossez authored and tmcw committed Aug 4, 2016
1 parent b317199 commit 117ad97
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/turf-center-of-mass/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @turf/center-of-mass

# center-of-mass
# centerOfMass

Takes a [feature](http://geojson.org/geojson-spec.html#feature-objects)
or a [featureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)
Expand All @@ -9,7 +9,7 @@ using this formula: [Centroid of Polygon](https://en.wikipedia.org/wiki/Centroid

**Parameters**

- `feature` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)** the feature
- `fc` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects))** the feature collection or feature

**Examples**

Expand Down
7 changes: 4 additions & 3 deletions packages/turf-convex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

# convex

Takes a set of [points](http://geojson.org/geojson-spec.html#point) and returns a
[convex hull](http://en.wikipedia.org/wiki/Convex_hull) polygon.
Takes a [feature](http://geojson.org/geojson-spec.html#feature-objects)
or a [featureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)
and returns a [convex hull](http://en.wikipedia.org/wiki/Convex_hull) polygon.

Internally this uses
the [convex-hull](https://github.com/mikolalysenko/convex-hull) module that
implements a [monotone chain hull](http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain).

**Parameters**

- `featurecollection` **[FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** input points
- `feature` **([Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects))** input Feature or FeatureCollection

**Examples**

Expand Down
11 changes: 6 additions & 5 deletions packages/turf-convex/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ var each = require('@turf/meta').coordEach,
polygon = require('@turf/helpers').polygon;

/**
* Takes a set of {@link Point|points} and returns a
* [convex hull](http://en.wikipedia.org/wiki/Convex_hull) polygon.
* Takes a [feature](http://geojson.org/geojson-spec.html#feature-objects)
* or a [featureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)
* and returns a [convex hull](http://en.wikipedia.org/wiki/Convex_hull) polygon.
*
* Internally this uses
* the [convex-hull](https://github.com/mikolalysenko/convex-hull) module that
* implements a [monotone chain hull](http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain).
*
* @name convex
* @param {FeatureCollection<Point>} featurecollection input points
* @param {(Feature|FeatureCollection)} feature input Feature or FeatureCollection
* @returns {Feature<Polygon>} a convex hull
* @example
* var points = {
Expand Down Expand Up @@ -73,11 +74,11 @@ var each = require('@turf/meta').coordEach,
*
* //=result
*/
module.exports = function (featurecollection) {
module.exports = function (feature) {
var points = [];

// Remove Z in coordinates because it breaks the convexHull algorithm
each(featurecollection, function (coord) {
each(feature, function (coord) {
points.push([coord[0], coord[1]]);
});

Expand Down
80 changes: 80 additions & 0 deletions packages/turf-convex/test/fixtures/in/elevation5.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-74.08355712890625,
40.6723059714534
],
[
-73.7567138671875,
40.8595252289932
],
[
-73.86383056640625,
40.97575093157534
],
[
-74.0203857421875,
41.04621681452063
],
[
-74.24285888671875,
41.04828819952275
],
[
-74.410400390625,
40.977824533189526
],
[
-74.5257568359375,
40.851215574282456
],
[
-74.5697021484375,
40.74309523218185
],
[
-74.59991455078125,
40.60144147645398
],
[
-74.56146240234375,
40.47620304302563
],
[
-74.41864013671875,
40.386304853509046
],
[
-74.2236328125,
40.32141999593439
],
[
-74.01214599609375,
40.317231732315236
],
[
-73.85009765625,
40.34654412118006
],
[
-73.76220703125,
40.444856858961764
],
[
-74.08355712890625,
40.6723059714534
]
]
]
}
}
]
}
1 change: 1 addition & 0 deletions packages/turf-convex/test/fixtures/out/elevation5.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[ [ [ -74.56146240234375, 40.47620304302563 ], [ -74.59991455078125, 40.60144147645398 ], [ -74.5697021484375, 40.74309523218185 ], [ -74.5257568359375, 40.851215574282456 ], [ -74.410400390625, 40.977824533189526 ], [ -74.24285888671875, 41.04828819952275 ], [ -74.0203857421875, 41.04621681452063 ], [ -73.86383056640625, 40.97575093157534 ], [ -73.7567138671875, 40.8595252289932 ], [ -73.76220703125, 40.444856858961764 ], [ -73.85009765625, 40.34654412118006 ], [ -74.01214599609375, 40.317231732315236 ], [ -74.2236328125, 40.32141999593439 ], [ -74.41864013671875, 40.386304853509046 ], [ -74.56146240234375, 40.47620304302563 ] ] ]},"properties":{}}

0 comments on commit 117ad97

Please sign in to comment.