diagram.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.intersectionAreaPath = void 0;
  4. const circleintersection_1 = require("./circleintersection");
  5. /**
  6. * 根据圆心(x, y) 半径 r 返回圆的绘制 path
  7. * @param x 圆心点 x
  8. * @param y 圆心点 y
  9. * @param r 圆的半径
  10. * @returns 圆的 path
  11. */
  12. function circlePath(x, y, r) {
  13. const ret = [];
  14. // ret.push('\nM', x, y);
  15. // ret.push('\nm', -r, 0);
  16. // ret.push('\na', r, r, 0, 1, 0, r * 2, 0);
  17. // ret.push('\na', r, r, 0, 1, 0, -r * 2, 0);
  18. const x0 = x - r;
  19. const y0 = y;
  20. ret.push('M', x0, y0);
  21. ret.push('A', r, r, 0, 1, 0, x0 + 2 * r, y0);
  22. ret.push('A', r, r, 0, 1, 0, x0, y0);
  23. return ret.join(' ');
  24. }
  25. /** returns a svg path of the intersection area of a bunch of circles */
  26. function intersectionAreaPath(circles) {
  27. const stats = {};
  28. (0, circleintersection_1.intersectionArea)(circles, stats);
  29. const arcs = stats.arcs;
  30. if (arcs.length === 0) {
  31. return 'M 0 0';
  32. }
  33. else if (arcs.length == 1) {
  34. const circle = arcs[0].circle;
  35. return circlePath(circle.x, circle.y, circle.radius);
  36. }
  37. else {
  38. // draw path around arcs
  39. const ret = ['\nM', arcs[0].p2.x, arcs[0].p2.y];
  40. for (let i = 0; i < arcs.length; ++i) {
  41. const arc = arcs[i], r = arc.circle.radius, wide = arc.width > r;
  42. ret.push('\nA', r, r, 0, wide ? 1 : 0, 1, arc.p1.x, arc.p1.y);
  43. }
  44. return ret.join(' ');
  45. }
  46. }
  47. exports.intersectionAreaPath = intersectionAreaPath;
  48. //# sourceMappingURL=diagram.js.map