Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish new module @turf/rewind #700

Merged
merged 5 commits into from
May 3, 2017
Merged

Publish new module @turf/rewind #700

merged 5 commits into from
May 3, 2017

Conversation

DenisCarriere
Copy link
Member

@DenisCarriere DenisCarriere commented May 1, 2017

New Module @turf/rewind 🎉

Rewind LineString or Polygon outer ring clockwise and inner rings counterclockwise (Uses Shoelace Formula).

Ref Issues: #250 #66

Contributors

Geometry Support

  • (Multi)Polygon
  • (Multi)LineString

JSDocs

/**
 * Rewind {@link LineString|(Mutli)LineString} or {@link Polygon|(Multi)Polygon} outer ring clockwise and inner rings counterclockwise (Uses {@link https://en.wikipedia.org/wiki/Shoelace_formula|Shoelace Formula}).
 *
 * @name rewind
 * @param {Feature<Polygon|MultiPolygon|LineString|MultiLineString>} geojson input GeoJSON Polygon
 * @param {Boolean} [reverse=false] enable reverse winding
 * @param {boolean} [mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
 * @returns {Feature<Polygon|MultiPolygon|LineString|MultiLineString>} rewind Polygon
 * @example
 * var polygon = {
 *     "type": "Feature",
 *     "properties": {},
 *     "geometry": {
 *         "type": "Polygon",
 *         "coordinates": [
 *             [[121, -29], [138, -29], [138, -18], [121, -18], [121, -29]]
 *         ]
 *     }
 * };
 * var rewind = turf.rewind(polygon);
 *
 * //addToMap
 * var addToMap = [rewind];
 */

Benchmark Results

Blazing fast 🔥

geometry-polygon-counter-clockwise x 3,217,454 ops/sec ±4.31% (83 runs sampled)
line-clockwise x 2,249,133 ops/sec ±0.97% (90 runs sampled)
line-counter-clockwise x 2,224,334 ops/sec ±1.40% (87 runs sampled)
polygon-clockwise x 3,429,437 ops/sec ±1.49% (86 runs sampled)
polygon-counter-clockwise x 3,464,880 ops/sec ±1.05% (88 runs sampled)

Example

Polygon with outer ring as counter-clockwise

image

Using @turf/rewind re-orders outer ring as clockwise

image

CC: @Turfjs/ownership

@DenisCarriere DenisCarriere added this to the 4.3.0 milestone May 1, 2017
@DenisCarriere DenisCarriere self-assigned this May 1, 2017
@DenisCarriere DenisCarriere merged commit 054b95b into master May 3, 2017
@DenisCarriere DenisCarriere deleted the turf-rewind branch May 3, 2017 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant