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distance } from \"@turf/distance\";\nimport { intersect } from \"@turf/intersect\";\nimport {\n Feature,\n FeatureCollection,\n GeoJsonProperties,\n Polygon,\n BBox,\n} from \"geojson\";\nimport { polygon, featureCollection, Units } from \"@turf/helpers\";\n\n/**\n * Takes a bounding box and the diameter of the cell and returns a {@link FeatureCollection} of flat-topped\n * hexagons or triangles ({@link Polygon} features) aligned in an \"odd-q\" vertical grid as\n * described in [Hexagonal Grids](http://www.redblobgames.com/grids/hexagons/).\n *\n * @function\n * @param {BBox} bbox extent in [minX, minY, maxX, maxY] order\n * @param {number} cellSide length of the side of the the hexagons or triangles, in units. It will also coincide with the\n * radius of the circumcircle of the hexagons.\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units='kilometers'] used in calculating cell size, can be degrees, radians, miles, or kilometers\n * @param {Object} [options.properties={}] passed to each hexagon or triangle of the grid\n * @param {Feature} [options.mask] if passed a Polygon or MultiPolygon, the grid Points will be created only inside it\n * @param {boolean} [options.triangles=false] whether to return as triangles instead of hexagons\n * @returns {FeatureCollection} a hexagonal grid\n * @example\n * var bbox = [-96,31,-84,40];\n * var cellSide = 50;\n * var options = {units: 'miles'};\n *\n * var hexgrid = turf.hexGrid(bbox, cellSide, options);\n *\n * //addToMap\n * var addToMap = [hexgrid];\n */\nfunction hexGrid

(\n bbox: BBox,\n cellSide: number,\n options: {\n units?: Units;\n triangles?: boolean;\n properties?: P;\n mask?: Feature;\n } = {}\n): FeatureCollection {\n // Issue => https://github.com/Turfjs/turf/issues/1284\n const clonedProperties = JSON.stringify(options.properties || {});\n\n const [west, south, east, north] = bbox;\n const centerY = (south + north) / 2;\n const centerX = (west + east) / 2;\n\n // https://github.com/Turfjs/turf/issues/758\n const xFraction =\n (cellSide * 2) / distance([west, centerY], [east, centerY], options);\n const cellWidth = xFraction * (east - west);\n const yFraction =\n (cellSide * 2) / distance([centerX, south], [centerX, north], options);\n const cellHeight = yFraction * (north - south);\n const radius = cellWidth / 2;\n\n const hex_width = radius * 2;\n const hex_height = (Math.sqrt(3) / 2) * cellHeight;\n\n const box_width = east - west;\n const box_height = north - south;\n\n const x_interval = (3 / 4) * hex_width;\n const y_interval = hex_height;\n\n // adjust box_width so all hexagons will be inside the bbox\n const x_span = (box_width - hex_width) / (hex_width - radius / 2);\n const x_count = Math.floor(x_span);\n\n const x_adjust =\n (x_count * x_interval - radius / 2 - box_width) / 2 -\n radius / 2 +\n x_interval / 2;\n\n // adjust box_height so all hexagons will be inside the bbox\n const y_count = Math.floor((box_height - hex_height) / hex_height);\n\n let y_adjust = (box_height - y_count * hex_height) / 2;\n\n const hasOffsetY = y_count * hex_height - box_height > hex_height / 2;\n if (hasOffsetY) {\n y_adjust -= hex_height / 4;\n }\n\n // Precompute cosines and sines of angles used in hexagon creation for performance gain\n const cosines = [];\n const sines = [];\n for (let i = 0; i < 6; i++) {\n const angle = ((2 * Math.PI) / 6) * i;\n cosines.push(Math.cos(angle));\n sines.push(Math.sin(angle));\n }\n\n const results = [];\n for (let x = 0; x <= x_count; x++) {\n for (let y = 0; y <= y_count; y++) {\n const isOdd = x % 2 === 1;\n if (y === 0 && isOdd) continue;\n if (y === 0 && hasOffsetY) continue;\n\n const center_x = x * x_interval + west - x_adjust;\n let center_y = y * y_interval + south + y_adjust;\n\n if (isOdd) {\n center_y -= hex_height / 2;\n }\n\n if (options.triangles === true) {\n hexTriangles(\n [center_x, center_y],\n cellWidth / 2,\n cellHeight / 2,\n JSON.parse(clonedProperties),\n cosines,\n sines\n ).forEach(function (triangle) {\n if (options.mask) {\n if (intersect(featureCollection([options.mask, triangle])))\n results.push(triangle);\n } else {\n results.push(triangle);\n }\n });\n } else {\n const hex = hexagon(\n [center_x, center_y],\n cellWidth / 2,\n cellHeight / 2,\n JSON.parse(clonedProperties),\n cosines,\n sines\n );\n if (options.mask) {\n if (intersect(featureCollection([options.mask, hex])))\n results.push(hex);\n } else {\n results.push(hex);\n }\n }\n }\n }\n\n return featureCollection(results) as FeatureCollection;\n}\n\n/**\n * Creates hexagon\n *\n * @private\n * @param {Array} center of the hexagon\n * @param {number} rx half hexagon width\n * @param {number} ry half hexagon height\n * @param {Object} properties passed to each hexagon\n * @param {Array} cosines precomputed\n * @param {Array} sines precomputed\n * @returns {Feature} hexagon\n */\nfunction hexagon(\n center: number[],\n rx: number,\n ry: number,\n properties: GeoJsonProperties,\n cosines: number[],\n sines: number[]\n) {\n const vertices = [];\n for (let i = 0; i < 6; i++) {\n const x = center[0] + rx * cosines[i];\n const y = center[1] + ry * sines[i];\n vertices.push([x, y]);\n }\n //first and last vertex must be the same\n vertices.push(vertices[0].slice());\n return polygon([vertices], properties);\n}\n\n/**\n * Creates triangles composing an hexagon\n *\n * @private\n * @param {Array} center of the hexagon\n * @param {number} rx half triangle width\n * @param {number} ry half triangle height\n * @param {Object} properties passed to each triangle\n * @param {Array} cosines precomputed\n * @param {Array} sines precomputed\n * @returns {Array>} triangles\n */\nfunction hexTriangles(\n center: number[],\n rx: number,\n ry: number,\n properties: GeoJsonProperties,\n cosines: number[],\n sines: number[]\n) {\n const triangles = [];\n for (let i = 0; i < 6; i++) {\n const vertices = [];\n vertices.push(center);\n vertices.push([center[0] + rx * cosines[i], center[1] + ry * sines[i]]);\n vertices.push([\n center[0] + rx * cosines[(i + 1) % 6],\n center[1] + ry * sines[(i + 1) % 6],\n ]);\n vertices.push(center);\n triangles.push(polygon([vertices], properties));\n }\n return triangles;\n}\n\nexport { hexGrid };\nexport default hexGrid;\n"]}