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

New module @turf/bbox-clip 🎉 #652

Merged
merged 4 commits into from
Apr 9, 2017
Merged

New module @turf/bbox-clip 🎉 #652

merged 4 commits into from
Apr 9, 2017

Conversation

DenisCarriere
Copy link
Member

New module! @turf/bbox-clip 🎉

Takes a Feature and a bbox and clips the feature to the bbox using lineclip.

Contributors

JS Docs

/**
 * Takes a {@link Feature} and a bbox and clips the feature to the bbox using [lineclip](https:/mapbox/lineclip).
 * May result in degenerate edges when clipping Polygons.
 *
 * @name bbox-clip
 * @param {Feature<LineString|MultiLineString|Polygon|MultiPolygon>} feature feature to clip to the bbox
 * @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
 * @returns {Feature<LineString|MultiLineString|Polygon|MultiPolygon>} clipped Feature
 * @example
 * var bbox = [0, 0, 10, 10];
 * var poly = {
 *   "type": "Feature",
 *   "properties": {},
 *   "geometry": {
 *     "type": "Polygon",
 *     "coordinates": [[[2, 2], [8, 4], [12, 8], [3, 7], [2, 2]]]
 *   }
 * }
 *
 * var clipped = turf.bboxClip(poly, bbox);
 *
 * //=clipped
 */

Dependencies

"dependencies": {
  "@turf/helpers": "^4.0.1",
  "@turf/invariant": "^4.0.1",
  "lineclip": "^1.1.5"
}

Benchmark Results

linestring-single-line x 1,065,073 ops/sec ±1.11% (90 runs sampled)
linestring x 56,599 ops/sec ±1.17% (90 runs sampled)
multi-linestring x 859,048 ops/sec ±1.01% (91 runs sampled)
multi-polygon x 26,991 ops/sec ±0.87% (94 runs sampled)
polygon-crossing-hole x 25,277 ops/sec ±0.72% (92 runs sampled)
polygon-holes x 27,233 ops/sec ±0.89% (91 runs sampled)
polygon x 21,339 ops/sec ±1.19% (89 runs sampled)

Examples test/out

  • Red: clipped lines (results)
  • Green: input feature
  • Blue: bbox clipping feature

image

image

image

CC: @Turfjs/ownership #281

@DenisCarriere
Copy link
Member Author

👍 Thanks @mourner for reviewing

@DenisCarriere DenisCarriere merged commit 2f0a511 into master Apr 9, 2017
@DenisCarriere DenisCarriere deleted the bbox-clip branch April 9, 2017 03:49
@DenisCarriere DenisCarriere added this to the 4.1.0 milestone Apr 9, 2017
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.

2 participants