Skip to content

Commit

Permalink
[#523] Remove unnecessary use of Point2D
Browse files Browse the repository at this point in the history
  • Loading branch information
prmr committed May 9, 2024
1 parent 3868c5f commit 9a56c61
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 40 deletions.
24 changes: 0 additions & 24 deletions src/org/jetuml/geom/Conversions.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package org.jetuml.geom;

import javafx.geometry.Bounds;
import javafx.geometry.Point2D;
import javafx.geometry.Rectangle2D;

/**
Expand All @@ -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.
Expand Down
32 changes: 16 additions & 16 deletions src/org/jetuml/rendering/edges/StateTransitionEdgeRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -370,18 +369,18 @@ 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;
}


/**
* 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));
Expand All @@ -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
Expand Down

0 comments on commit 9a56c61

Please sign in to comment.