New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@turf/kinks

Package Overview
Dependencies
Maintainers
9
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/kinks - npm Package Compare versions

Comparing version
7.1.0-alpha.7
to
7.1.0-alpha.70
+90
-13
dist/cjs/index.cjs

@@ -1,10 +0,6 @@

"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// index.ts
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
var _helpers = require('@turf/helpers');
// lib/sweepline-intersections-export.ts
var _sweeplineintersections = require('sweepline-intersections'); var _sweeplineintersections2 = _interopRequireDefault(_sweeplineintersections);
var sweeplineIntersections = _sweeplineintersections2.default;
// 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(_helpers.point.call(void 0, [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(_helpers.point.call(void 0, [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 @@

+1
-1

@@ -1,1 +0,1 @@

{"version":3,"sources":["../../index.ts","../../lib/sweepline-intersections-export.ts"],"names":[],"mappings":";AASA,SAAS,aAAa;;;ACLtB,OAAO,SAAS;AAET,IAAM,yBAAyB;;;AD4BtC,SAAS,MACP,WAC0B;AAC1B,QAAM,UAAoC;AAAA,IACxC,MAAM;AAAA,IACN,UAAU,CAAC;AAAA,EACb;AACA,MACE,UAAU,SAAS,cACjB,UAAsB,SAAS,SAAS,WACvC,UAAsB,SAAS,SAAS,eAC3C;AACA,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AACA,QAAM,gBAAgB,uBAAkB,WAAW,KAAK;AACxD,WAAS,IAAI,GAAG,IAAI,cAAc,QAAQ,EAAE,GAAG;AAC7C,UAAM,eAAe,cAAc,CAAC;AACpC,YAAQ,SAAS,KAAK,MAAM,CAAC,aAAa,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AAAA,EACjE;AACA,SAAO;AACT;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\";\nimport { sweeplineIntersections as findIntersections } from \"./lib/sweepline-intersections-export.js\";\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>\n): FeatureCollection<Point> {\n const results: FeatureCollection<Point> = {\n type: \"FeatureCollection\",\n features: [],\n };\n if (\n featureIn.type === \"Feature\" &&\n ((featureIn as Feature).geometry.type === \"Point\" ||\n (featureIn as Feature).geometry.type === \"MultiPoint\")\n ) {\n throw new Error(\n \"Input must be a LineString, MultiLineString, \" +\n \"Polygon, or MultiPolygon Feature or Geometry\"\n );\n }\n const intersections = findIntersections(featureIn, false);\n for (let i = 0; i < intersections.length; ++i) {\n const intersection = intersections[i];\n results.features.push(point([intersection[0], intersection[1]]));\n }\n return results;\n}\n\nexport { kinks };\nexport default kinks;\n","// Get around problems with moduleResolution node16 and some older libraries.\n// Manifests as \"This expression is not callable ... has no call signatures\"\n// https://stackoverflow.com/a/74709714\n\nimport lib from \"sweepline-intersections\";\n\nexport const sweeplineIntersections = lib as unknown as typeof lib.default;\n"]}
{"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,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,M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AAI,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"]}

@@ -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 };

@@ -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 {

@@ -1,1 +0,1 @@

{"version":3,"sources":["../../index.ts","../../lib/sweepline-intersections-export.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\";\nimport { sweeplineIntersections as findIntersections } from \"./lib/sweepline-intersections-export.js\";\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>\n): FeatureCollection<Point> {\n const results: FeatureCollection<Point> = {\n type: \"FeatureCollection\",\n features: [],\n };\n if (\n featureIn.type === \"Feature\" &&\n ((featureIn as Feature).geometry.type === \"Point\" ||\n (featureIn as Feature).geometry.type === \"MultiPoint\")\n ) {\n throw new Error(\n \"Input must be a LineString, MultiLineString, \" +\n \"Polygon, or MultiPolygon Feature or Geometry\"\n );\n }\n const intersections = findIntersections(featureIn, false);\n for (let i = 0; i < intersections.length; ++i) {\n const intersection = intersections[i];\n results.features.push(point([intersection[0], intersection[1]]));\n }\n return results;\n}\n\nexport { kinks };\nexport default kinks;\n","// Get around problems with moduleResolution node16 and some older libraries.\n// Manifests as \"This expression is not callable ... has no call signatures\"\n// https://stackoverflow.com/a/74709714\n\nimport lib from \"sweepline-intersections\";\n\nexport const sweeplineIntersections = lib as unknown as typeof lib.default;\n"],"mappings":";AASA,SAAS,aAAa;;;ACLtB,OAAO,SAAS;AAET,IAAM,yBAAyB;;;AD4BtC,SAAS,MACP,WAC0B;AAC1B,QAAM,UAAoC;AAAA,IACxC,MAAM;AAAA,IACN,UAAU,CAAC;AAAA,EACb;AACA,MACE,UAAU,SAAS,cACjB,UAAsB,SAAS,SAAS,WACvC,UAAsB,SAAS,SAAS,eAC3C;AACA,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AACA,QAAM,gBAAgB,uBAAkB,WAAW,KAAK;AACxD,WAAS,IAAI,GAAG,IAAI,cAAc,QAAQ,EAAE,GAAG;AAC7C,UAAM,eAAe,cAAc,CAAC;AACpC,YAAQ,SAAS,KAAK,MAAM,CAAC,aAAa,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AAAA,EACjE;AACA,SAAO;AACT;AAGA,IAAO,qBAAQ;","names":[]}
{"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,EACx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;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;","names":[]}
{
"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 @@