Skip to content
Snippets Groups Projects

[3924] Fix small bugs in fx diagram editor

Merged Ulrich Schöpp requested to merge 3924 into master
2 files
+ 3
1
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -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;
@@ -53,14 +51,23 @@ public final class EllipticBorderLocation {
/**
* Returns the location computed from this {@link EllipticBorderLocation} relative to the
* ellipse center.
* TODO(JE): leads to java.lang.ArithmeticException: / by zero if cos is 0. What is the
* difference to the existing code? Why is an adaption needed?
*/
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);
}
/**
Loading