123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import {
- every
- } from "./chunk-4AK4GF4H.js";
- // node_modules/.pnpm/diagram-js@11.9.1/node_modules/diagram-js/lib/util/Geometry.js
- function pointDistance(a, b) {
- if (!a || !b) {
- return -1;
- }
- return Math.sqrt(
- Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2)
- );
- }
- function pointsOnLine(p, q, r, accuracy) {
- if (typeof accuracy === "undefined") {
- accuracy = 5;
- }
- if (!p || !q || !r) {
- return false;
- }
- var val = (q.x - p.x) * (r.y - p.y) - (q.y - p.y) * (r.x - p.x), dist = pointDistance(p, q);
- return Math.abs(val / dist) <= accuracy;
- }
- var ALIGNED_THRESHOLD = 2;
- function pointsAligned(a, b) {
- var points = Array.from(arguments).flat();
- const axisMap = {
- "x": "v",
- "y": "h"
- };
- for (const [axis, orientation] of Object.entries(axisMap)) {
- if (pointsAlignedOnAxis(axis, points)) {
- return orientation;
- }
- }
- return false;
- }
- function pointsAlignedOnAxis(axis, points) {
- const referencePoint = points[0];
- return every(points, function(point) {
- return Math.abs(referencePoint[axis] - point[axis]) <= ALIGNED_THRESHOLD;
- });
- }
- function pointInRect(p, rect, tolerance) {
- tolerance = tolerance || 0;
- 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;
- }
- function getMidPoint(p, q) {
- return {
- x: Math.round(p.x + (q.x - p.x) / 2),
- y: Math.round(p.y + (q.y - p.y) / 2)
- };
- }
- export {
- pointDistance,
- pointsOnLine,
- pointsAligned,
- pointsAlignedOnAxis,
- pointInRect,
- getMidPoint
- };
- //# sourceMappingURL=chunk-XX4N3DI4.js.map
|