Dear users, Please note that, from Monday, August 16, 2019, RSA keys shorter than 2048bit will no longer be accepted for security reasons. Please update your keys as needed before this date. If you need assistance with regard to this process, please contact sia@list.lu

Thank you for your understanding.

Commit e1979a95 authored by Nico Mack's avatar Nico Mack

Fixed minor bugs in connectable bootstrapping.

Splines are now drawn as open paths.
parent a8af8a3b
......@@ -8,15 +8,16 @@ import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.PolarCoordinateHelper;
import lu.list.itis.dkd.tui.utility.ScreenCoordinates;
import lu.list.itis.dkd.tui.utility.ShapeUtils;
import lu.list.itis.dkd.tui.widget.corona.ShapeFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;
import java.awt.geom.Line2D;
import java.util.ArrayList;
import java.util.List;
......@@ -33,7 +34,7 @@ public class Spline extends Connection implements Cloneable {
protected double originOffsetAngle;
protected double endingOffsetAngle;
protected int interpolationSteps;
protected Polygon spline;
protected Shape spline;
protected float strokeWidth;
protected Color strokeColour;
......@@ -41,14 +42,17 @@ public class Spline extends Connection implements Cloneable {
private Linear second;
private Point intersection;
private Shape marker = ShapeFactory.buildCircle(2);
// private Shape marker = ShapeFactory.buildCircle(2);
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static final double EPSILON = 1e-2;
private static final double SCREEN_DIAGONAL = Math.sqrt(Math.pow(Calibration.getScreenWidth(), 2) + Math.pow(Calibration.getScreenHeight(), 2));
private static final Logger LOGGER = LoggerFactory.getLogger(Spline.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
......@@ -103,12 +107,18 @@ public class Spline extends Connection implements Cloneable {
second = this.getLine(endingConnector, this.endingOffsetAngle);
intersection = first.intersectionWith(second);
if (intersection != null) {
if (first.equals(second, EPSILON)) {
this.spline = new Line2D.Float(originConnector.x, originConnector.y, endingConnector.x, endingConnector.y);
} else {
List<Point> segments = new ArrayList<>();
segments.add(originConnector);
segments.add(intersection);
segments.add(endingConnector);
this.spline = ShapeUtils.quadraticBSpline(segments, this.interpolationSteps);
}
} else {
LOGGER.warn("Unable to determine intersection!");
}
}
// ---------------------------------------------------------------------------
......@@ -131,30 +141,30 @@ public class Spline extends Connection implements Cloneable {
localCanvas.setStroke(pen);
localCanvas.setColor(strokeColour);
localCanvas.drawPolygon(this.spline);
localCanvas.draw(this.spline);
}
localCanvas.setColor(Color.WHITE);
if (this.first != null) {
Point start = this.origin.getConnector();
float x = start.x + 100;
float y = start.y + (float) this.first.getValueFor(x);
Point end = new Point(x, y, 0f, ScreenCoordinates.class);
localCanvas.drawLine((int) start.x, (int) start.y, (int) end.x, (int) end.y);
}
if (this.second != null) {
Point start = this.ending.getConnector();
float x = start.x + 100;
float y = start.y + (float) this.second.getValueFor(x);
Point end = new Point(x, y, 0f, ScreenCoordinates.class);
localCanvas.drawLine((int) start.x, (int) start.y, (int) end.x, (int) end.y);
}
if (this.intersection != null) {
AffineTransform translate = AffineTransform.getTranslateInstance(intersection.x, intersection.y);
localCanvas.draw(translate.createTransformedShape(marker));
}
// localCanvas.setColor(Color.WHITE);
// if (this.first != null) {
// Point start = this.origin.getConnector();
// float x = start.x + 100;
// float y = start.y + (float) this.first.getValueFor(x);
// Point end = new Point(x, y, 0f, ScreenCoordinates.class);
// localCanvas.drawLine((int) start.x, (int) start.y, (int) end.x, (int) end.y);
// }
// if (this.second != null) {
// Point start = this.ending.getConnector();
// float x = start.x + 100;
// float y = start.y + (float) this.second.getValueFor(x);
// Point end = new Point(x, y, 0f, ScreenCoordinates.class);
// localCanvas.drawLine((int) start.x, (int) start.y, (int) end.x, (int) end.y);
// }
//
// if (this.intersection != null) {
// AffineTransform translate = AffineTransform.getTranslateInstance(intersection.x, intersection.y);
// localCanvas.draw(translate.createTransformedShape(marker));
// }
......
......@@ -178,6 +178,23 @@ public class Linear {
return null;
}
// ---------------------------------------------------------------------------
/**
* @param other
* @param epsilon
* @return
*/
// ---------------------------------------------------------------------------
public boolean equals(Linear other, double epsilon) {
if (other == null)
return false;
boolean areEqual = MathUtils.equals(this.slope, other.slope, epsilon);
areEqual &= MathUtils.equals(this.intercept, other.intercept, epsilon);
return areEqual;
}
// ---------------------------------------------------------------------------
@Override
......
......@@ -16,8 +16,9 @@
*/
package lu.list.itis.dkd.tui.utility;
import java.awt.Polygon;
import java.awt.Shape;
import java.awt.geom.GeneralPath;
import java.awt.geom.Path2D;
import java.awt.geom.PathIterator;
import java.util.List;
......@@ -195,11 +196,12 @@ public class ShapeUtils {
*/
// ---------------------------------------------------------------------------
public static Polygon quadraticBSpline(List<Point> controlSegments, int numberOfSteps) {
Polygon poly = new Polygon();
public static Path2D quadraticBSpline(List<Point> controlSegments, int numberOfSteps) {
Path2D path = new GeneralPath();
int numberOfPoints = controlSegments.size();
Point[] segments = new Point[numberOfPoints];
Point ctrl;
boolean first = true;
for (int i = 0; i < numberOfPoints; i++) {
segments[i] = controlSegments.get(i).clone().toCoordinates(ScreenCoordinates.class);
......@@ -211,11 +213,16 @@ public class ShapeUtils {
for (int j = 0; j <= numberOfSteps; j++) {
double u = ((double) j) / numberOfSteps;
ctrl = getControlPoint(i, u, segments);
poly.addPoint((int) ctrl.x, (int) ctrl.y);
if (first) {
path.reset();
path.moveTo((int) ctrl.x, (int) ctrl.y);
first = false;
} else {
path.lineTo((int) ctrl.x, (int) ctrl.y);
}
}
}
return poly;
return path;
}
// ---------------------------------------------------------------------------
......
......@@ -222,6 +222,7 @@ public abstract class CoronaBuilder<B extends CoronaBuilder<B>> {
Element connectionsNode = connectableNode.getChild(Externalization.CONNECTIONS_NODE);
this.connections = this.buildConnections(connectionsNode, context, callback);
this.exclusive = BootstrappingUtils.getContentAsBoolean(connectableNode, Externalization.EXCLUSIVE_NODE, BootstrappingUtils.OPTIONAL, false, context);
this.connector = new Point(connectableNode.getChild(Externalization.CONNECTOR_NODE), context, callback);
}
}
......
......@@ -20,7 +20,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.awt.Polygon;
import java.awt.geom.Path2D;
import java.util.ArrayList;
import java.util.List;
......@@ -50,7 +50,7 @@ public class ShapeUtilsTest {
controlSegments.add(new Point(0, 0, 0, ScreenCoordinates.class));
controlSegments.add(new Point(100, 0, 0, ScreenCoordinates.class));
Polygon poly = ShapeUtils.quadraticBSpline(controlSegments, 4);
Path2D poly = ShapeUtils.quadraticBSpline(controlSegments, 4);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment