rounded.js 1.7 KB

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.rounded = void 0;
  4. const x6_geometry_1 = require("@antv/x6-geometry");
  5. const rounded = function (sourcePoint, targetPoint, routePoints, options = {}) {
  6. const path = new x6_geometry_1.Path();
  7. path.appendSegment(x6_geometry_1.Path.createSegment('M', sourcePoint));
  8. const f13 = 1 / 3;
  9. const f23 = 2 / 3;
  10. const radius = options.radius || 10;
  11. let prevDistance;
  12. let nextDistance;
  13. for (let i = 0, ii = routePoints.length; i < ii; i += 1) {
  14. const curr = x6_geometry_1.Point.create(routePoints[i]);
  15. const prev = routePoints[i - 1] || sourcePoint;
  16. const next = routePoints[i + 1] || targetPoint;
  17. prevDistance = nextDistance || curr.distance(prev) / 2;
  18. nextDistance = curr.distance(next) / 2;
  19. const startMove = -Math.min(radius, prevDistance);
  20. const endMove = -Math.min(radius, nextDistance);
  21. const roundedStart = curr.clone().move(prev, startMove).round();
  22. const roundedEnd = curr.clone().move(next, endMove).round();
  23. const control1 = new x6_geometry_1.Point(f13 * roundedStart.x + f23 * curr.x, f23 * curr.y + f13 * roundedStart.y);
  24. const control2 = new x6_geometry_1.Point(f13 * roundedEnd.x + f23 * curr.x, f23 * curr.y + f13 * roundedEnd.y);
  25. path.appendSegment(x6_geometry_1.Path.createSegment('L', roundedStart));
  26. path.appendSegment(x6_geometry_1.Path.createSegment('C', control1, control2, roundedEnd));
  27. }
  28. path.appendSegment(x6_geometry_1.Path.createSegment('L', targetPoint));
  29. return options.raw ? path : path.serialize();
  30. };
  31. exports.rounded = rounded;
  32. //# sourceMappingURL=rounded.js.map