index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // index.ts
  2. import { bearing } from "@turf/bearing";
  3. import { bearingToAzimuth, isObject } from "@turf/helpers";
  4. import { rhumbBearing } from "@turf/rhumb-bearing";
  5. function angle(startPoint, midPoint, endPoint, options = {}) {
  6. if (!isObject(options)) {
  7. throw new Error("options is invalid");
  8. }
  9. if (!startPoint) {
  10. throw new Error("startPoint is required");
  11. }
  12. if (!midPoint) {
  13. throw new Error("midPoint is required");
  14. }
  15. if (!endPoint) {
  16. throw new Error("endPoint is required");
  17. }
  18. const A = startPoint;
  19. const O = midPoint;
  20. const B = endPoint;
  21. const azimuthOA = bearingToAzimuth(
  22. options.mercator !== true ? bearing(O, A) : rhumbBearing(O, A)
  23. );
  24. let azimuthOB = bearingToAzimuth(
  25. options.mercator !== true ? bearing(O, B) : rhumbBearing(O, B)
  26. );
  27. if (azimuthOB < azimuthOA) {
  28. azimuthOB = azimuthOB + 360;
  29. }
  30. const angleAOB = azimuthOB - azimuthOA;
  31. if (options.explementary === true) {
  32. return 360 - angleAOB;
  33. }
  34. return angleAOB;
  35. }
  36. var turf_angle_default = angle;
  37. export {
  38. angle,
  39. turf_angle_default as default
  40. };
  41. //# sourceMappingURL=index.js.map