From: Jussi Koskela Date: Tue, 14 Apr 2020 07:37:42 +0000 (+0300) Subject: Round corners between non-axis-aligned connection lines properly X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F36%2F4136%2F1;p=simantics%2Fplatform.git Round corners between non-axis-aligned connection lines properly gitlab #517 Change-Id: I8eb1fba0ecf419834f9a830bbe2aa0fb0e8d21fd --- diff --git a/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/rendering/BasicConnectionStyle.java b/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/rendering/BasicConnectionStyle.java index b2895fb34..301cfdf09 100644 --- a/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/rendering/BasicConnectionStyle.java +++ b/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/rendering/BasicConnectionStyle.java @@ -126,16 +126,18 @@ public class BasicConnectionStyle implements ConnectionStyle, Serializable { double dy1 = curY-oldY; double dx2 = curX-newX; double dy2 = curY-newY; - double maxRadius = 0.5 * Math.min(Math.sqrt(dx1*dx1 + dy1*dy1), Math.sqrt(dx2*dx2 + dy2*dy2)); + double r1 = Math.sqrt(dx1*dx1 + dy1*dy1); + double r2 = Math.sqrt(dx2*dx2 + dy2*dy2); + double maxRadius = 0.5 * Math.min(r1, r2); double radius = Math.min(rounding, maxRadius); - newPath.lineTo(curX + radius*Math.signum(oldX-curX), curY + radius*Math.signum(oldY-curY)); + double dx1Normalized = r1 > 0 ? dx1 / r1 : 0; + double dy1Normalized = r1 > 0 ? dy1 / r1 : 0; + double dx2Normalized = r2 > 0 ? dx2 / r2 : 0; + double dy2Normalized = r2 > 0 ? dy2 / r2 : 0; + newPath.lineTo(curX - radius*dx1Normalized, curY - radius*dy1Normalized); newPath.curveTo(curX, curY, curX, curY, - curX + radius*Math.signum(newX-curX), curY + radius*Math.signum(newY-curY)); - - //newPath.lineTo(curX + round*Math.signum(oldX-curX), curY + round*Math.signum(oldY-curY)); - //newPath.lineTo(curX + round*Math.signum(newX-curX), curY + round*Math.signum(newY-curY)); - //newPath.lineTo(curX, curY); + curX - radius*dx2Normalized, curY - radius*dy2Normalized); } else ++state;