Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to render connections with round corners #747

Merged
merged 6 commits into from
Feb 2, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore(util): simplify Geometry#pointsAligned helper
  • Loading branch information
nikku committed Feb 1, 2023
commit aec2232ebf018a79cd146e4c984b6c8600b7183a
68 changes: 22 additions & 46 deletions lib/util/Geometry.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
every,
isArray
every
} from 'min-dash';

/**
Expand Down Expand Up @@ -56,65 +55,42 @@ var ALIGNED_THRESHOLD = 2;
/**
* Check whether two points are horizontally or vertically aligned.
*
* @param {Array<Point>|Point}
* @param {Point}
* @param {Point[]|Point} a
* @param {Point} [b]
*
* @return {string|boolean}
* @return {'h'|'v'|false} axis or false
*/
export function pointsAligned(a, b) {
var points;
var points = Array.from(arguments).flat();

if (isArray(a)) {
points = a;
} else {
points = [ a, b ];
}

if (pointsAlignedHorizontally(points)) {
return 'h';
}
const axisMap = {
'x': 'v',
'y': 'h'
};

if (pointsAlignedVertically(points)) {
return 'v';
for (const [ axis, orientation ] of Object.entries(axisMap)) {
if (pointsAlignedOnAxis(axis, points)) {
return orientation;
}
}

return false;
}

export function pointsAlignedHorizontally(a, b) {
var points;

if (isArray(a)) {
points = a;
} else {
points = [ a, b ];
}

var firstPoint = points.slice().shift();

return every(points, function(point) {
return Math.abs(firstPoint.y - point.y) <= ALIGNED_THRESHOLD;
});
}

export function pointsAlignedVertically(a, b) {
var points;

if (isArray(a)) {
points = a;
} else {
points = [ a, b ];
}

var firstPoint = points.slice().shift();
/**
* @param { 'x' | 'y' } axis
* @param { Point[] } points
*
* @return {boolean}
*/
export function pointsAlignedOnAxis(axis, points) {
const referencePoint = points[0];

return every(points, function(point) {
return Math.abs(firstPoint.x - point.x) <= ALIGNED_THRESHOLD;
return Math.abs(referencePoint[axis] - point[axis]) <= ALIGNED_THRESHOLD;
});
}



/**
* Returns true if the point p is inside the rectangle rect
*
Expand Down