Canvas: Ensure tangency for first segment (#86543)

This commit is contained in:
Drew Slobodnjak 2024-04-23 07:54:42 -07:00 committed by GitHub
parent 2049f766c6
commit 173ba73a8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -196,7 +196,7 @@ export const ConnectionSVG = ({
const Yn = vertices[index + 1].y * yDist + yStart;
if (index === 0) {
// First vertex
angle1 = calculateAngle(xStart, yStart, X, Y);
angle1 = calculateAngle(x1, y1, X, Y);
angle2 = calculateAngle(X, Y, Xn, Yn);
} else {
// All vertices
@ -239,7 +239,7 @@ export const ConnectionSVG = ({
// Only calculate arcs if there is a radius
if (radius) {
// Length of segment
const lSegment = calculateDistance(X, Y, xStart, yStart);
const lSegment = calculateDistance(X, Y, x1, y1);
if (Math.abs(lHalfArc) > 0.5 * Math.abs(lSegment)) {
// Limit curve control points to mid segment
lHalfArc = 0.5 * lSegment;
@ -250,8 +250,8 @@ export const ConnectionSVG = ({
if (index < vertices.length - 1) {
// Not also the last point
const nextVertex = vertices[index + 1];
Xn = nextVertex.x * xDist + xStart;
Yn = nextVertex.y * yDist + yStart;
Xn = nextVertex.x * xDist + x1;
Yn = nextVertex.y * yDist + y1;
}
// Length of next segment
@ -262,15 +262,15 @@ export const ConnectionSVG = ({
}
// Calculate arc control points
const lDelta = lSegment - lHalfArc;
xa = lDelta * Math.cos(angle1) + xStart;
ya = lDelta * Math.sin(angle1) + yStart;
xa = lDelta * Math.cos(angle1) + x1;
ya = lDelta * Math.sin(angle1) + y1;
xb = lHalfArc * Math.cos(angle2) + X;
yb = lHalfArc * Math.sin(angle2) + Y;
// Check if arc control points are inside of segment, otherwise swap sign
if ((xa > X && xa > xStart) || (xa < X && xa < xStart)) {
xa = (lDelta + 2 * lHalfArc) * Math.cos(angle1) + xStart;
ya = (lDelta + 2 * lHalfArc) * Math.sin(angle1) + yStart;
if ((xa > X && xa > x1) || (xa < X && xa < x1)) {
xa = (lDelta + 2 * lHalfArc) * Math.cos(angle1) + x1;
ya = (lDelta + 2 * lHalfArc) * Math.sin(angle1) + y1;
xb = -lHalfArc * Math.cos(angle2) + X;
yb = -lHalfArc * Math.sin(angle2) + Y;
}