{"version":3,"sources":["../../index.ts"],"sourcesContent":["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"],"mappings":";AACA,SAAS,UAAU,eAAe;AAoClC,SAAS,WACP,OACA,UACQ;AAER,QAAM,QAAQ,SAAS,KAAK;AAC5B,QAAM,OAAO,QAAQ,QAAQ;AAC7B,QAAM,SAAS,KAAK;AACpB,QAAM,QAAQ,OAAO,CAAC;AACtB,MAAI,MAAM,SAAS;AACjB,UAAM,IAAI,MAAM,uDAAuD;AACzE,QAAM,aAAc,SAAS,SAAS,aAAa,SAAS,cAAe,CAAC;AAC5E,QAAM,IAAI,WAAW;AACrB,QAAM,IAAI,WAAW;AACrB,QAAM,IAAI,WAAW;AAGrB,QAAM,IAAI,MAAM,CAAC;AACjB,QAAM,IAAI,MAAM,CAAC;AACjB,QAAM,KAAK,MAAM,CAAC,EAAE,CAAC;AACrB,QAAM,KAAK,MAAM,CAAC,EAAE,CAAC;AACrB,QAAM,KAAK,MAAM,SAAY,IAAI,MAAM,CAAC,EAAE,CAAC;AAC3C,QAAM,KAAK,MAAM,CAAC,EAAE,CAAC;AACrB,QAAM,KAAK,MAAM,CAAC,EAAE,CAAC;AACrB,QAAM,KAAK,MAAM,SAAY,IAAI,MAAM,CAAC,EAAE,CAAC;AAC3C,QAAM,KAAK,MAAM,CAAC,EAAE,CAAC;AACrB,QAAM,KAAK,MAAM,CAAC,EAAE,CAAC;AACrB,QAAM,KAAK,MAAM,SAAY,IAAI,MAAM,CAAC,EAAE,CAAC;AAC3C,QAAM,KACH,MAAM,IAAI,OAAO,IAAI,MACpB,MAAM,IAAI,OAAO,IAAI,MACrB,MAAM,IAAI,OAAO,IAAI,MACrB,MAAM,IAAI,OAAO,IAAI,MACrB,MAAM,IAAI,OAAO,IAAI,MACrB,MAAM,IAAI,OAAO,IAAI,SACrB,IAAI,OAAO,IAAI,OACd,IAAI,OAAO,IAAI,OACf,IAAI,OAAO,IAAI,OACf,IAAI,OAAO,IAAI,OACf,IAAI,OAAO,IAAI,OACf,IAAI,OAAO,IAAI;AAEpB,SAAO;AACT;AAGA,IAAO,0BAAQ;","names":[]}