From 9a56c6112f9ddc5f3ecd6cbca202fccd6ad08fe1 Mon Sep 17 00:00:00 2001 From: Martin Robillard Date: Thu, 9 May 2024 16:22:04 -0400 Subject: [PATCH] [#523] Remove unnecessary use of Point2D --- src/org/jetuml/geom/Conversions.java | 24 -------------- .../edges/StateTransitionEdgeRenderer.java | 32 +++++++++---------- 2 files changed, 16 insertions(+), 40 deletions(-) diff --git a/src/org/jetuml/geom/Conversions.java b/src/org/jetuml/geom/Conversions.java index a92ca0aa..c0c500ce 100644 --- a/src/org/jetuml/geom/Conversions.java +++ b/src/org/jetuml/geom/Conversions.java @@ -21,7 +21,6 @@ package org.jetuml.geom; import javafx.geometry.Bounds; -import javafx.geometry.Point2D; import javafx.geometry.Rectangle2D; /** @@ -31,29 +30,6 @@ public final class Conversions { private Conversions() {} - /** - * @param pPoint2D The point to convert. - * @return A point created from rounding both x and y coordinate - * of the input parameter to integers. - * @pre pPoint2D != null; - */ - public static Point toPoint(Point2D pPoint2D) - { - assert pPoint2D != null; - return new Point( GeomUtils.round(pPoint2D.getX()), GeomUtils.round(pPoint2D.getY())); - } - - /** - * @param pPoint The point to covert. - * @return A Point2D with the same coordinates as pPoint. - * @pre pPoint != null; - */ - public static Point2D toPoint2D(Point pPoint) - { - assert pPoint != null; - return new Point2D(pPoint.x(), pPoint.y()); - } - /** * @param pBounds An input bounds object. * @return A rectangle that corresponds to pBounds. diff --git a/src/org/jetuml/rendering/edges/StateTransitionEdgeRenderer.java b/src/org/jetuml/rendering/edges/StateTransitionEdgeRenderer.java index 47af28f2..32841832 100644 --- a/src/org/jetuml/rendering/edges/StateTransitionEdgeRenderer.java +++ b/src/org/jetuml/rendering/edges/StateTransitionEdgeRenderer.java @@ -35,10 +35,9 @@ import org.jetuml.rendering.DiagramRenderer; import org.jetuml.rendering.LineStyle; import org.jetuml.rendering.StringRenderer; -import org.jetuml.rendering.ToolGraphics; import org.jetuml.rendering.StringRenderer.Alignment; +import org.jetuml.rendering.ToolGraphics; -import javafx.geometry.Point2D; import javafx.geometry.Rectangle2D; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; @@ -113,7 +112,7 @@ private void drawArrowHead(Edge pEdge, GraphicsContext pGraphics) else { ArrowHeadRenderer.draw(pGraphics, ArrowHead.V, - Conversions.toPoint(getControlPoint(pEdge)), getConnectionPoints(pEdge).point2()); + getControlPoint(pEdge), getConnectionPoints(pEdge).point2()); } } @@ -174,9 +173,9 @@ private static Dimension getLabelBounds(String pString) private Rectangle2D getNormalEdgeLabelBounds(StateTransitionEdge pEdge) { Line line = getConnectionPoints(pEdge); - Point2D control = getControlPoint(pEdge); - double x = control.getX() / 2 + line.x1() / 4 + line.x2() / 4; - double y = control.getY() / 2 + line.y1() / 4 + line.y2() / 4; + Point control = getControlPoint(pEdge); + int x = control.x() / 2 + line.x1() / 4 + line.x2() / 4; + int y = control.y() / 2 + line.y1() / 4 + line.y2() / 4; String label = wrapLabel(pEdge); Dimension textDimensions = getLabelBounds(label); @@ -349,19 +348,19 @@ private Line getSelfEdgeConnectionPoints(Edge pEdge) { if( getPosition(pEdge) == 1 ) { - Point2D point1 = new Point2D(parent().getBounds(pEdge.start()).maxX() - SELF_EDGE_OFFSET, + Point point1 = new Point(parent().getBounds(pEdge.start()).maxX() - SELF_EDGE_OFFSET, parent().getBounds(pEdge.start()).y()); - Point2D point2 = new Point2D(parent().getBounds(pEdge.start()).maxX(), + Point point2 = new Point(parent().getBounds(pEdge.start()).maxX(), parent().getBounds(pEdge.start()).y() + SELF_EDGE_OFFSET); - return new Line(Conversions.toPoint(point1), Conversions.toPoint(point2)); + return new Line(point1, point2); } else { - Point2D point1 = new Point2D(parent().getBounds(pEdge.start()).x(), + Point point1 = new Point(parent().getBounds(pEdge.start()).x(), parent().getBounds(pEdge.start()).y() + SELF_EDGE_OFFSET); - Point2D point2 = new Point2D(parent().getBounds(pEdge.start()).x() + SELF_EDGE_OFFSET, + Point point2 = new Point(parent().getBounds(pEdge.start()).x() + SELF_EDGE_OFFSET, parent().getBounds(pEdge.start()).y()); - return new Line(Conversions.toPoint(point1), Conversions.toPoint(point2)); + return new Line(point1, point2); } } @@ -370,7 +369,7 @@ private Shape getNormalEdgeShape(Edge pEdge) Line line = getConnectionPoints(pEdge); Path path = new Path(); MoveTo moveTo = new MoveTo(line.point1().x(), line.point1().y()); - QuadCurveTo curveTo = new QuadCurveTo(getControlPoint(pEdge).getX(), getControlPoint(pEdge).getY(), + QuadCurveTo curveTo = new QuadCurveTo(getControlPoint(pEdge).x(), getControlPoint(pEdge).y(), line.point2().x(), line.point2().y()); path.getElements().addAll(moveTo, curveTo); return path; @@ -378,10 +377,10 @@ private Shape getNormalEdgeShape(Edge pEdge) /** - * Gets the control point for the quadratic spline. + * Gets the control point for the quadratic spline. * @return the control point */ - private Point2D getControlPoint(Edge pEdge) + private Point getControlPoint(Edge pEdge) { Line line = getConnectionPoints(pEdge); double tangent = Math.tan(Math.toRadians(DEGREES_10)); @@ -391,7 +390,8 @@ private Point2D getControlPoint(Edge pEdge) } double dx = (line.x2() - line.x1()) / 2; double dy = (line.y2() - line.y1()) / 2; - return new Point2D((line.x1() + line.x2()) / 2 + tangent * dy, (line.y1() + line.y2()) / 2 - tangent * dx); + return new Point(GeomUtils.round((line.x1() + line.x2()) / 2 + tangent * dy), + GeomUtils.round((line.y1() + line.y2()) / 2 - tangent * dx)); } @Override