@turf/kinks
Advanced tools
Comparing version 7.1.0-alpha.7 to 7.1.0-alpha.70
@@ -25,4 +25,4 @@ import { LineString, MultiLineString, Polygon, MultiPolygon, Feature, FeatureCollection, Point } from 'geojson'; | ||
*/ | ||
declare function kinks<T extends LineString | MultiLineString | Polygon | MultiPolygon>(featureIn: Feature<T>): FeatureCollection<Point>; | ||
declare function kinks<T extends LineString | MultiLineString | Polygon | MultiPolygon>(featureIn: Feature<T> | T): FeatureCollection<Point>; | ||
export { kinks as default, kinks }; |
// index.ts | ||
import { point } from "@turf/helpers"; | ||
// lib/sweepline-intersections-export.ts | ||
import lib from "sweepline-intersections"; | ||
var sweeplineIntersections = lib; | ||
// index.ts | ||
function kinks(featureIn) { | ||
let coordinates; | ||
let feature; | ||
const results = { | ||
@@ -14,3 +10,16 @@ type: "FeatureCollection", | ||
}; | ||
if (featureIn.type === "Feature" && (featureIn.geometry.type === "Point" || featureIn.geometry.type === "MultiPoint")) { | ||
if (featureIn.type === "Feature") { | ||
feature = featureIn.geometry; | ||
} else { | ||
feature = featureIn; | ||
} | ||
if (feature.type === "LineString") { | ||
coordinates = [feature.coordinates]; | ||
} else if (feature.type === "MultiLineString") { | ||
coordinates = feature.coordinates; | ||
} else if (feature.type === "MultiPolygon") { | ||
coordinates = [].concat(...feature.coordinates); | ||
} else if (feature.type === "Polygon") { | ||
coordinates = feature.coordinates; | ||
} else { | ||
throw new Error( | ||
@@ -20,9 +29,77 @@ "Input must be a LineString, MultiLineString, Polygon, or MultiPolygon Feature or Geometry" | ||
} | ||
const intersections = sweeplineIntersections(featureIn, false); | ||
for (let i = 0; i < intersections.length; ++i) { | ||
const intersection = intersections[i]; | ||
results.features.push(point([intersection[0], intersection[1]])); | ||
} | ||
coordinates.forEach((line1) => { | ||
coordinates.forEach((line2) => { | ||
for (let i = 0; i < line1.length - 1; i++) { | ||
for (let k = i; k < line2.length - 1; k++) { | ||
if (line1 === line2) { | ||
if (Math.abs(i - k) === 1) { | ||
continue; | ||
} | ||
if ( | ||
// 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] | ||
) { | ||
continue; | ||
} | ||
} | ||
const 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]])); | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
return results; | ||
} | ||
function lineIntersects(line1StartX, line1StartY, line1EndX, line1EndY, line2StartX, line2StartY, line2EndX, line2EndY) { | ||
let denominator; | ||
let a; | ||
let b; | ||
let numerator1; | ||
let numerator2; | ||
const result = { | ||
x: null, | ||
y: null, | ||
onLine1: false, | ||
onLine2: false | ||
}; | ||
denominator = (line2EndY - line2StartY) * (line1EndX - line1StartX) - (line2EndX - line2StartX) * (line1EndY - line1StartY); | ||
if (denominator === 0) { | ||
if (result.x !== null && result.y !== null) { | ||
return result; | ||
} else { | ||
return false; | ||
} | ||
} | ||
a = line1StartY - line2StartY; | ||
b = line1StartX - line2StartX; | ||
numerator1 = (line2EndX - line2StartX) * a - (line2EndY - line2StartY) * b; | ||
numerator2 = (line1EndX - line1StartX) * a - (line1EndY - line1StartY) * b; | ||
a = numerator1 / denominator; | ||
b = numerator2 / denominator; | ||
result.x = line1StartX + a * (line1EndX - line1StartX); | ||
result.y = line1StartY + a * (line1EndY - line1StartY); | ||
if (a >= 0 && a <= 1) { | ||
result.onLine1 = true; | ||
} | ||
if (b >= 0 && b <= 1) { | ||
result.onLine2 = true; | ||
} | ||
if (result.onLine1 && result.onLine2) { | ||
return [result.x, result.y]; | ||
} else { | ||
return false; | ||
} | ||
} | ||
var turf_kinks_default = kinks; | ||
@@ -29,0 +106,0 @@ export { |
{ | ||
"name": "@turf/kinks", | ||
"version": "7.1.0-alpha.7+0ce6ecca0", | ||
"version": "7.1.0-alpha.70+948cdafaf", | ||
"description": "turf kinks module", | ||
@@ -54,3 +54,3 @@ "author": "Turf Authors", | ||
"devDependencies": { | ||
"@turf/meta": "^7.1.0-alpha.7+0ce6ecca0", | ||
"@turf/meta": "^7.1.0-alpha.70+948cdafaf", | ||
"@types/benchmark": "^2.1.5", | ||
@@ -68,7 +68,7 @@ "@types/tape": "^4.2.32", | ||
"dependencies": { | ||
"@turf/helpers": "^7.1.0-alpha.7+0ce6ecca0", | ||
"sweepline-intersections": "^1.5.0", | ||
"@turf/helpers": "^7.1.0-alpha.70+948cdafaf", | ||
"@types/geojson": "^7946.0.10", | ||
"tslib": "^2.6.2" | ||
}, | ||
"gitHead": "0ce6ecca05829690270fec6d6bed2003495fe0ea" | ||
"gitHead": "948cdafaf70606d2e27fcc79973fa48ee1182067" | ||
} |
@@ -13,3 +13,3 @@ # @turf/kinks | ||
* `featureIn` **[Feature][6]<([LineString][7] | [MultiLineString][8] | [MultiPolygon][9] | [Polygon][10])>** input feature | ||
* `featureIn` **[Feature][6]<([LineString][1] | [MultiLineString][2] | [MultiPolygon][3] | [Polygon][4])>** input feature | ||
@@ -33,3 +33,3 @@ ### Examples | ||
Returns **[FeatureCollection][11]<[Point][12]>** self-intersections | ||
Returns **[FeatureCollection][7]<[Point][5]>** self-intersections | ||
@@ -48,14 +48,4 @@ [1]: https://tools.ietf.org/html/rfc7946#section-3.1.4 | ||
[7]: https://tools.ietf.org/html/rfc7946#section-3.1.4 | ||
[7]: https://tools.ietf.org/html/rfc7946#section-3.3 | ||
[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. 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. --> | ||
@@ -62,0 +52,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
28056
236
67
+ Added@types/geojson@^7946.0.10
- Removedsweepline-intersections@^1.5.0
- Removedsweepline-intersections@1.5.0(transitive)
- Removedtinyqueue@2.0.3(transitive)