Node-Red configuration
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import {Adder} from "d3-array";
  2. import {atan2, cos, quarterPi, radians, sin, tau} from "./math.js";
  3. import noop from "./noop.js";
  4. import stream from "./stream.js";
  5. export var areaRingSum = new Adder();
  6. // hello?
  7. var areaSum = new Adder(),
  8. lambda00,
  9. phi00,
  10. lambda0,
  11. cosPhi0,
  12. sinPhi0;
  13. export var areaStream = {
  14. point: noop,
  15. lineStart: noop,
  16. lineEnd: noop,
  17. polygonStart: function() {
  18. areaRingSum = new Adder();
  19. areaStream.lineStart = areaRingStart;
  20. areaStream.lineEnd = areaRingEnd;
  21. },
  22. polygonEnd: function() {
  23. var areaRing = +areaRingSum;
  24. areaSum.add(areaRing < 0 ? tau + areaRing : areaRing);
  25. this.lineStart = this.lineEnd = this.point = noop;
  26. },
  27. sphere: function() {
  28. areaSum.add(tau);
  29. }
  30. };
  31. function areaRingStart() {
  32. areaStream.point = areaPointFirst;
  33. }
  34. function areaRingEnd() {
  35. areaPoint(lambda00, phi00);
  36. }
  37. function areaPointFirst(lambda, phi) {
  38. areaStream.point = areaPoint;
  39. lambda00 = lambda, phi00 = phi;
  40. lambda *= radians, phi *= radians;
  41. lambda0 = lambda, cosPhi0 = cos(phi = phi / 2 + quarterPi), sinPhi0 = sin(phi);
  42. }
  43. function areaPoint(lambda, phi) {
  44. lambda *= radians, phi *= radians;
  45. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  46. // Spherical excess E for a spherical triangle with vertices: south pole,
  47. // previous point, current point. Uses a formula derived from Cagnoli’s
  48. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  49. var dLambda = lambda - lambda0,
  50. sdLambda = dLambda >= 0 ? 1 : -1,
  51. adLambda = sdLambda * dLambda,
  52. cosPhi = cos(phi),
  53. sinPhi = sin(phi),
  54. k = sinPhi0 * sinPhi,
  55. u = cosPhi0 * cosPhi + k * cos(adLambda),
  56. v = k * sdLambda * sin(adLambda);
  57. areaRingSum.add(atan2(v, u));
  58. // Advance the previous points.
  59. lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
  60. }
  61. export default function(object) {
  62. areaSum = new Adder();
  63. stream(object, areaStream);
  64. return areaSum * 2;
  65. }