@turf/line-slice 7.3.2 → 7.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +10 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +10 -2
- package/dist/esm/index.js.map +1 -1
- package/package.json +6 -6
package/dist/cjs/index.cjs
CHANGED
|
@@ -8,14 +8,22 @@ function lineSlice(startPt, stopPt, line) {
|
|
|
8
8
|
throw new Error("line must be a LineString");
|
|
9
9
|
const startVertex = _nearestpointonline.nearestPointOnLine.call(void 0, line, startPt);
|
|
10
10
|
const stopVertex = _nearestpointonline.nearestPointOnLine.call(void 0, line, stopPt);
|
|
11
|
-
|
|
11
|
+
fixSegmentIndexBounds(line, startVertex);
|
|
12
|
+
fixSegmentIndexBounds(line, stopVertex);
|
|
13
|
+
const ends = startVertex.properties.segmentIndex <= stopVertex.properties.segmentIndex ? [startVertex, stopVertex] : [stopVertex, startVertex];
|
|
12
14
|
const clipCoords = [ends[0].geometry.coordinates];
|
|
13
|
-
for (let i = ends[0].properties.
|
|
15
|
+
for (let i = ends[0].properties.segmentIndex + 1; i < ends[1].properties.segmentIndex + 1; i++) {
|
|
14
16
|
clipCoords.push(coords[i]);
|
|
15
17
|
}
|
|
16
18
|
clipCoords.push(ends[1].geometry.coordinates);
|
|
17
19
|
return _helpers.lineString.call(void 0, clipCoords, line.type === "Feature" ? line.properties : {});
|
|
18
20
|
}
|
|
21
|
+
function fixSegmentIndexBounds(line, vertex) {
|
|
22
|
+
let geometry = line.type === "Feature" ? line.geometry : line;
|
|
23
|
+
if (vertex.properties.segmentIndex >= geometry.coordinates.length - 1) {
|
|
24
|
+
vertex.properties.segmentIndex = geometry.coordinates.length - 2;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
19
27
|
var index_default = lineSlice;
|
|
20
28
|
|
|
21
29
|
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-line-slice/dist/cjs/index.cjs","../../index.ts"],"names":[],"mappings":"AAAA;ACAA,4CAAmC;AACnC,wCAAgD;AAChD,iEAAmC;AAgCnC,SAAS,SAAA,CACP,OAAA,EACA,MAAA,EACA,IAAA,EACqB;AAErB,EAAA,MAAM,OAAA,EAAS,kCAAA,IAAc,CAAA;AAC7B,EAAA,GAAA,CAAI,gCAAA,IAAY,EAAA,IAAM,YAAA;AACpB,IAAA,MAAM,IAAI,KAAA,CAAM,2BAA2B,CAAA;AAE7C,EAAA,MAAM,YAAA,EAAc,oDAAA,IAAmB,EAAM,OAAO,CAAA;AACpD,EAAA,MAAM,WAAA,EAAa,oDAAA,IAAmB,EAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-line-slice/dist/cjs/index.cjs","../../index.ts"],"names":[],"mappings":"AAAA;ACAA,4CAAmC;AACnC,wCAAgD;AAChD,iEAAmC;AAgCnC,SAAS,SAAA,CACP,OAAA,EACA,MAAA,EACA,IAAA,EACqB;AAErB,EAAA,MAAM,OAAA,EAAS,kCAAA,IAAc,CAAA;AAC7B,EAAA,GAAA,CAAI,gCAAA,IAAY,EAAA,IAAM,YAAA;AACpB,IAAA,MAAM,IAAI,KAAA,CAAM,2BAA2B,CAAA;AAE7C,EAAA,MAAM,YAAA,EAAc,oDAAA,IAAmB,EAAM,OAAO,CAAA;AACpD,EAAA,MAAM,WAAA,EAAa,oDAAA,IAAmB,EAAM,MAAM,CAAA;AAIlD,EAAA,qBAAA,CAAsB,IAAA,EAAM,WAAW,CAAA;AACvC,EAAA,qBAAA,CAAsB,IAAA,EAAM,UAAU,CAAA;AAEtC,EAAA,MAAM,KAAA,EACJ,WAAA,CAAY,UAAA,CAAW,aAAA,GAAgB,UAAA,CAAW,UAAA,CAAW,aAAA,EACzD,CAAC,WAAA,EAAa,UAAU,EAAA,EACxB,CAAC,UAAA,EAAY,WAAW,CAAA;AAC9B,EAAA,MAAM,WAAA,EAAa,CAAC,IAAA,CAAK,CAAC,CAAA,CAAE,QAAA,CAAS,WAAW,CAAA;AAChD,EAAA,IAAA,CAAA,IACM,EAAA,EAAI,IAAA,CAAK,CAAC,CAAA,CAAE,UAAA,CAAW,aAAA,EAAe,CAAA,EAC1C,EAAA,EAAI,IAAA,CAAK,CAAC,CAAA,CAAE,UAAA,CAAW,aAAA,EAAe,CAAA,EACtC,CAAA,EAAA,EACA;AACA,IAAA,UAAA,CAAW,IAAA,CAAK,MAAA,CAAO,CAAC,CAAC,CAAA;AAAA,EAC3B;AACA,EAAA,UAAA,CAAW,IAAA,CAAK,IAAA,CAAK,CAAC,CAAA,CAAE,QAAA,CAAS,WAAW,CAAA;AAC5C,EAAA,OAAO,iCAAA,UAAW,EAAY,IAAA,CAAK,KAAA,IAAS,UAAA,EAAY,IAAA,CAAK,WAAA,EAAa,CAAC,CAAC,CAAA;AAC9E;AAEA,SAAS,qBAAA,CACP,IAAA,EACA,MAAA,EACA;AAMA,EAAA,IAAI,SAAA,EAAuB,IAAA,CAAK,KAAA,IAAS,UAAA,EAAY,IAAA,CAAK,SAAA,EAAW,IAAA;AAErE,EAAA,GAAA,CAAI,MAAA,CAAO,UAAA,CAAW,aAAA,GAAgB,QAAA,CAAS,WAAA,CAAY,OAAA,EAAS,CAAA,EAAG;AAGrE,IAAA,MAAA,CAAO,UAAA,CAAW,aAAA,EAAe,QAAA,CAAS,WAAA,CAAY,OAAA,EAAS,CAAA;AAAA,EACjE;AACF;AAGA,IAAO,cAAA,EAAQ,SAAA;AD5Df;AACE;AACA;AACF,+DAAC","file":"/home/runner/work/turf/turf/packages/turf-line-slice/dist/cjs/index.cjs","sourcesContent":[null,"import { getCoords, getType } from \"@turf/invariant\";\nimport { Coord, lineString as linestring } from \"@turf/helpers\";\nimport { nearestPointOnLine } from \"@turf/nearest-point-on-line\";\nimport type { Feature, LineString, Point } from \"geojson\";\n\n/**\n * Takes a {@link LineString|line}, a start {@link Point}, and a stop point\n * and returns a subsection of the line in-between those points.\n * The start & stop points don't need to fall exactly on the line.\n *\n * This can be useful for extracting only the part of a route between waypoints.\n *\n * @function\n * @param {Coord} startPt starting point\n * @param {Coord} stopPt stopping point\n * @param {Feature<LineString>|LineString} line line to slice\n * @returns {Feature<LineString>} sliced line\n * @example\n * var line = turf.lineString([\n * [-77.031669, 38.878605],\n * [-77.029609, 38.881946],\n * [-77.020339, 38.884084],\n * [-77.025661, 38.885821],\n * [-77.021884, 38.889563],\n * [-77.019824, 38.892368]\n * ]);\n * var start = turf.point([-77.029609, 38.881946]);\n * var stop = turf.point([-77.021884, 38.889563]);\n *\n * var sliced = turf.lineSlice(start, stop, line);\n *\n * //addToMap\n * var addToMap = [start, stop, line]\n */\nfunction lineSlice(\n startPt: Coord,\n stopPt: Coord,\n line: Feature<LineString> | LineString\n): Feature<LineString> {\n // Validation\n const coords = getCoords(line);\n if (getType(line) !== \"LineString\")\n throw new Error(\"line must be a LineString\");\n\n const startVertex = nearestPointOnLine(line, startPt);\n const stopVertex = nearestPointOnLine(line, stopPt);\n\n // Workaround until we can fix backwards incompatible nearestPointOnLine bug\n // #3016\n fixSegmentIndexBounds(line, startVertex);\n fixSegmentIndexBounds(line, stopVertex);\n\n const ends =\n startVertex.properties.segmentIndex <= stopVertex.properties.segmentIndex\n ? [startVertex, stopVertex]\n : [stopVertex, startVertex];\n const clipCoords = [ends[0].geometry.coordinates];\n for (\n let i = ends[0].properties.segmentIndex + 1;\n i < ends[1].properties.segmentIndex + 1;\n i++\n ) {\n clipCoords.push(coords[i]);\n }\n clipCoords.push(ends[1].geometry.coordinates);\n return linestring(clipCoords, line.type === \"Feature\" ? line.properties : {});\n}\n\nfunction fixSegmentIndexBounds(\n line: Feature<LineString> | LineString,\n vertex: Feature<Point, { segmentIndex: number }>\n) {\n // There is a bug in nearestPointOnLine where the returned segmentIndex can\n // refer to a non-existent segment (overflows). Until we can fix that bug\n // (see https://github.com/Turfjs/turf/issues/3016) we adjust the\n // segmentIndex here to make sure it's in range.\n\n let geometry: LineString = line.type === \"Feature\" ? line.geometry : line;\n\n if (vertex.properties.segmentIndex >= geometry.coordinates.length - 1) {\n // segmentIndex refers to a non-existent segment beyond the end of the\n // lineString. Override it.\n vertex.properties.segmentIndex = geometry.coordinates.length - 2;\n }\n}\n\nexport { lineSlice };\nexport default lineSlice;\n"]}
|
package/dist/esm/index.js
CHANGED
|
@@ -8,14 +8,22 @@ function lineSlice(startPt, stopPt, line) {
|
|
|
8
8
|
throw new Error("line must be a LineString");
|
|
9
9
|
const startVertex = nearestPointOnLine(line, startPt);
|
|
10
10
|
const stopVertex = nearestPointOnLine(line, stopPt);
|
|
11
|
-
|
|
11
|
+
fixSegmentIndexBounds(line, startVertex);
|
|
12
|
+
fixSegmentIndexBounds(line, stopVertex);
|
|
13
|
+
const ends = startVertex.properties.segmentIndex <= stopVertex.properties.segmentIndex ? [startVertex, stopVertex] : [stopVertex, startVertex];
|
|
12
14
|
const clipCoords = [ends[0].geometry.coordinates];
|
|
13
|
-
for (let i = ends[0].properties.
|
|
15
|
+
for (let i = ends[0].properties.segmentIndex + 1; i < ends[1].properties.segmentIndex + 1; i++) {
|
|
14
16
|
clipCoords.push(coords[i]);
|
|
15
17
|
}
|
|
16
18
|
clipCoords.push(ends[1].geometry.coordinates);
|
|
17
19
|
return linestring(clipCoords, line.type === "Feature" ? line.properties : {});
|
|
18
20
|
}
|
|
21
|
+
function fixSegmentIndexBounds(line, vertex) {
|
|
22
|
+
let geometry = line.type === "Feature" ? line.geometry : line;
|
|
23
|
+
if (vertex.properties.segmentIndex >= geometry.coordinates.length - 1) {
|
|
24
|
+
vertex.properties.segmentIndex = geometry.coordinates.length - 2;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
19
27
|
var index_default = lineSlice;
|
|
20
28
|
export {
|
|
21
29
|
index_default as default,
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { getCoords, getType } from \"@turf/invariant\";\nimport { Coord, lineString as linestring } from \"@turf/helpers\";\nimport { nearestPointOnLine } from \"@turf/nearest-point-on-line\";\nimport { Feature, LineString } from \"geojson\";\n\n/**\n * Takes a {@link LineString|line}, a start {@link Point}, and a stop point\n * and returns a subsection of the line in-between those points.\n * The start & stop points don't need to fall exactly on the line.\n *\n * This can be useful for extracting only the part of a route between waypoints.\n *\n * @function\n * @param {Coord} startPt starting point\n * @param {Coord} stopPt stopping point\n * @param {Feature<LineString>|LineString} line line to slice\n * @returns {Feature<LineString>} sliced line\n * @example\n * var line = turf.lineString([\n * [-77.031669, 38.878605],\n * [-77.029609, 38.881946],\n * [-77.020339, 38.884084],\n * [-77.025661, 38.885821],\n * [-77.021884, 38.889563],\n * [-77.019824, 38.892368]\n * ]);\n * var start = turf.point([-77.029609, 38.881946]);\n * var stop = turf.point([-77.021884, 38.889563]);\n *\n * var sliced = turf.lineSlice(start, stop, line);\n *\n * //addToMap\n * var addToMap = [start, stop, line]\n */\nfunction lineSlice(\n startPt: Coord,\n stopPt: Coord,\n line: Feature<LineString> | LineString\n): Feature<LineString> {\n // Validation\n const coords = getCoords(line);\n if (getType(line) !== \"LineString\")\n throw new Error(\"line must be a LineString\");\n\n const startVertex = nearestPointOnLine(line, startPt);\n const stopVertex = nearestPointOnLine(line, stopPt);\n const ends =\n startVertex.properties.
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { getCoords, getType } from \"@turf/invariant\";\nimport { Coord, lineString as linestring } from \"@turf/helpers\";\nimport { nearestPointOnLine } from \"@turf/nearest-point-on-line\";\nimport type { Feature, LineString, Point } from \"geojson\";\n\n/**\n * Takes a {@link LineString|line}, a start {@link Point}, and a stop point\n * and returns a subsection of the line in-between those points.\n * The start & stop points don't need to fall exactly on the line.\n *\n * This can be useful for extracting only the part of a route between waypoints.\n *\n * @function\n * @param {Coord} startPt starting point\n * @param {Coord} stopPt stopping point\n * @param {Feature<LineString>|LineString} line line to slice\n * @returns {Feature<LineString>} sliced line\n * @example\n * var line = turf.lineString([\n * [-77.031669, 38.878605],\n * [-77.029609, 38.881946],\n * [-77.020339, 38.884084],\n * [-77.025661, 38.885821],\n * [-77.021884, 38.889563],\n * [-77.019824, 38.892368]\n * ]);\n * var start = turf.point([-77.029609, 38.881946]);\n * var stop = turf.point([-77.021884, 38.889563]);\n *\n * var sliced = turf.lineSlice(start, stop, line);\n *\n * //addToMap\n * var addToMap = [start, stop, line]\n */\nfunction lineSlice(\n startPt: Coord,\n stopPt: Coord,\n line: Feature<LineString> | LineString\n): Feature<LineString> {\n // Validation\n const coords = getCoords(line);\n if (getType(line) !== \"LineString\")\n throw new Error(\"line must be a LineString\");\n\n const startVertex = nearestPointOnLine(line, startPt);\n const stopVertex = nearestPointOnLine(line, stopPt);\n\n // Workaround until we can fix backwards incompatible nearestPointOnLine bug\n // #3016\n fixSegmentIndexBounds(line, startVertex);\n fixSegmentIndexBounds(line, stopVertex);\n\n const ends =\n startVertex.properties.segmentIndex <= stopVertex.properties.segmentIndex\n ? [startVertex, stopVertex]\n : [stopVertex, startVertex];\n const clipCoords = [ends[0].geometry.coordinates];\n for (\n let i = ends[0].properties.segmentIndex + 1;\n i < ends[1].properties.segmentIndex + 1;\n i++\n ) {\n clipCoords.push(coords[i]);\n }\n clipCoords.push(ends[1].geometry.coordinates);\n return linestring(clipCoords, line.type === \"Feature\" ? line.properties : {});\n}\n\nfunction fixSegmentIndexBounds(\n line: Feature<LineString> | LineString,\n vertex: Feature<Point, { segmentIndex: number }>\n) {\n // There is a bug in nearestPointOnLine where the returned segmentIndex can\n // refer to a non-existent segment (overflows). Until we can fix that bug\n // (see https://github.com/Turfjs/turf/issues/3016) we adjust the\n // segmentIndex here to make sure it's in range.\n\n let geometry: LineString = line.type === \"Feature\" ? line.geometry : line;\n\n if (vertex.properties.segmentIndex >= geometry.coordinates.length - 1) {\n // segmentIndex refers to a non-existent segment beyond the end of the\n // lineString. Override it.\n vertex.properties.segmentIndex = geometry.coordinates.length - 2;\n }\n}\n\nexport { lineSlice };\nexport default lineSlice;\n"],"mappings":";AAAA,SAAS,WAAW,eAAe;AACnC,SAAgB,cAAc,kBAAkB;AAChD,SAAS,0BAA0B;AAgCnC,SAAS,UACP,SACA,QACA,MACqB;AAErB,QAAM,SAAS,UAAU,IAAI;AAC7B,MAAI,QAAQ,IAAI,MAAM;AACpB,UAAM,IAAI,MAAM,2BAA2B;AAE7C,QAAM,cAAc,mBAAmB,MAAM,OAAO;AACpD,QAAM,aAAa,mBAAmB,MAAM,MAAM;AAIlD,wBAAsB,MAAM,WAAW;AACvC,wBAAsB,MAAM,UAAU;AAEtC,QAAM,OACJ,YAAY,WAAW,gBAAgB,WAAW,WAAW,eACzD,CAAC,aAAa,UAAU,IACxB,CAAC,YAAY,WAAW;AAC9B,QAAM,aAAa,CAAC,KAAK,CAAC,EAAE,SAAS,WAAW;AAChD,WACM,IAAI,KAAK,CAAC,EAAE,WAAW,eAAe,GAC1C,IAAI,KAAK,CAAC,EAAE,WAAW,eAAe,GACtC,KACA;AACA,eAAW,KAAK,OAAO,CAAC,CAAC;AAAA,EAC3B;AACA,aAAW,KAAK,KAAK,CAAC,EAAE,SAAS,WAAW;AAC5C,SAAO,WAAW,YAAY,KAAK,SAAS,YAAY,KAAK,aAAa,CAAC,CAAC;AAC9E;AAEA,SAAS,sBACP,MACA,QACA;AAMA,MAAI,WAAuB,KAAK,SAAS,YAAY,KAAK,WAAW;AAErE,MAAI,OAAO,WAAW,gBAAgB,SAAS,YAAY,SAAS,GAAG;AAGrE,WAAO,WAAW,eAAe,SAAS,YAAY,SAAS;AAAA,EACjE;AACF;AAGA,IAAO,gBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/line-slice",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.4",
|
|
4
4
|
"description": "Useful for extracting only the part of a route between waypoints.",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"test:tape": "tsx test.ts"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@turf/truncate": "7.3.
|
|
57
|
+
"@turf/truncate": "7.3.4",
|
|
58
58
|
"@types/benchmark": "^2.1.5",
|
|
59
59
|
"@types/tape": "^5.8.1",
|
|
60
60
|
"benchmark": "^2.1.4",
|
|
@@ -66,11 +66,11 @@
|
|
|
66
66
|
"write-json-file": "^6.0.0"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@turf/helpers": "7.3.
|
|
70
|
-
"@turf/invariant": "7.3.
|
|
71
|
-
"@turf/nearest-point-on-line": "7.3.
|
|
69
|
+
"@turf/helpers": "7.3.4",
|
|
70
|
+
"@turf/invariant": "7.3.4",
|
|
71
|
+
"@turf/nearest-point-on-line": "7.3.4",
|
|
72
72
|
"@types/geojson": "^7946.0.10",
|
|
73
73
|
"tslib": "^2.8.1"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "a0878648b801443f342aae692c60ab95a1da61a9"
|
|
76
76
|
}
|