@turf/boolean-point-in-polygon 7.0.0-alpha.2 → 7.1.0-alpha.7

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 CHANGED
@@ -52,26 +52,21 @@ Returns **[boolean][9]** `true` if the Point is inside the Polygon; `false` if t
52
52
 
53
53
  [9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
54
54
 
55
- <!-- This file is automatically generated. Please don't edit it directly:
56
- if you find an error, edit the source file (likely index.js), and re-run
57
- ./scripts/generate-readmes in the turf project. -->
55
+ <!-- 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. -->
58
56
 
59
57
  ---
60
58
 
61
- This module is part of the [Turfjs project](http://turfjs.org/), an open source
62
- module collection dedicated to geographic algorithms. It is maintained in the
63
- [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
64
- PRs and issues.
59
+ This module is part of the [Turfjs project](https://turfjs.org/), an open source module collection dedicated to geographic algorithms. It is maintained in the [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create PRs and issues.
65
60
 
66
61
  ### Installation
67
62
 
68
- Install this module individually:
63
+ Install this single module individually:
69
64
 
70
65
  ```sh
71
66
  $ npm install @turf/boolean-point-in-polygon
72
67
  ```
73
68
 
74
- Or install the Turf module that includes it as a function:
69
+ Or install the all-encompassing @turf/turf module that includes all modules as functions:
75
70
 
76
71
  ```sh
77
72
  $ npm install @turf/turf
@@ -0,0 +1,40 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// index.ts
2
+ var _pointinpolygonhao = require('point-in-polygon-hao'); var _pointinpolygonhao2 = _interopRequireDefault(_pointinpolygonhao);
3
+ var _invariant = require('@turf/invariant');
4
+ function booleanPointInPolygon(point, polygon, options = {}) {
5
+ if (!point) {
6
+ throw new Error("point is required");
7
+ }
8
+ if (!polygon) {
9
+ throw new Error("polygon is required");
10
+ }
11
+ const pt = _invariant.getCoord.call(void 0, point);
12
+ const geom = _invariant.getGeom.call(void 0, polygon);
13
+ const type = geom.type;
14
+ const bbox = polygon.bbox;
15
+ let polys = geom.coordinates;
16
+ if (bbox && inBBox(pt, bbox) === false) {
17
+ return false;
18
+ }
19
+ if (type === "Polygon") {
20
+ polys = [polys];
21
+ }
22
+ let result = false;
23
+ for (var i = 0; i < polys.length; ++i) {
24
+ const polyResult = _pointinpolygonhao2.default.call(void 0, pt, polys[i]);
25
+ if (polyResult === 0)
26
+ return options.ignoreBoundary ? false : true;
27
+ else if (polyResult)
28
+ result = true;
29
+ }
30
+ return result;
31
+ }
32
+ function inBBox(pt, bbox) {
33
+ return bbox[0] <= pt[0] && bbox[1] <= pt[1] && bbox[2] >= pt[0] && bbox[3] >= pt[1];
34
+ }
35
+ var turf_boolean_point_in_polygon_default = booleanPointInPolygon;
36
+
37
+
38
+
39
+ exports.booleanPointInPolygon = booleanPointInPolygon; exports.default = turf_boolean_point_in_polygon_default;
40
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AAAA,OAAO,SAAS;AAShB,SAAS,UAAU,eAAe;AA6BlC,SAAS,sBAIP,OACA,SACA,UAEI,CAAC,GACL;AAEA,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,mBAAmB;AAAA,EACrC;AACA,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACvC;AAEA,QAAM,KAAK,SAAS,KAAK;AACzB,QAAM,OAAO,QAAQ,OAAO;AAC5B,QAAM,OAAO,KAAK;AAClB,QAAM,OAAO,QAAQ;AACrB,MAAI,QAAe,KAAK;AAGxB,MAAI,QAAQ,OAAO,IAAI,IAAI,MAAM,OAAO;AACtC,WAAO;AAAA,EACT;AAEA,MAAI,SAAS,WAAW;AACtB,YAAQ,CAAC,KAAK;AAAA,EAChB;AACA,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,EAAE,GAAG;AACrC,UAAM,aAAa,IAAI,IAAI,MAAM,CAAC,CAAC;AACnC,QAAI,eAAe;AAAG,aAAO,QAAQ,iBAAiB,QAAQ;AAAA,aACrD;AAAY,eAAS;AAAA,EAChC;AAEA,SAAO;AACT;AAUA,SAAS,OAAO,IAAc,MAAY;AACxC,SACE,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,GAAG,CAAC;AAE/E;AAGA,IAAO,wCAAQ","sourcesContent":["import pip from \"point-in-polygon-hao\";\nimport {\n BBox,\n Feature,\n MultiPolygon,\n Polygon,\n GeoJsonProperties,\n} from \"geojson\";\nimport { Coord } from \"@turf/helpers\";\nimport { getCoord, getGeom } from \"@turf/invariant\";\n\n// http://en.wikipedia.org/wiki/Even%E2%80%93odd_rule\n// modified from: https://github.com/substack/point-in-polygon/blob/master/index.js\n// which was modified from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html\n/**\n * Takes a {@link Point} and a {@link Polygon} or {@link MultiPolygon} and determines if the point\n * resides inside the polygon. The polygon can be convex or concave. The function accounts for holes.\n *\n * @name booleanPointInPolygon\n * @param {Coord} point input point\n * @param {Feature<Polygon|MultiPolygon>} polygon input polygon or multipolygon\n * @param {Object} [options={}] Optional parameters\n * @param {boolean} [options.ignoreBoundary=false] True if polygon boundary should be ignored when determining if\n * the point is inside the polygon otherwise false.\n * @returns {boolean} `true` if the Point is inside the Polygon; `false` if the Point is not inside the Polygon\n * @example\n * var pt = turf.point([-77, 44]);\n * var poly = turf.polygon([[\n * [-81, 41],\n * [-81, 47],\n * [-72, 47],\n * [-72, 41],\n * [-81, 41]\n * ]]);\n *\n * turf.booleanPointInPolygon(pt, poly);\n * //= true\n */\nfunction booleanPointInPolygon<\n G extends Polygon | MultiPolygon,\n P extends GeoJsonProperties = GeoJsonProperties,\n>(\n point: Coord,\n polygon: Feature<G, P> | G,\n options: {\n ignoreBoundary?: boolean;\n } = {}\n) {\n // validation\n if (!point) {\n throw new Error(\"point is required\");\n }\n if (!polygon) {\n throw new Error(\"polygon is required\");\n }\n\n const pt = getCoord(point);\n const geom = getGeom(polygon);\n const type = geom.type;\n const bbox = polygon.bbox;\n let polys: any[] = geom.coordinates;\n\n // Quick elimination if point is not inside bbox\n if (bbox && inBBox(pt, bbox) === false) {\n return false;\n }\n\n if (type === \"Polygon\") {\n polys = [polys];\n }\n let result = false;\n for (var i = 0; i < polys.length; ++i) {\n const polyResult = pip(pt, polys[i]);\n if (polyResult === 0) return options.ignoreBoundary ? false : true;\n else if (polyResult) result = true;\n }\n\n return result;\n}\n\n/**\n * inBBox\n *\n * @private\n * @param {Position} pt point [x,y]\n * @param {BBox} bbox BBox [west, south, east, north]\n * @returns {boolean} true/false if point is inside BBox\n */\nfunction inBBox(pt: number[], bbox: BBox) {\n return (\n bbox[0] <= pt[0] && bbox[1] <= pt[1] && bbox[2] >= pt[0] && bbox[3] >= pt[1]\n );\n}\n\nexport { booleanPointInPolygon };\nexport default booleanPointInPolygon;\n"]}
@@ -0,0 +1,32 @@
1
+ import { Polygon, MultiPolygon, GeoJsonProperties, Feature } from 'geojson';
2
+ import { Coord } from '@turf/helpers';
3
+
4
+ /**
5
+ * Takes a {@link Point} and a {@link Polygon} or {@link MultiPolygon} and determines if the point
6
+ * resides inside the polygon. The polygon can be convex or concave. The function accounts for holes.
7
+ *
8
+ * @name booleanPointInPolygon
9
+ * @param {Coord} point input point
10
+ * @param {Feature<Polygon|MultiPolygon>} polygon input polygon or multipolygon
11
+ * @param {Object} [options={}] Optional parameters
12
+ * @param {boolean} [options.ignoreBoundary=false] True if polygon boundary should be ignored when determining if
13
+ * the point is inside the polygon otherwise false.
14
+ * @returns {boolean} `true` if the Point is inside the Polygon; `false` if the Point is not inside the Polygon
15
+ * @example
16
+ * var pt = turf.point([-77, 44]);
17
+ * var poly = turf.polygon([[
18
+ * [-81, 41],
19
+ * [-81, 47],
20
+ * [-72, 47],
21
+ * [-72, 41],
22
+ * [-81, 41]
23
+ * ]]);
24
+ *
25
+ * turf.booleanPointInPolygon(pt, poly);
26
+ * //= true
27
+ */
28
+ declare function booleanPointInPolygon<G extends Polygon | MultiPolygon, P extends GeoJsonProperties = GeoJsonProperties>(point: Coord, polygon: Feature<G, P> | G, options?: {
29
+ ignoreBoundary?: boolean;
30
+ }): boolean;
31
+
32
+ export { booleanPointInPolygon, booleanPointInPolygon as default };
@@ -1,5 +1,6 @@
1
- import { Feature, MultiPolygon, Polygon, GeoJsonProperties } from "geojson";
2
- import { Coord } from "@turf/helpers";
1
+ import { Polygon, MultiPolygon, GeoJsonProperties, Feature } from 'geojson';
2
+ import { Coord } from '@turf/helpers';
3
+
3
4
  /**
4
5
  * Takes a {@link Point} and a {@link Polygon} or {@link MultiPolygon} and determines if the point
5
6
  * resides inside the polygon. The polygon can be convex or concave. The function accounts for holes.
@@ -24,6 +25,8 @@ import { Coord } from "@turf/helpers";
24
25
  * turf.booleanPointInPolygon(pt, poly);
25
26
  * //= true
26
27
  */
27
- export default function booleanPointInPolygon<G extends Polygon | MultiPolygon, P = GeoJsonProperties>(point: Coord, polygon: Feature<G, P> | G, options?: {
28
+ declare function booleanPointInPolygon<G extends Polygon | MultiPolygon, P extends GeoJsonProperties = GeoJsonProperties>(point: Coord, polygon: Feature<G, P> | G, options?: {
28
29
  ignoreBoundary?: boolean;
29
30
  }): boolean;
31
+
32
+ export { booleanPointInPolygon, booleanPointInPolygon as default };
@@ -0,0 +1,40 @@
1
+ // index.ts
2
+ import pip from "point-in-polygon-hao";
3
+ import { getCoord, getGeom } from "@turf/invariant";
4
+ function booleanPointInPolygon(point, polygon, options = {}) {
5
+ if (!point) {
6
+ throw new Error("point is required");
7
+ }
8
+ if (!polygon) {
9
+ throw new Error("polygon is required");
10
+ }
11
+ const pt = getCoord(point);
12
+ const geom = getGeom(polygon);
13
+ const type = geom.type;
14
+ const bbox = polygon.bbox;
15
+ let polys = geom.coordinates;
16
+ if (bbox && inBBox(pt, bbox) === false) {
17
+ return false;
18
+ }
19
+ if (type === "Polygon") {
20
+ polys = [polys];
21
+ }
22
+ let result = false;
23
+ for (var i = 0; i < polys.length; ++i) {
24
+ const polyResult = pip(pt, polys[i]);
25
+ if (polyResult === 0)
26
+ return options.ignoreBoundary ? false : true;
27
+ else if (polyResult)
28
+ result = true;
29
+ }
30
+ return result;
31
+ }
32
+ function inBBox(pt, bbox) {
33
+ return bbox[0] <= pt[0] && bbox[1] <= pt[1] && bbox[2] >= pt[0] && bbox[3] >= pt[1];
34
+ }
35
+ var turf_boolean_point_in_polygon_default = booleanPointInPolygon;
36
+ export {
37
+ booleanPointInPolygon,
38
+ turf_boolean_point_in_polygon_default as default
39
+ };
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import pip from \"point-in-polygon-hao\";\nimport {\n BBox,\n Feature,\n MultiPolygon,\n Polygon,\n GeoJsonProperties,\n} from \"geojson\";\nimport { Coord } from \"@turf/helpers\";\nimport { getCoord, getGeom } from \"@turf/invariant\";\n\n// http://en.wikipedia.org/wiki/Even%E2%80%93odd_rule\n// modified from: https://github.com/substack/point-in-polygon/blob/master/index.js\n// which was modified from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html\n/**\n * Takes a {@link Point} and a {@link Polygon} or {@link MultiPolygon} and determines if the point\n * resides inside the polygon. The polygon can be convex or concave. The function accounts for holes.\n *\n * @name booleanPointInPolygon\n * @param {Coord} point input point\n * @param {Feature<Polygon|MultiPolygon>} polygon input polygon or multipolygon\n * @param {Object} [options={}] Optional parameters\n * @param {boolean} [options.ignoreBoundary=false] True if polygon boundary should be ignored when determining if\n * the point is inside the polygon otherwise false.\n * @returns {boolean} `true` if the Point is inside the Polygon; `false` if the Point is not inside the Polygon\n * @example\n * var pt = turf.point([-77, 44]);\n * var poly = turf.polygon([[\n * [-81, 41],\n * [-81, 47],\n * [-72, 47],\n * [-72, 41],\n * [-81, 41]\n * ]]);\n *\n * turf.booleanPointInPolygon(pt, poly);\n * //= true\n */\nfunction booleanPointInPolygon<\n G extends Polygon | MultiPolygon,\n P extends GeoJsonProperties = GeoJsonProperties,\n>(\n point: Coord,\n polygon: Feature<G, P> | G,\n options: {\n ignoreBoundary?: boolean;\n } = {}\n) {\n // validation\n if (!point) {\n throw new Error(\"point is required\");\n }\n if (!polygon) {\n throw new Error(\"polygon is required\");\n }\n\n const pt = getCoord(point);\n const geom = getGeom(polygon);\n const type = geom.type;\n const bbox = polygon.bbox;\n let polys: any[] = geom.coordinates;\n\n // Quick elimination if point is not inside bbox\n if (bbox && inBBox(pt, bbox) === false) {\n return false;\n }\n\n if (type === \"Polygon\") {\n polys = [polys];\n }\n let result = false;\n for (var i = 0; i < polys.length; ++i) {\n const polyResult = pip(pt, polys[i]);\n if (polyResult === 0) return options.ignoreBoundary ? false : true;\n else if (polyResult) result = true;\n }\n\n return result;\n}\n\n/**\n * inBBox\n *\n * @private\n * @param {Position} pt point [x,y]\n * @param {BBox} bbox BBox [west, south, east, north]\n * @returns {boolean} true/false if point is inside BBox\n */\nfunction inBBox(pt: number[], bbox: BBox) {\n return (\n bbox[0] <= pt[0] && bbox[1] <= pt[1] && bbox[2] >= pt[0] && bbox[3] >= pt[1]\n );\n}\n\nexport { booleanPointInPolygon };\nexport default booleanPointInPolygon;\n"],"mappings":";AAAA,OAAO,SAAS;AAShB,SAAS,UAAU,eAAe;AA6BlC,SAAS,sBAIP,OACA,SACA,UAEI,CAAC,GACL;AAEA,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,mBAAmB;AAAA,EACrC;AACA,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACvC;AAEA,QAAM,KAAK,SAAS,KAAK;AACzB,QAAM,OAAO,QAAQ,OAAO;AAC5B,QAAM,OAAO,KAAK;AAClB,QAAM,OAAO,QAAQ;AACrB,MAAI,QAAe,KAAK;AAGxB,MAAI,QAAQ,OAAO,IAAI,IAAI,MAAM,OAAO;AACtC,WAAO;AAAA,EACT;AAEA,MAAI,SAAS,WAAW;AACtB,YAAQ,CAAC,KAAK;AAAA,EAChB;AACA,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,EAAE,GAAG;AACrC,UAAM,aAAa,IAAI,IAAI,MAAM,CAAC,CAAC;AACnC,QAAI,eAAe;AAAG,aAAO,QAAQ,iBAAiB,QAAQ;AAAA,aACrD;AAAY,eAAS;AAAA,EAChC;AAEA,SAAO;AACT;AAUA,SAAS,OAAO,IAAc,MAAY;AACxC,SACE,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,GAAG,CAAC;AAE/E;AAGA,IAAO,wCAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/boolean-point-in-polygon",
3
- "version": "7.0.0-alpha.2",
3
+ "version": "7.1.0-alpha.7+0ce6ecca0",
4
4
  "description": "turf boolean-point-in-polygon module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -24,44 +24,49 @@
24
24
  "bin",
25
25
  "gis"
26
26
  ],
27
- "main": "dist/js/index.js",
28
- "module": "dist/es/index.js",
27
+ "type": "module",
28
+ "main": "dist/cjs/index.cjs",
29
+ "module": "dist/esm/index.js",
30
+ "types": "dist/esm/index.d.ts",
29
31
  "exports": {
30
32
  "./package.json": "./package.json",
31
33
  ".": {
32
- "types": "./dist/js/index.d.ts",
33
- "import": "./dist/es/index.js",
34
- "require": "./dist/js/index.js"
34
+ "import": {
35
+ "types": "./dist/esm/index.d.ts",
36
+ "default": "./dist/esm/index.js"
37
+ },
38
+ "require": {
39
+ "types": "./dist/cjs/index.d.cts",
40
+ "default": "./dist/cjs/index.cjs"
41
+ }
35
42
  }
36
43
  },
37
- "types": "dist/js/index.d.ts",
38
44
  "sideEffects": false,
39
45
  "files": [
40
46
  "dist"
41
47
  ],
42
48
  "scripts": {
43
- "bench": "tsx bench.js",
44
- "build": "npm-run-all build:*",
45
- "build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
46
- "build:js": "tsc",
47
- "docs": "tsx ../../scripts/generate-readmes",
48
- "test": "npm-run-all test:*",
49
- "test:tape": "tsx test.js"
49
+ "bench": "tsx bench.ts",
50
+ "build": "tsup --config ../../tsup.config.ts",
51
+ "docs": "tsx ../../scripts/generate-readmes.ts",
52
+ "test": "npm-run-all --npm-path npm test:*",
53
+ "test:tape": "tsx test.ts"
50
54
  },
51
55
  "devDependencies": {
52
- "@types/tape": "*",
53
- "benchmark": "*",
54
- "npm-run-all": "*",
55
- "tape": "*",
56
- "tslint": "*",
57
- "tsx": "*",
58
- "typescript": "*"
56
+ "@types/benchmark": "^2.1.5",
57
+ "@types/tape": "^4.2.32",
58
+ "benchmark": "^2.1.4",
59
+ "npm-run-all": "^4.1.5",
60
+ "tape": "^5.7.2",
61
+ "tsup": "^8.0.1",
62
+ "tsx": "^4.6.2",
63
+ "typescript": "^5.2.2"
59
64
  },
60
65
  "dependencies": {
61
- "@turf/helpers": "^7.0.0-alpha.2",
62
- "@turf/invariant": "^7.0.0-alpha.2",
66
+ "@turf/helpers": "^7.1.0-alpha.7+0ce6ecca0",
67
+ "@turf/invariant": "^7.1.0-alpha.7+0ce6ecca0",
63
68
  "point-in-polygon-hao": "^1.1.0",
64
- "tslib": "^2.3.0"
69
+ "tslib": "^2.6.2"
65
70
  },
66
- "gitHead": "dd35b52725945b4fa29a98d9a550733e06cc222e"
71
+ "gitHead": "0ce6ecca05829690270fec6d6bed2003495fe0ea"
67
72
  }
package/dist/es/index.js DELETED
@@ -1,70 +0,0 @@
1
- import pip from "point-in-polygon-hao";
2
- import { getCoord, getGeom } from "@turf/invariant";
3
- // http://en.wikipedia.org/wiki/Even%E2%80%93odd_rule
4
- // modified from: https://github.com/substack/point-in-polygon/blob/master/index.js
5
- // which was modified from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
6
- /**
7
- * Takes a {@link Point} and a {@link Polygon} or {@link MultiPolygon} and determines if the point
8
- * resides inside the polygon. The polygon can be convex or concave. The function accounts for holes.
9
- *
10
- * @name booleanPointInPolygon
11
- * @param {Coord} point input point
12
- * @param {Feature<Polygon|MultiPolygon>} polygon input polygon or multipolygon
13
- * @param {Object} [options={}] Optional parameters
14
- * @param {boolean} [options.ignoreBoundary=false] True if polygon boundary should be ignored when determining if
15
- * the point is inside the polygon otherwise false.
16
- * @returns {boolean} `true` if the Point is inside the Polygon; `false` if the Point is not inside the Polygon
17
- * @example
18
- * var pt = turf.point([-77, 44]);
19
- * var poly = turf.polygon([[
20
- * [-81, 41],
21
- * [-81, 47],
22
- * [-72, 47],
23
- * [-72, 41],
24
- * [-81, 41]
25
- * ]]);
26
- *
27
- * turf.booleanPointInPolygon(pt, poly);
28
- * //= true
29
- */
30
- export default function booleanPointInPolygon(point, polygon, options = {}) {
31
- // validation
32
- if (!point) {
33
- throw new Error("point is required");
34
- }
35
- if (!polygon) {
36
- throw new Error("polygon is required");
37
- }
38
- const pt = getCoord(point);
39
- const geom = getGeom(polygon);
40
- const type = geom.type;
41
- const bbox = polygon.bbox;
42
- let polys = geom.coordinates;
43
- // Quick elimination if point is not inside bbox
44
- if (bbox && inBBox(pt, bbox) === false) {
45
- return false;
46
- }
47
- if (type === "Polygon") {
48
- polys = [polys];
49
- }
50
- let result = false;
51
- for (var i = 0; i < polys.length; ++i) {
52
- const polyResult = pip(pt, polys[i]);
53
- if (polyResult === 0)
54
- return options.ignoreBoundary ? false : true;
55
- else if (polyResult)
56
- result = true;
57
- }
58
- return result;
59
- }
60
- /**
61
- * inBBox
62
- *
63
- * @private
64
- * @param {Position} pt point [x,y]
65
- * @param {BBox} bbox BBox [west, south, east, north]
66
- * @returns {boolean} true/false if point is inside BBox
67
- */
68
- function inBBox(pt, bbox) {
69
- return (bbox[0] <= pt[0] && bbox[1] <= pt[1] && bbox[2] >= pt[0] && bbox[3] >= pt[1]);
70
- }
@@ -1 +0,0 @@
1
- {"type":"module"}
package/dist/js/index.js DELETED
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const point_in_polygon_hao_1 = tslib_1.__importDefault(require("point-in-polygon-hao"));
5
- const invariant_1 = require("@turf/invariant");
6
- // http://en.wikipedia.org/wiki/Even%E2%80%93odd_rule
7
- // modified from: https://github.com/substack/point-in-polygon/blob/master/index.js
8
- // which was modified from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
9
- /**
10
- * Takes a {@link Point} and a {@link Polygon} or {@link MultiPolygon} and determines if the point
11
- * resides inside the polygon. The polygon can be convex or concave. The function accounts for holes.
12
- *
13
- * @name booleanPointInPolygon
14
- * @param {Coord} point input point
15
- * @param {Feature<Polygon|MultiPolygon>} polygon input polygon or multipolygon
16
- * @param {Object} [options={}] Optional parameters
17
- * @param {boolean} [options.ignoreBoundary=false] True if polygon boundary should be ignored when determining if
18
- * the point is inside the polygon otherwise false.
19
- * @returns {boolean} `true` if the Point is inside the Polygon; `false` if the Point is not inside the Polygon
20
- * @example
21
- * var pt = turf.point([-77, 44]);
22
- * var poly = turf.polygon([[
23
- * [-81, 41],
24
- * [-81, 47],
25
- * [-72, 47],
26
- * [-72, 41],
27
- * [-81, 41]
28
- * ]]);
29
- *
30
- * turf.booleanPointInPolygon(pt, poly);
31
- * //= true
32
- */
33
- function booleanPointInPolygon(point, polygon, options = {}) {
34
- // validation
35
- if (!point) {
36
- throw new Error("point is required");
37
- }
38
- if (!polygon) {
39
- throw new Error("polygon is required");
40
- }
41
- const pt = invariant_1.getCoord(point);
42
- const geom = invariant_1.getGeom(polygon);
43
- const type = geom.type;
44
- const bbox = polygon.bbox;
45
- let polys = geom.coordinates;
46
- // Quick elimination if point is not inside bbox
47
- if (bbox && inBBox(pt, bbox) === false) {
48
- return false;
49
- }
50
- if (type === "Polygon") {
51
- polys = [polys];
52
- }
53
- let result = false;
54
- for (var i = 0; i < polys.length; ++i) {
55
- const polyResult = point_in_polygon_hao_1.default(pt, polys[i]);
56
- if (polyResult === 0)
57
- return options.ignoreBoundary ? false : true;
58
- else if (polyResult)
59
- result = true;
60
- }
61
- return result;
62
- }
63
- exports.default = booleanPointInPolygon;
64
- /**
65
- * inBBox
66
- *
67
- * @private
68
- * @param {Position} pt point [x,y]
69
- * @param {BBox} bbox BBox [west, south, east, north]
70
- * @returns {boolean} true/false if point is inside BBox
71
- */
72
- function inBBox(pt, bbox) {
73
- return (bbox[0] <= pt[0] && bbox[1] <= pt[1] && bbox[2] >= pt[0] && bbox[3] >= pt[1]);
74
- }