index.cjs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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) return options.ignoreBoundary ? false : true;
  26. else if (polyResult) result = true;
  27. }
  28. return result;
  29. }
  30. function inBBox(pt, bbox) {
  31. return bbox[0] <= pt[0] && bbox[1] <= pt[1] && bbox[2] >= pt[0] && bbox[3] >= pt[1];
  32. }
  33. var turf_boolean_point_in_polygon_default = booleanPointInPolygon;
  34. exports.booleanPointInPolygon = booleanPointInPolygon; exports.default = turf_boolean_point_in_polygon_default;
  35. //# sourceMappingURL=index.cjs.map