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

Implement Clone module #824

Merged
merged 4 commits into from
Jun 30, 2017
Merged

Implement Clone module #824

merged 4 commits into from
Jun 30, 2017

Conversation

DenisCarriere
Copy link
Member

New module! 🎉 @turf/clone

Prevents GeoJSON coordinates from being mutated, similar to JSON.parse(JSON.stringify(geojson)).

Only cloning the coordinates can be 3x-20x faster than the parse + stringify approach.

JSDocs

/**
 * Prevents GeoJSON coordinates from being mutated, similar to JSON.parse(JSON.stringify(geojson)).
 *
 * @name clone
 * @param {GeoJSON} geojson GeoJSON Object
 * @param {Boolean} [cloneAll=false] clones entire GeoJSON (3-20x slower if True)
 * @returns {GeoJSON} cloned GeoJSON Object
 * @example
 * var line = {
 *   "type": "Feature",
 *   "properties": {},
 *   "geometry": {
 *     "type": "LineString",
 *     "coordinates": [[-74, 40], [-78, 42], [-82, 35]]
 *   }
 * }
 * var lineCloned = turf.clone(line);
 */

Benchmark Results

Benchmark Results

Point x 6,972,739 ops/sec ±5.50% (86 runs sampled)
Point -- clones entire object x 357,437 ops/sec ±0.95% (88 runs sampled)
LineString x 1,502,039 ops/sec ±1.01% (86 runs sampled)
LineString -- clones entire object x 291,562 ops/sec ±1.00% (88 runs sampled)
Polygon x 723,111 ops/sec ±1.06% (87 runs sampled)
Polygon -- clones entire object x 227,034 ops/sec ±0.62% (91 runs sampled)
FeatureCollection x 370,012 ops/sec ±1.25% (87 runs sampled)
FeatureCollection -- clones entire object x 91,582 ops/sec ±0.81% (86 runs sampled)

@DenisCarriere DenisCarriere added this to the 4.5.0 milestone Jun 30, 2017
@DenisCarriere DenisCarriere self-assigned this Jun 30, 2017
@DenisCarriere DenisCarriere merged commit 99229d8 into master Jun 30, 2017
@DenisCarriere DenisCarriere deleted the turf-clone branch June 30, 2017 17:19
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