index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. // index.ts
  2. import { getCoord, getGeom } from "@turf/invariant";
  3. function planepoint(point, triangle) {
  4. const coord = getCoord(point);
  5. const geom = getGeom(triangle);
  6. const coords = geom.coordinates;
  7. const outer = coords[0];
  8. if (outer.length < 4)
  9. throw new Error("OuterRing of a Polygon must have 4 or more Positions.");
  10. const properties = triangle.type === "Feature" && triangle.properties || {};
  11. const a = properties.a;
  12. const b = properties.b;
  13. const c = properties.c;
  14. const x = coord[0];
  15. const y = coord[1];
  16. const x1 = outer[0][0];
  17. const y1 = outer[0][1];
  18. const z1 = a !== void 0 ? a : outer[0][2];
  19. const x2 = outer[1][0];
  20. const y2 = outer[1][1];
  21. const z2 = b !== void 0 ? b : outer[1][2];
  22. const x3 = outer[2][0];
  23. const y3 = outer[2][1];
  24. const z3 = c !== void 0 ? c : outer[2][2];
  25. const z = (z3 * (x - x1) * (y - y2) + z1 * (x - x2) * (y - y3) + z2 * (x - x3) * (y - y1) - z2 * (x - x1) * (y - y3) - z3 * (x - x2) * (y - y1) - z1 * (x - x3) * (y - y2)) / ((x - x1) * (y - y2) + (x - x2) * (y - y3) + (x - x3) * (y - y1) - (x - x1) * (y - y3) - (x - x2) * (y - y1) - (x - x3) * (y - y2));
  26. return z;
  27. }
  28. var turf_planepoint_default = planepoint;
  29. export {
  30. turf_planepoint_default as default,
  31. planepoint
  32. };
  33. //# sourceMappingURL=index.js.map