Skip to content
Snippets Groups Projects
Commit 9aff21b6 authored by Ulrich Schöpp's avatar Ulrich Schöpp
Browse files

Fix coordinate calculation in EllipticBorderLocation

Method getLocation should compute the location on the ellipse border
from the angle (counter-clockwise, starting from the x coordinate). THe
formula that was implemented took the angle on a circle and then scales
it to an ellipse. But this scaling does not preserve angles, so the
resulting point isn't right.

This means that if one starts with a point on the border of the ellipse,
uses getClosestLocationOnBounds and then getLocation, then one does not
get the point that one started with. When dragging an anchorage on an
elliptic component, the anchorage will often not be in the right place.

Issue-Ref: 3924
Issue-Url: https://af3-developer.fortiss.org/issues/3924


Signed-off-by: default avatarUlrich Schöpp <schoepp@fortiss.org>
parent 28adcf50
No related branches found
No related tags found
1 merge request!89[3924] Fix small bugs in fx diagram editor
......@@ -3,5 +3,5 @@ CircularContentVisualBase.java cc3caea328e36e90069b915e413c8e7e9522a939 YELLOW
CircularDiagramAnchorageVisualBase.java 7a3b92fb1b135c218b9a5e16506acfc74a6b5468 YELLOW
CurveLinkVisualBase.java 0b8706214320d715966c86a5242ad21c8bf5a315 YELLOW
CurveSegment.java 445bc2607cb70ae1c788c27ba9fc637dd7df4956 YELLOW
EllipticBorderLocation.java 1e9b3d42c7fcd5495004fb30b0c499096a839967 YELLOW
EllipticBorderLocation.java 6775dd54c01f8d76ecf1721185b60b63f1eec6c2 YELLOW
EllipticContentVisualBase.java dc2fddc9cfe5605bc8a5d09dd862845e360b23f5 YELLOW
......@@ -10,8 +10,6 @@
package org.fortiss.tooling.common.ui.javafx.lwfxef.visual.elliptic;
import static java.lang.Math.atan2;
import static java.lang.Math.cos;
import static java.lang.Math.sin;
import static java.util.Objects.requireNonNull;
import org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramCoordinate;
......@@ -55,12 +53,19 @@ public final class EllipticBorderLocation {
* ellipse center.
*/
public DiagramCoordinate getLocation() {
double rw = radiuses.getWidth();
double rh = radiuses.getHeight();
double angle = Math.PI * angleInDegree / 180;
double x = rw - correction.getWidth() / 2 + rw * cos(angle);
double y = rh - correction.getHeight() / 2 - rh * sin(angle);
return new DiagramCoordinate(x, y);
double rh = radiuses.getWidth();
double rv = radiuses.getHeight();
DiagramCoordinate middle = new DiagramCoordinate(rh, rv);
double cos = Math.cos(angle);
double sin = Math.sin(angle);
double tan = (sin / cos);
// Division by zero will result in tan being Infinity,
// which gives the right results for x and y.
double x = rh * rv / Math.sqrt(rv * rv + rh * rh * tan * tan);
double y = rh * rv * Math.signum(tan) / Math.sqrt(rv * rv / (tan * tan) + rh * rh);
return middle.add(x * Math.signum(cos), -y * Math.signum(cos))
.subtract(correction.getWidth() / 2.0, correction.getHeight() / 2.0);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment