@turf/kinks
Advanced tools
Comparing version 5.1.5 to 6.0.0
@@ -1,16 +0,24 @@ | ||
import { | ||
LineString, | ||
MultiLineString, | ||
Polygon, | ||
MultiPolygon, | ||
Point, | ||
FeatureCollection, | ||
Feature | ||
} from '@turf/helpers' | ||
import { Feature, FeatureCollection, LineString, MultiLineString, MultiPolygon, Point, Polygon } from "@turf/helpers"; | ||
/** | ||
* http://turfjs.org/docs/#kinks | ||
* Takes a {@link LineString|linestring}, {@link MultiLineString|multi-linestring}, | ||
* {@link MultiPolygon|multi-polygon} or {@link Polygon|polygon} and | ||
* returns {@link Point|points} at all self-intersections. | ||
* | ||
* @name kinks | ||
* @param {Feature<LineString|MultiLineString|MultiPolygon|Polygon>} featureIn input feature | ||
* @returns {FeatureCollection<Point>} self-intersections | ||
* @example | ||
* var poly = turf.polygon([[ | ||
* [-12.034835, 8.901183], | ||
* [-12.060413, 8.899826], | ||
* [-12.03638, 8.873199], | ||
* [-12.059383, 8.871418], | ||
* [-12.034835, 8.901183] | ||
* ]]); | ||
* | ||
* var kinks = turf.kinks(poly); | ||
* | ||
* //addToMap | ||
* var addToMap = [poly, kinks] | ||
*/ | ||
export default function kinks<T extends LineString | MultiLineString | Polygon | MultiPolygon>( | ||
featureIn: Feature<T> | T | ||
): FeatureCollection<Point>; | ||
export default function kinks<T extends LineString | MultiLineString | Polygon | MultiPolygon>(featureIn: Feature<T> | T): FeatureCollection<Point>; |
87
index.js
@@ -1,5 +0,8 @@ | ||
import { point } from '@turf/helpers'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var helpers_1 = require("@turf/helpers"); | ||
/** | ||
* Takes a {@link LineString|linestring}, {@link MultiLineString|multi-linestring}, {@link MultiPolygon|multi-polygon}, or {@link Polygon|polygon} and returns {@link Point|points} at all self-intersections. | ||
* Takes a {@link LineString|linestring}, {@link MultiLineString|multi-linestring}, | ||
* {@link MultiPolygon|multi-polygon} or {@link Polygon|polygon} and | ||
* returns {@link Point|points} at all self-intersections. | ||
* | ||
@@ -27,26 +30,32 @@ * @name kinks | ||
var results = { | ||
type: 'FeatureCollection', | ||
features: [] | ||
type: "FeatureCollection", | ||
features: [], | ||
}; | ||
if (featureIn.type === 'Feature') { | ||
if (featureIn.type === "Feature") { | ||
feature = featureIn.geometry; | ||
} else { | ||
} | ||
else { | ||
feature = featureIn; | ||
} | ||
if (feature.type === 'LineString') { | ||
if (feature.type === "LineString") { | ||
coordinates = [feature.coordinates]; | ||
} else if (feature.type === 'MultiLineString') { | ||
} | ||
else if (feature.type === "MultiLineString") { | ||
coordinates = feature.coordinates; | ||
} else if (feature.type === 'MultiPolygon') { | ||
} | ||
else if (feature.type === "MultiPolygon") { | ||
coordinates = [].concat.apply([], feature.coordinates); | ||
} else if (feature.type === 'Polygon') { | ||
} | ||
else if (feature.type === "Polygon") { | ||
coordinates = feature.coordinates; | ||
} else { | ||
throw new Error('Input must be a LineString, MultiLineString, ' + | ||
'Polygon, or MultiPolygon Feature or Geometry'); | ||
} | ||
else { | ||
throw new Error("Input must be a LineString, MultiLineString, " + | ||
"Polygon, or MultiPolygon Feature or Geometry"); | ||
} | ||
coordinates.forEach(function (line1) { | ||
coordinates.forEach(function (line2) { | ||
for (var i = 0; i < line1.length - 1; i++) { | ||
// start iteration at i, intersections for k < i have already been checked in previous outer loop iterations | ||
// start iteration at i, intersections for k < i have already | ||
// been checked in previous outer loop iterations | ||
for (var k = i; k < line2.length - 1; k++) { | ||
@@ -60,17 +69,14 @@ if (line1 === line2) { | ||
if ( | ||
// segments are first and last segment of lineString | ||
i === 0 && | ||
// segments are first and last segment of lineString | ||
i === 0 && | ||
k === line1.length - 2 && | ||
// lineString is closed | ||
line1[i][0] === line1[line1.length - 1][0] && | ||
line1[i][1] === line1[line1.length - 1][1] | ||
) { | ||
line1[i][1] === line1[line1.length - 1][1]) { | ||
continue; | ||
} | ||
} | ||
var intersection = lineIntersects(line1[i][0], line1[i][1], line1[i + 1][0], line1[i + 1][1], | ||
line2[k][0], line2[k][1], line2[k + 1][0], line2[k + 1][1]); | ||
var intersection = lineIntersects(line1[i][0], line1[i][1], line1[i + 1][0], line1[i + 1][1], line2[k][0], line2[k][1], line2[k + 1][0], line2[k + 1][1]); | ||
if (intersection) { | ||
results.features.push(point([intersection[0], intersection[1]])); | ||
results.features.push(helpers_1.point([intersection[0], intersection[1]])); | ||
} | ||
@@ -83,14 +89,19 @@ } | ||
} | ||
exports.default = kinks; | ||
// modified from http://jsfiddle.net/justin_c_rounds/Gd2S2/light/ | ||
function lineIntersects(line1StartX, line1StartY, line1EndX, line1EndY, line2StartX, line2StartY, line2EndX, line2EndY) { | ||
// if the lines intersect, the result contains the x and y of the intersection (treating the lines as infinite) and booleans for whether line segment 1 or line segment 2 contain the point | ||
var denominator, a, b, numerator1, numerator2, | ||
result = { | ||
x: null, | ||
y: null, | ||
onLine1: false, | ||
onLine2: false | ||
}; | ||
// if the lines intersect, the result contains the x and y of the | ||
// intersection (treating the lines as infinite) and booleans for whether | ||
// line segment 1 or line segment 2 contain the point | ||
var denominator; | ||
var a; | ||
var b; | ||
var numerator1; | ||
var numerator2; | ||
var result = { | ||
x: null, | ||
y: null, | ||
onLine1: false, | ||
onLine2: false, | ||
}; | ||
denominator = ((line2EndY - line2StartY) * (line1EndX - line1StartX)) - ((line2EndX - line2StartX) * (line1EndY - line1StartY)); | ||
@@ -100,3 +111,4 @@ if (denominator === 0) { | ||
return result; | ||
} else { | ||
} | ||
else { | ||
return false; | ||
@@ -111,7 +123,5 @@ } | ||
b = numerator2 / denominator; | ||
// if we cast these lines infinitely in both directions, they intersect here: | ||
result.x = line1StartX + (a * (line1EndX - line1StartX)); | ||
result.y = line1StartY + (a * (line1EndY - line1StartY)); | ||
// if line1 is a segment and line2 is infinite, they intersect if: | ||
@@ -128,7 +138,6 @@ if (a >= 0 && a <= 1) { | ||
return [result.x, result.y]; | ||
} else { | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
export default kinks; |
@@ -0,19 +1,17 @@ | ||
{ | ||
"name": "@turf/kinks", | ||
"version": "5.1.5", | ||
"version": "6.0.0", | ||
"description": "turf kinks module", | ||
"main": "main.js", | ||
"module": "main.es.js", | ||
"main": "index", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"main.js", | ||
"main.es.js" | ||
"index.d.ts" | ||
], | ||
"scripts": { | ||
"pretest": "rollup -c ../../rollup.config.js", | ||
"test": "node -r @std/esm test.js", | ||
"posttest": "node -r @std/esm ../../scripts/validate-es5-dependencies.js", | ||
"bench": "node -r @std/esm bench.js", | ||
"prepare": "tsc", | ||
"pretest": "tsc", | ||
"test": "node test.js", | ||
"bench": "node bench.js", | ||
"docs": "node ../../scripts/generate-readmes" | ||
@@ -37,7 +35,6 @@ }, | ||
"devDependencies": { | ||
"@std/esm": "*", | ||
"@turf/meta": "^5.1.5", | ||
"@turf/meta": "*", | ||
"benchmark": "*", | ||
"load-json-file": "*", | ||
"rollup": "*", | ||
"typescript": "*", | ||
"tape": "*", | ||
@@ -47,8 +44,4 @@ "write-json-file": "*" | ||
"dependencies": { | ||
"@turf/helpers": "^5.1.5" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
"@turf/helpers": "6.x" | ||
} | ||
} |
@@ -7,7 +7,7 @@ # @turf/kinks | ||
Takes a [linestring](https://tools.ietf.org/html/rfc7946#section-3.1.4), [multi-linestring](https://tools.ietf.org/html/rfc7946#section-3.1.5), [multi-polygon](https://tools.ietf.org/html/rfc7946#section-3.1.7), or [polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6) and returns [points](https://tools.ietf.org/html/rfc7946#section-3.1.2) at all self-intersections. | ||
Takes a [linestring][1], [multi-linestring][2], [multi-polygon][3], or [polygon][4] and returns [points][5] at all self-intersections. | ||
**Parameters** | ||
- `featureIn` **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)<([LineString](https://tools.ietf.org/html/rfc7946#section-3.1.4) \| [MultiLineString](https://tools.ietf.org/html/rfc7946#section-3.1.5) \| [MultiPolygon](https://tools.ietf.org/html/rfc7946#section-3.1.7) \| [Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6))>** input feature | ||
- `featureIn` **[Feature][6]<([LineString][7] \| [MultiLineString][8] \| [MultiPolygon][9] \| [Polygon][10])>** input feature | ||
@@ -31,4 +31,28 @@ **Examples** | ||
Returns **[FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3)<[Point](https://tools.ietf.org/html/rfc7946#section-3.1.2)>** self-intersections | ||
Returns **[FeatureCollection][11]<[Point][12]>** self-intersections | ||
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.4 | ||
[2]: https://tools.ietf.org/html/rfc7946#section-3.1.5 | ||
[3]: https://tools.ietf.org/html/rfc7946#section-3.1.7 | ||
[4]: https://tools.ietf.org/html/rfc7946#section-3.1.6 | ||
[5]: https://tools.ietf.org/html/rfc7946#section-3.1.2 | ||
[6]: https://tools.ietf.org/html/rfc7946#section-3.2 | ||
[7]: https://tools.ietf.org/html/rfc7946#section-3.1.4 | ||
[8]: https://tools.ietf.org/html/rfc7946#section-3.1.5 | ||
[9]: https://tools.ietf.org/html/rfc7946#section-3.1.7 | ||
[10]: https://tools.ietf.org/html/rfc7946#section-3.1.6 | ||
[11]: https://tools.ietf.org/html/rfc7946#section-3.3 | ||
[12]: https://tools.ietf.org/html/rfc7946#section-3.1.2 | ||
<!-- This file is automatically generated. Please don't edit it directly: | ||
@@ -35,0 +59,0 @@ if you find an error, edit the source file (likely index.js), and re-run |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
6
80
10105
5
161
1
+ Added@turf/helpers@6.5.0(transitive)
- Removed@turf/helpers@5.1.5(transitive)
Updated@turf/helpers@6.x