From 5314e7c06579fa6f8d965e289b4a94c464ea1ec2 Mon Sep 17 00:00:00 2001 From: xiongjiabin Date: Thu, 26 Oct 2017 05:58:51 -0500 Subject: [PATCH 1/3] fix bug when the number of segments is integer if numberOfSegments is an integer, like line length is 100, and segmentLength is 10, it's just 10 segments, no need to plus 1 to 11, otherwise will throw exception later. --- packages/turf-line-chunk/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/turf-line-chunk/index.js b/packages/turf-line-chunk/index.js index 2ec06dc488..d5be1bed61 100644 --- a/packages/turf-line-chunk/index.js +++ b/packages/turf-line-chunk/index.js @@ -64,7 +64,12 @@ function sliceLineSegments(line, segmentLength, units, callback) { // If the line is shorter than the segment length then the orginal line is returned. if (lineLength <= segmentLength) return callback(line); - var numberOfSegments = Math.floor(lineLength / segmentLength) + 1; + var numberOfSegments = lineLength / segmentLength; + // If numberOfSegments is integer, no need to plus 1 + if(!Number.isInteger(numberOfSegments)){ + numberOfSegments = Math.floor(numberOfSegments) + 1; + } + for (var i = 0; i < numberOfSegments; i++) { var outline = lineSliceAlong(line, segmentLength * i, segmentLength * (i + 1), {units: units}); callback(outline, i); From 60df1bbbe4a60dc3baf2b337e7de7a3a87384fbf Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 26 Oct 2017 23:22:38 -0400 Subject: [PATCH 2/3] Update index.js --- packages/turf-line-chunk/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/turf-line-chunk/index.js b/packages/turf-line-chunk/index.js index d5be1bed61..70c9b7ffc0 100644 --- a/packages/turf-line-chunk/index.js +++ b/packages/turf-line-chunk/index.js @@ -65,8 +65,9 @@ function sliceLineSegments(line, segmentLength, units, callback) { if (lineLength <= segmentLength) return callback(line); var numberOfSegments = lineLength / segmentLength; + // If numberOfSegments is integer, no need to plus 1 - if(!Number.isInteger(numberOfSegments)){ + if (!Number.isInteger(numberOfSegments)) { numberOfSegments = Math.floor(numberOfSegments) + 1; } From 55137ce9306bee0d7332cda70f80350531a6ce81 Mon Sep 17 00:00:00 2001 From: Denis Date: Fri, 27 Oct 2017 00:08:15 -0400 Subject: [PATCH 3/3] Removing trailing spaces --- packages/turf-line-chunk/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/turf-line-chunk/index.js b/packages/turf-line-chunk/index.js index 70c9b7ffc0..89470e6b9d 100644 --- a/packages/turf-line-chunk/index.js +++ b/packages/turf-line-chunk/index.js @@ -70,7 +70,7 @@ function sliceLineSegments(line, segmentLength, units, callback) { if (!Number.isInteger(numberOfSegments)) { numberOfSegments = Math.floor(numberOfSegments) + 1; } - + for (var i = 0; i < numberOfSegments; i++) { var outline = lineSliceAlong(line, segmentLength * i, segmentLength * (i + 1), {units: units}); callback(outline, i);