Node-Red configuration
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

length.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {Adder} from "d3-array";
  2. import {abs, atan2, cos, radians, sin, sqrt} from "./math.js";
  3. import noop from "./noop.js";
  4. import stream from "./stream.js";
  5. var lengthSum,
  6. lambda0,
  7. sinPhi0,
  8. cosPhi0;
  9. var lengthStream = {
  10. sphere: noop,
  11. point: noop,
  12. lineStart: lengthLineStart,
  13. lineEnd: noop,
  14. polygonStart: noop,
  15. polygonEnd: noop
  16. };
  17. function lengthLineStart() {
  18. lengthStream.point = lengthPointFirst;
  19. lengthStream.lineEnd = lengthLineEnd;
  20. }
  21. function lengthLineEnd() {
  22. lengthStream.point = lengthStream.lineEnd = noop;
  23. }
  24. function lengthPointFirst(lambda, phi) {
  25. lambda *= radians, phi *= radians;
  26. lambda0 = lambda, sinPhi0 = sin(phi), cosPhi0 = cos(phi);
  27. lengthStream.point = lengthPoint;
  28. }
  29. function lengthPoint(lambda, phi) {
  30. lambda *= radians, phi *= radians;
  31. var sinPhi = sin(phi),
  32. cosPhi = cos(phi),
  33. delta = abs(lambda - lambda0),
  34. cosDelta = cos(delta),
  35. sinDelta = sin(delta),
  36. x = cosPhi * sinDelta,
  37. y = cosPhi0 * sinPhi - sinPhi0 * cosPhi * cosDelta,
  38. z = sinPhi0 * sinPhi + cosPhi0 * cosPhi * cosDelta;
  39. lengthSum.add(atan2(sqrt(x * x + y * y), z));
  40. lambda0 = lambda, sinPhi0 = sinPhi, cosPhi0 = cosPhi;
  41. }
  42. export default function(object) {
  43. lengthSum = new Adder();
  44. stream(object, lengthStream);
  45. return +lengthSum;
  46. }