@turf/kinks 7.1.0-alpha.7 → 7.1.0
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/README.md +3 -13
- package/dist/cjs/index.cjs +90 -13
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +89 -12
- package/dist/esm/index.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ returns [points][5] at all self-intersections.
|
|
|
10
10
|
|
|
11
11
|
### Parameters
|
|
12
12
|
|
|
13
|
-
* `featureIn` **[Feature][6]<([LineString][
|
|
13
|
+
* `featureIn` **[Feature][6]<([LineString][1] | [MultiLineString][2] | [MultiPolygon][3] | [Polygon][4])>** input feature
|
|
14
14
|
|
|
15
15
|
### Examples
|
|
16
16
|
|
|
@@ -29,7 +29,7 @@ var kinks = turf.kinks(poly);
|
|
|
29
29
|
var addToMap = [poly, kinks]
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
Returns **[FeatureCollection][
|
|
32
|
+
Returns **[FeatureCollection][7]<[Point][5]>** self-intersections
|
|
33
33
|
|
|
34
34
|
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.4
|
|
35
35
|
|
|
@@ -43,17 +43,7 @@ Returns **[FeatureCollection][11]<[Point][12]>** self-intersections
|
|
|
43
43
|
|
|
44
44
|
[6]: https://tools.ietf.org/html/rfc7946#section-3.2
|
|
45
45
|
|
|
46
|
-
[7]: https://tools.ietf.org/html/rfc7946#section-3.
|
|
47
|
-
|
|
48
|
-
[8]: https://tools.ietf.org/html/rfc7946#section-3.1.5
|
|
49
|
-
|
|
50
|
-
[9]: https://tools.ietf.org/html/rfc7946#section-3.1.7
|
|
51
|
-
|
|
52
|
-
[10]: https://tools.ietf.org/html/rfc7946#section-3.1.6
|
|
53
|
-
|
|
54
|
-
[11]: https://tools.ietf.org/html/rfc7946#section-3.3
|
|
55
|
-
|
|
56
|
-
[12]: https://tools.ietf.org/html/rfc7946#section-3.1.2
|
|
46
|
+
[7]: https://tools.ietf.org/html/rfc7946#section-3.3
|
|
57
47
|
|
|
58
48
|
<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
|
|
59
49
|
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,28 +1,105 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true})
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
|
|
2
2
|
var _helpers = require('@turf/helpers');
|
|
3
|
-
|
|
4
|
-
// lib/sweepline-intersections-export.ts
|
|
5
|
-
var _sweeplineintersections = require('sweepline-intersections'); var _sweeplineintersections2 = _interopRequireDefault(_sweeplineintersections);
|
|
6
|
-
var sweeplineIntersections = _sweeplineintersections2.default;
|
|
7
|
-
|
|
8
|
-
// index.ts
|
|
9
3
|
function kinks(featureIn) {
|
|
4
|
+
let coordinates;
|
|
5
|
+
let feature;
|
|
10
6
|
const results = {
|
|
11
7
|
type: "FeatureCollection",
|
|
12
8
|
features: []
|
|
13
9
|
};
|
|
14
|
-
if (featureIn.type === "Feature"
|
|
10
|
+
if (featureIn.type === "Feature") {
|
|
11
|
+
feature = featureIn.geometry;
|
|
12
|
+
} else {
|
|
13
|
+
feature = featureIn;
|
|
14
|
+
}
|
|
15
|
+
if (feature.type === "LineString") {
|
|
16
|
+
coordinates = [feature.coordinates];
|
|
17
|
+
} else if (feature.type === "MultiLineString") {
|
|
18
|
+
coordinates = feature.coordinates;
|
|
19
|
+
} else if (feature.type === "MultiPolygon") {
|
|
20
|
+
coordinates = [].concat(...feature.coordinates);
|
|
21
|
+
} else if (feature.type === "Polygon") {
|
|
22
|
+
coordinates = feature.coordinates;
|
|
23
|
+
} else {
|
|
15
24
|
throw new Error(
|
|
16
25
|
"Input must be a LineString, MultiLineString, Polygon, or MultiPolygon Feature or Geometry"
|
|
17
26
|
);
|
|
18
27
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
coordinates.forEach((line1) => {
|
|
29
|
+
coordinates.forEach((line2) => {
|
|
30
|
+
for (let i = 0; i < line1.length - 1; i++) {
|
|
31
|
+
for (let k = i; k < line2.length - 1; k++) {
|
|
32
|
+
if (line1 === line2) {
|
|
33
|
+
if (Math.abs(i - k) === 1) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (
|
|
37
|
+
// segments are first and last segment of lineString
|
|
38
|
+
i === 0 && k === line1.length - 2 && // lineString is closed
|
|
39
|
+
line1[i][0] === line1[line1.length - 1][0] && line1[i][1] === line1[line1.length - 1][1]
|
|
40
|
+
) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const intersection = lineIntersects(
|
|
45
|
+
line1[i][0],
|
|
46
|
+
line1[i][1],
|
|
47
|
+
line1[i + 1][0],
|
|
48
|
+
line1[i + 1][1],
|
|
49
|
+
line2[k][0],
|
|
50
|
+
line2[k][1],
|
|
51
|
+
line2[k + 1][0],
|
|
52
|
+
line2[k + 1][1]
|
|
53
|
+
);
|
|
54
|
+
if (intersection) {
|
|
55
|
+
results.features.push(_helpers.point.call(void 0, [intersection[0], intersection[1]]));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
24
61
|
return results;
|
|
25
62
|
}
|
|
63
|
+
function lineIntersects(line1StartX, line1StartY, line1EndX, line1EndY, line2StartX, line2StartY, line2EndX, line2EndY) {
|
|
64
|
+
let denominator;
|
|
65
|
+
let a;
|
|
66
|
+
let b;
|
|
67
|
+
let numerator1;
|
|
68
|
+
let numerator2;
|
|
69
|
+
const result = {
|
|
70
|
+
x: null,
|
|
71
|
+
y: null,
|
|
72
|
+
onLine1: false,
|
|
73
|
+
onLine2: false
|
|
74
|
+
};
|
|
75
|
+
denominator = (line2EndY - line2StartY) * (line1EndX - line1StartX) - (line2EndX - line2StartX) * (line1EndY - line1StartY);
|
|
76
|
+
if (denominator === 0) {
|
|
77
|
+
if (result.x !== null && result.y !== null) {
|
|
78
|
+
return result;
|
|
79
|
+
} else {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
a = line1StartY - line2StartY;
|
|
84
|
+
b = line1StartX - line2StartX;
|
|
85
|
+
numerator1 = (line2EndX - line2StartX) * a - (line2EndY - line2StartY) * b;
|
|
86
|
+
numerator2 = (line1EndX - line1StartX) * a - (line1EndY - line1StartY) * b;
|
|
87
|
+
a = numerator1 / denominator;
|
|
88
|
+
b = numerator2 / denominator;
|
|
89
|
+
result.x = line1StartX + a * (line1EndX - line1StartX);
|
|
90
|
+
result.y = line1StartY + a * (line1EndY - line1StartY);
|
|
91
|
+
if (a >= 0 && a <= 1) {
|
|
92
|
+
result.onLine1 = true;
|
|
93
|
+
}
|
|
94
|
+
if (b >= 0 && b <= 1) {
|
|
95
|
+
result.onLine2 = true;
|
|
96
|
+
}
|
|
97
|
+
if (result.onLine1 && result.onLine2) {
|
|
98
|
+
return [result.x, result.y];
|
|
99
|
+
} else {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
26
103
|
var turf_kinks_default = kinks;
|
|
27
104
|
|
|
28
105
|
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts"
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AASA,SAAS,aAAa;AAwBtB,SAAS,MACP,WAC0B;AAC1B,MAAI;AACJ,MAAI;AACJ,QAAM,UAAoC;AAAA,IACxC,MAAM;AAAA,IACN,UAAU,CAAC;AAAA,EACb;AACA,MAAI,UAAU,SAAS,WAAW;AAChC,cAAU,UAAU;AAAA,EACtB,OAAO;AACL,cAA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AAS,KAAK,MAAM,CAAC,aAAa,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AAAA,UACjE;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACD,SAAO;AACT;AAGA,SAAS,eACP,aACA,aACA,WACA,WACA,aACA,aACA,WACA,WACA;AAIA,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,QAAM,SAAS;AAAA,IACb,GAAG;AAAA,IACH,GAAG;AAAA,IACH,SAAS;AAAA,IACT,SAAS;AAAA,EACX;AACA,iBACG,YAAY,gBAAgB,YAAY,gBACxC,YAAY,gBAAgB,YAAY;AAC3C,MAAI,gBAAgB,GAAG;AACrB,QAAI,OAAO,MAAM,QAAQ,OAAO,MAAM,MAAM;AAC1C,aAAO;AAAA,IACT,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AACA,MAAI,cAAc;AAClB,MAAI,cAAc;AAClB,gBAAc,YAAY,eAAe,KAAK,YAAY,eAAe;AACzE,gBAAc,YAAY,eAAe,KAAK,YAAY,eAAe;AACzE,MAAI,aAAa;AACjB,MAAI,aAAa;AAGjB,SAAO,IAAI,cAAc,KAAK,YAAY;AAC1C,SAAO,IAAI,cAAc,KAAK,YAAY;AAG1C,MAAI,KAAK,KAAK,KAAK,GAAG;AACpB,WAAO,UAAU;AAAA,EACnB;AAEA,MAAI,KAAK,KAAK,KAAK,GAAG;AACpB,WAAO,UAAU;AAAA,EACnB;AAEA,MAAI,OAAO,WAAW,OAAO,SAAS;AACpC,WAAO,CAAC,OAAO,GAAG,OAAO,CAAC;AAAA,EAC5B,OAAO;AACL,WAAO;AAAA,EACT;AACF;AAGA,IAAO,qBAAQ","sourcesContent":["import {\n Feature,\n FeatureCollection,\n LineString,\n MultiLineString,\n MultiPolygon,\n Point,\n Polygon,\n} from \"geojson\";\nimport { point } from \"@turf/helpers\";\n\n/**\n * Takes a {@link LineString|linestring}, {@link MultiLineString|multi-linestring},\n * {@link MultiPolygon|multi-polygon} or {@link Polygon|polygon} and\n * returns {@link Point|points} at all self-intersections.\n *\n * @name kinks\n * @param {Feature<LineString|MultiLineString|MultiPolygon|Polygon>} featureIn input feature\n * @returns {FeatureCollection<Point>} self-intersections\n * @example\n * var poly = turf.polygon([[\n * [-12.034835, 8.901183],\n * [-12.060413, 8.899826],\n * [-12.03638, 8.873199],\n * [-12.059383, 8.871418],\n * [-12.034835, 8.901183]\n * ]]);\n *\n * var kinks = turf.kinks(poly);\n *\n * //addToMap\n * var addToMap = [poly, kinks]\n */\nfunction kinks<T extends LineString | MultiLineString | Polygon | MultiPolygon>(\n featureIn: Feature<T> | T\n): FeatureCollection<Point> {\n let coordinates: any;\n let feature: any;\n const results: FeatureCollection<Point> = {\n type: \"FeatureCollection\",\n features: [],\n };\n if (featureIn.type === \"Feature\") {\n feature = featureIn.geometry;\n } else {\n feature = featureIn;\n }\n if (feature.type === \"LineString\") {\n coordinates = [feature.coordinates];\n } else if (feature.type === \"MultiLineString\") {\n coordinates = feature.coordinates;\n } else if (feature.type === \"MultiPolygon\") {\n coordinates = [].concat(...feature.coordinates);\n } else if (feature.type === \"Polygon\") {\n coordinates = feature.coordinates;\n } else {\n throw new Error(\n \"Input must be a LineString, MultiLineString, \" +\n \"Polygon, or MultiPolygon Feature or Geometry\"\n );\n }\n coordinates.forEach((line1: any) => {\n coordinates.forEach((line2: any) => {\n for (let i = 0; i < line1.length - 1; i++) {\n // start iteration at i, intersections for k < i have already\n // been checked in previous outer loop iterations\n for (let k = i; k < line2.length - 1; k++) {\n if (line1 === line2) {\n // segments are adjacent and always share a vertex, not a kink\n if (Math.abs(i - k) === 1) {\n continue;\n }\n // first and last segment in a closed lineString or ring always share a vertex, not a kink\n if (\n // segments are first and last segment of lineString\n i === 0 &&\n k === line1.length - 2 &&\n // lineString is closed\n line1[i][0] === line1[line1.length - 1][0] &&\n line1[i][1] === line1[line1.length - 1][1]\n ) {\n continue;\n }\n }\n\n const intersection: any = lineIntersects(\n line1[i][0],\n line1[i][1],\n line1[i + 1][0],\n line1[i + 1][1],\n line2[k][0],\n line2[k][1],\n line2[k + 1][0],\n line2[k + 1][1]\n );\n if (intersection) {\n results.features.push(point([intersection[0], intersection[1]]));\n }\n }\n }\n });\n });\n return results;\n}\n\n// modified from http://jsfiddle.net/justin_c_rounds/Gd2S2/light/\nfunction lineIntersects(\n line1StartX: any,\n line1StartY: any,\n line1EndX: any,\n line1EndY: any,\n line2StartX: any,\n line2StartY: any,\n line2EndX: any,\n line2EndY: any\n) {\n // if the lines intersect, the result contains the x and y of the\n // intersection (treating the lines as infinite) and booleans for whether\n // line segment 1 or line segment 2 contain the point\n let denominator;\n let a;\n let b;\n let numerator1;\n let numerator2;\n const result = {\n x: null,\n y: null,\n onLine1: false,\n onLine2: false,\n };\n denominator =\n (line2EndY - line2StartY) * (line1EndX - line1StartX) -\n (line2EndX - line2StartX) * (line1EndY - line1StartY);\n if (denominator === 0) {\n if (result.x !== null && result.y !== null) {\n return result;\n } else {\n return false;\n }\n }\n a = line1StartY - line2StartY;\n b = line1StartX - line2StartX;\n numerator1 = (line2EndX - line2StartX) * a - (line2EndY - line2StartY) * b;\n numerator2 = (line1EndX - line1StartX) * a - (line1EndY - line1StartY) * b;\n a = numerator1 / denominator;\n b = numerator2 / denominator;\n\n // if we cast these lines infinitely in both directions, they intersect here:\n result.x = line1StartX + a * (line1EndX - line1StartX);\n result.y = line1StartY + a * (line1EndY - line1StartY);\n\n // if line1 is a segment and line2 is infinite, they intersect if:\n if (a >= 0 && a <= 1) {\n result.onLine1 = true;\n }\n // if line2 is a segment and line1 is infinite, they intersect if:\n if (b >= 0 && b <= 1) {\n result.onLine2 = true;\n }\n // if line1 and line2 are segments, they intersect if both of the above are true\n if (result.onLine1 && result.onLine2) {\n return [result.x, result.y];\n } else {\n return false;\n }\n}\n\nexport { kinks };\nexport default kinks;\n"]}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -22,6 +22,6 @@ import { LineString, MultiLineString, Polygon, MultiPolygon, Feature, FeatureCol
|
|
|
22
22
|
* //addToMap
|
|
23
23
|
* var addToMap = [poly, kinks]
|
|
24
24
|
*/
|
|
25
|
-
declare function kinks<T extends LineString | MultiLineString | Polygon | MultiPolygon>(featureIn: Feature<T>): FeatureCollection<Point>;
|
|
25
|
+
declare function kinks<T extends LineString | MultiLineString | Polygon | MultiPolygon>(featureIn: Feature<T> | T): FeatureCollection<Point>;
|
|
26
26
|
|
|
27
27
|
export { kinks as default, kinks };
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -22,6 +22,6 @@ import { LineString, MultiLineString, Polygon, MultiPolygon, Feature, FeatureCol
|
|
|
22
22
|
* //addToMap
|
|
23
23
|
* var addToMap = [poly, kinks]
|
|
24
24
|
*/
|
|
25
|
-
declare function kinks<T extends LineString | MultiLineString | Polygon | MultiPolygon>(featureIn: Feature<T>): FeatureCollection<Point>;
|
|
25
|
+
declare function kinks<T extends LineString | MultiLineString | Polygon | MultiPolygon>(featureIn: Feature<T> | T): FeatureCollection<Point>;
|
|
26
26
|
|
|
27
27
|
export { kinks as default, kinks };
|
package/dist/esm/index.js
CHANGED
|
@@ -1,28 +1,105 @@
|
|
|
1
1
|
// index.ts
|
|
2
2
|
import { point } from "@turf/helpers";
|
|
3
|
-
|
|
4
|
-
// lib/sweepline-intersections-export.ts
|
|
5
|
-
import lib from "sweepline-intersections";
|
|
6
|
-
var sweeplineIntersections = lib;
|
|
7
|
-
|
|
8
|
-
// index.ts
|
|
9
3
|
function kinks(featureIn) {
|
|
4
|
+
let coordinates;
|
|
5
|
+
let feature;
|
|
10
6
|
const results = {
|
|
11
7
|
type: "FeatureCollection",
|
|
12
8
|
features: []
|
|
13
9
|
};
|
|
14
|
-
if (featureIn.type === "Feature"
|
|
10
|
+
if (featureIn.type === "Feature") {
|
|
11
|
+
feature = featureIn.geometry;
|
|
12
|
+
} else {
|
|
13
|
+
feature = featureIn;
|
|
14
|
+
}
|
|
15
|
+
if (feature.type === "LineString") {
|
|
16
|
+
coordinates = [feature.coordinates];
|
|
17
|
+
} else if (feature.type === "MultiLineString") {
|
|
18
|
+
coordinates = feature.coordinates;
|
|
19
|
+
} else if (feature.type === "MultiPolygon") {
|
|
20
|
+
coordinates = [].concat(...feature.coordinates);
|
|
21
|
+
} else if (feature.type === "Polygon") {
|
|
22
|
+
coordinates = feature.coordinates;
|
|
23
|
+
} else {
|
|
15
24
|
throw new Error(
|
|
16
25
|
"Input must be a LineString, MultiLineString, Polygon, or MultiPolygon Feature or Geometry"
|
|
17
26
|
);
|
|
18
27
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
coordinates.forEach((line1) => {
|
|
29
|
+
coordinates.forEach((line2) => {
|
|
30
|
+
for (let i = 0; i < line1.length - 1; i++) {
|
|
31
|
+
for (let k = i; k < line2.length - 1; k++) {
|
|
32
|
+
if (line1 === line2) {
|
|
33
|
+
if (Math.abs(i - k) === 1) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (
|
|
37
|
+
// segments are first and last segment of lineString
|
|
38
|
+
i === 0 && k === line1.length - 2 && // lineString is closed
|
|
39
|
+
line1[i][0] === line1[line1.length - 1][0] && line1[i][1] === line1[line1.length - 1][1]
|
|
40
|
+
) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const intersection = lineIntersects(
|
|
45
|
+
line1[i][0],
|
|
46
|
+
line1[i][1],
|
|
47
|
+
line1[i + 1][0],
|
|
48
|
+
line1[i + 1][1],
|
|
49
|
+
line2[k][0],
|
|
50
|
+
line2[k][1],
|
|
51
|
+
line2[k + 1][0],
|
|
52
|
+
line2[k + 1][1]
|
|
53
|
+
);
|
|
54
|
+
if (intersection) {
|
|
55
|
+
results.features.push(point([intersection[0], intersection[1]]));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
24
61
|
return results;
|
|
25
62
|
}
|
|
63
|
+
function lineIntersects(line1StartX, line1StartY, line1EndX, line1EndY, line2StartX, line2StartY, line2EndX, line2EndY) {
|
|
64
|
+
let denominator;
|
|
65
|
+
let a;
|
|
66
|
+
let b;
|
|
67
|
+
let numerator1;
|
|
68
|
+
let numerator2;
|
|
69
|
+
const result = {
|
|
70
|
+
x: null,
|
|
71
|
+
y: null,
|
|
72
|
+
onLine1: false,
|
|
73
|
+
onLine2: false
|
|
74
|
+
};
|
|
75
|
+
denominator = (line2EndY - line2StartY) * (line1EndX - line1StartX) - (line2EndX - line2StartX) * (line1EndY - line1StartY);
|
|
76
|
+
if (denominator === 0) {
|
|
77
|
+
if (result.x !== null && result.y !== null) {
|
|
78
|
+
return result;
|
|
79
|
+
} else {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
a = line1StartY - line2StartY;
|
|
84
|
+
b = line1StartX - line2StartX;
|
|
85
|
+
numerator1 = (line2EndX - line2StartX) * a - (line2EndY - line2StartY) * b;
|
|
86
|
+
numerator2 = (line1EndX - line1StartX) * a - (line1EndY - line1StartY) * b;
|
|
87
|
+
a = numerator1 / denominator;
|
|
88
|
+
b = numerator2 / denominator;
|
|
89
|
+
result.x = line1StartX + a * (line1EndX - line1StartX);
|
|
90
|
+
result.y = line1StartY + a * (line1EndY - line1StartY);
|
|
91
|
+
if (a >= 0 && a <= 1) {
|
|
92
|
+
result.onLine1 = true;
|
|
93
|
+
}
|
|
94
|
+
if (b >= 0 && b <= 1) {
|
|
95
|
+
result.onLine2 = true;
|
|
96
|
+
}
|
|
97
|
+
if (result.onLine1 && result.onLine2) {
|
|
98
|
+
return [result.x, result.y];
|
|
99
|
+
} else {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
26
103
|
var turf_kinks_default = kinks;
|
|
27
104
|
export {
|
|
28
105
|
turf_kinks_default as default,
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts"
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import {\n Feature,\n FeatureCollection,\n LineString,\n MultiLineString,\n MultiPolygon,\n Point,\n Polygon,\n} from \"geojson\";\nimport { point } from \"@turf/helpers\";\n\n/**\n * Takes a {@link LineString|linestring}, {@link MultiLineString|multi-linestring},\n * {@link MultiPolygon|multi-polygon} or {@link Polygon|polygon} and\n * returns {@link Point|points} at all self-intersections.\n *\n * @name kinks\n * @param {Feature<LineString|MultiLineString|MultiPolygon|Polygon>} featureIn input feature\n * @returns {FeatureCollection<Point>} self-intersections\n * @example\n * var poly = turf.polygon([[\n * [-12.034835, 8.901183],\n * [-12.060413, 8.899826],\n * [-12.03638, 8.873199],\n * [-12.059383, 8.871418],\n * [-12.034835, 8.901183]\n * ]]);\n *\n * var kinks = turf.kinks(poly);\n *\n * //addToMap\n * var addToMap = [poly, kinks]\n */\nfunction kinks<T extends LineString | MultiLineString | Polygon | MultiPolygon>(\n featureIn: Feature<T> | T\n): FeatureCollection<Point> {\n let coordinates: any;\n let feature: any;\n const results: FeatureCollection<Point> = {\n type: \"FeatureCollection\",\n features: [],\n };\n if (featureIn.type === \"Feature\") {\n feature = featureIn.geometry;\n } else {\n feature = featureIn;\n }\n if (feature.type === \"LineString\") {\n coordinates = [feature.coordinates];\n } else if (feature.type === \"MultiLineString\") {\n coordinates = feature.coordinates;\n } else if (feature.type === \"MultiPolygon\") {\n coordinates = [].concat(...feature.coordinates);\n } else if (feature.type === \"Polygon\") {\n coordinates = feature.coordinates;\n } else {\n throw new Error(\n \"Input must be a LineString, MultiLineString, \" +\n \"Polygon, or MultiPolygon Feature or Geometry\"\n );\n }\n coordinates.forEach((line1: any) => {\n coordinates.forEach((line2: any) => {\n for (let i = 0; i < line1.length - 1; i++) {\n // start iteration at i, intersections for k < i have already\n // been checked in previous outer loop iterations\n for (let k = i; k < line2.length - 1; k++) {\n if (line1 === line2) {\n // segments are adjacent and always share a vertex, not a kink\n if (Math.abs(i - k) === 1) {\n continue;\n }\n // first and last segment in a closed lineString or ring always share a vertex, not a kink\n if (\n // segments are first and last segment of lineString\n i === 0 &&\n k === line1.length - 2 &&\n // lineString is closed\n line1[i][0] === line1[line1.length - 1][0] &&\n line1[i][1] === line1[line1.length - 1][1]\n ) {\n continue;\n }\n }\n\n const intersection: any = lineIntersects(\n line1[i][0],\n line1[i][1],\n line1[i + 1][0],\n line1[i + 1][1],\n line2[k][0],\n line2[k][1],\n line2[k + 1][0],\n line2[k + 1][1]\n );\n if (intersection) {\n results.features.push(point([intersection[0], intersection[1]]));\n }\n }\n }\n });\n });\n return results;\n}\n\n// modified from http://jsfiddle.net/justin_c_rounds/Gd2S2/light/\nfunction lineIntersects(\n line1StartX: any,\n line1StartY: any,\n line1EndX: any,\n line1EndY: any,\n line2StartX: any,\n line2StartY: any,\n line2EndX: any,\n line2EndY: any\n) {\n // if the lines intersect, the result contains the x and y of the\n // intersection (treating the lines as infinite) and booleans for whether\n // line segment 1 or line segment 2 contain the point\n let denominator;\n let a;\n let b;\n let numerator1;\n let numerator2;\n const result = {\n x: null,\n y: null,\n onLine1: false,\n onLine2: false,\n };\n denominator =\n (line2EndY - line2StartY) * (line1EndX - line1StartX) -\n (line2EndX - line2StartX) * (line1EndY - line1StartY);\n if (denominator === 0) {\n if (result.x !== null && result.y !== null) {\n return result;\n } else {\n return false;\n }\n }\n a = line1StartY - line2StartY;\n b = line1StartX - line2StartX;\n numerator1 = (line2EndX - line2StartX) * a - (line2EndY - line2StartY) * b;\n numerator2 = (line1EndX - line1StartX) * a - (line1EndY - line1StartY) * b;\n a = numerator1 / denominator;\n b = numerator2 / denominator;\n\n // if we cast these lines infinitely in both directions, they intersect here:\n result.x = line1StartX + a * (line1EndX - line1StartX);\n result.y = line1StartY + a * (line1EndY - line1StartY);\n\n // if line1 is a segment and line2 is infinite, they intersect if:\n if (a >= 0 && a <= 1) {\n result.onLine1 = true;\n }\n // if line2 is a segment and line1 is infinite, they intersect if:\n if (b >= 0 && b <= 1) {\n result.onLine2 = true;\n }\n // if line1 and line2 are segments, they intersect if both of the above are true\n if (result.onLine1 && result.onLine2) {\n return [result.x, result.y];\n } else {\n return false;\n }\n}\n\nexport { kinks };\nexport default kinks;\n"],"mappings":";AASA,SAAS,aAAa;AAwBtB,SAAS,MACP,WAC0B;AAC1B,MAAI;AACJ,MAAI;AACJ,QAAM,UAAoC;AAAA,IACxC,MAAM;AAAA,IACN,UAAU,CAAC;AAAA,EACb;AACA,MAAI,UAAU,SAAS,WAAW;AAChC,cAAU,UAAU;AAAA,EACtB,OAAO;AACL,cAAU;AAAA,EACZ;AACA,MAAI,QAAQ,SAAS,cAAc;AACjC,kBAAc,CAAC,QAAQ,WAAW;AAAA,EACpC,WAAW,QAAQ,SAAS,mBAAmB;AAC7C,kBAAc,QAAQ;AAAA,EACxB,WAAW,QAAQ,SAAS,gBAAgB;AAC1C,kBAAc,CAAC,EAAE,OAAO,GAAG,QAAQ,WAAW;AAAA,EAChD,WAAW,QAAQ,SAAS,WAAW;AACrC,kBAAc,QAAQ;AAAA,EACxB,OAAO;AACL,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AACA,cAAY,QAAQ,CAAC,UAAe;AAClC,gBAAY,QAAQ,CAAC,UAAe;AAClC,eAAS,IAAI,GAAG,IAAI,MAAM,SAAS,GAAG,KAAK;AAGzC,iBAAS,IAAI,GAAG,IAAI,MAAM,SAAS,GAAG,KAAK;AACzC,cAAI,UAAU,OAAO;AAEnB,gBAAI,KAAK,IAAI,IAAI,CAAC,MAAM,GAAG;AACzB;AAAA,YACF;AAEA;AAAA;AAAA,cAEE,MAAM,KACN,MAAM,MAAM,SAAS;AAAA,cAErB,MAAM,CAAC,EAAE,CAAC,MAAM,MAAM,MAAM,SAAS,CAAC,EAAE,CAAC,KACzC,MAAM,CAAC,EAAE,CAAC,MAAM,MAAM,MAAM,SAAS,CAAC,EAAE,CAAC;AAAA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AAG;AACpB,WAAO,UAAU;AAAA,EACnB;AAEA,MAAI,KAAK,KAAK,KAAK,GAAG;AACpB,WAAO,UAAU;AAAA,EACnB;AAEA,MAAI,OAAO,WAAW,OAAO,SAAS;AACpC,WAAO,CAAC,OAAO,GAAG,OAAO,CAAC;AAAA,EAC5B,OAAO;AACL,WAAO;AAAA,EACT;AACF;AAGA,IAAO,qBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/kinks",
|
|
3
|
-
"version": "7.1.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "turf kinks module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@turf/meta": "^7.1.0
|
|
54
|
+
"@turf/meta": "^7.1.0",
|
|
55
55
|
"@types/benchmark": "^2.1.5",
|
|
56
56
|
"@types/tape": "^4.2.32",
|
|
57
57
|
"benchmark": "^2.1.4",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
"write-json-file": "^5.0.0"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@turf/helpers": "^7.1.0
|
|
68
|
-
"
|
|
67
|
+
"@turf/helpers": "^7.1.0",
|
|
68
|
+
"@types/geojson": "^7946.0.10",
|
|
69
69
|
"tslib": "^2.6.2"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "68915eeebc9278bb40dec3f1034499698a0561ef"
|
|
72
72
|
}
|