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AAA,CAAO,EAAA,EAAI,EAAA,EAAA,EAAA,CACf,EAAA,EAAI,EAAA,EAAA,EAAA,CAAO,EAAA,EAAI,EAAA,CAAA,CAAA;AAEpB,EAAA,OAAO,CAAA;AACT;AAGA,IAAO,wBAAA,EAAQ,UAAA;ADvDf;AACE;AACA;AACF,2EAAC","file":"/home/runner/work/turf/turf/packages/turf-planepoint/dist/cjs/index.cjs","sourcesContent":[null,"import { Feature, Polygon } from \"geojson\";\nimport { getCoord, getGeom } from \"@turf/invariant\";\nimport { Coord } from \"@turf/helpers\";\n\n/**\n * Takes a triangular plane as a polygon and a point within that triangle, and\n * returns the z-value at that point.\n *\n * The Polygon should have properties `a`, `b`, and `c`\n * that define the values at its three corners. Alternatively, the z-values\n * of each triangle point can be provided by their respective 3rd coordinate\n * if their values are not provided as properties.\n *\n * @function\n * @param {Coord} point the Point for which a z-value will be calculated\n * @param {Feature} triangle a Polygon feature with three vertices\n * @returns {number} the z-value for `interpolatedPoint`\n * @example\n * const point = turf.point([-75.3221, 39.529]);\n * // \"a\", \"b\", and \"c\" values represent the values of the coordinates in order.\n * const triangle = turf.polygon([[\n * [-75.1221, 39.57],\n * [-75.58, 39.18],\n * [-75.97, 39.86],\n * [-75.1221, 39.57]\n * ]], {\n * \"a\": 11,\n * \"b\": 122,\n * \"c\": 44\n * });\n *\n * const zValue = turf.planepoint(point, triangle);\n * point.properties.zValue = zValue;\n *\n * //addToMap\n * const addToMap = [triangle, point];\n */\nfunction planepoint(\n point: Coord,\n triangle: Feature | Polygon\n): number {\n // Normalize input\n const coord = getCoord(point);\n const geom = getGeom(triangle);\n const coords = geom.coordinates;\n const outer = coords[0];\n if (outer.length < 4)\n throw new Error(\"OuterRing of a Polygon must have 4 or more Positions.\");\n const properties = (triangle.type === \"Feature\" && triangle.properties) || {};\n const a = properties.a;\n const b = properties.b;\n const c = properties.c;\n\n // Planepoint\n const x = coord[0];\n const y = coord[1];\n const x1 = outer[0][0];\n const y1 = outer[0][1];\n const z1 = a !== undefined ? a : outer[0][2];\n const x2 = outer[1][0];\n const y2 = outer[1][1];\n const z2 = b !== undefined ? b : outer[1][2];\n const x3 = outer[2][0];\n const y3 = outer[2][1];\n const z3 = c !== undefined ? c : outer[2][2];\n const z =\n (z3 * (x - x1) * (y - y2) +\n z1 * (x - x2) * (y - y3) +\n z2 * (x - x3) * (y - y1) -\n z2 * (x - x1) * (y - y3) -\n z3 * (x - x2) * (y - y1) -\n z1 * (x - x3) * (y - y2)) /\n ((x - x1) * (y - y2) +\n (x - x2) * (y - y3) +\n (x - x3) * (y - y1) -\n (x - x1) * (y - y3) -\n (x - x2) * (y - y1) -\n (x - x3) * (y - y2));\n\n return z;\n}\n\nexport { planepoint };\nexport default planepoint;\n"]}