chunk-XX4N3DI4.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import {
  2. every
  3. } from "./chunk-4AK4GF4H.js";
  4. // node_modules/.pnpm/diagram-js@11.9.1/node_modules/diagram-js/lib/util/Geometry.js
  5. function pointDistance(a, b) {
  6. if (!a || !b) {
  7. return -1;
  8. }
  9. return Math.sqrt(
  10. Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2)
  11. );
  12. }
  13. function pointsOnLine(p, q, r, accuracy) {
  14. if (typeof accuracy === "undefined") {
  15. accuracy = 5;
  16. }
  17. if (!p || !q || !r) {
  18. return false;
  19. }
  20. var val = (q.x - p.x) * (r.y - p.y) - (q.y - p.y) * (r.x - p.x), dist = pointDistance(p, q);
  21. return Math.abs(val / dist) <= accuracy;
  22. }
  23. var ALIGNED_THRESHOLD = 2;
  24. function pointsAligned(a, b) {
  25. var points = Array.from(arguments).flat();
  26. const axisMap = {
  27. "x": "v",
  28. "y": "h"
  29. };
  30. for (const [axis, orientation] of Object.entries(axisMap)) {
  31. if (pointsAlignedOnAxis(axis, points)) {
  32. return orientation;
  33. }
  34. }
  35. return false;
  36. }
  37. function pointsAlignedOnAxis(axis, points) {
  38. const referencePoint = points[0];
  39. return every(points, function(point) {
  40. return Math.abs(referencePoint[axis] - point[axis]) <= ALIGNED_THRESHOLD;
  41. });
  42. }
  43. function pointInRect(p, rect, tolerance) {
  44. tolerance = tolerance || 0;
  45. return p.x > rect.x - tolerance && p.y > rect.y - tolerance && p.x < rect.x + rect.width + tolerance && p.y < rect.y + rect.height + tolerance;
  46. }
  47. function getMidPoint(p, q) {
  48. return {
  49. x: Math.round(p.x + (q.x - p.x) / 2),
  50. y: Math.round(p.y + (q.y - p.y) / 2)
  51. };
  52. }
  53. export {
  54. pointDistance,
  55. pointsOnLine,
  56. pointsAligned,
  57. pointsAlignedOnAxis,
  58. pointInRect,
  59. getMidPoint
  60. };
  61. //# sourceMappingURL=chunk-XX4N3DI4.js.map