Skip to content

Commit

Permalink
Use PrecisionPoint instead of Point to handle deprecation warning
Browse files Browse the repository at this point in the history
This commit partially reverts fd75841
and uses PrecisionPoints instead of Points in the FanRouter class, to
store the bend point.

Note that because the mid point is a plain point, the equality check is
done using the integer coordinates.

Resolves eclipse#383
  • Loading branch information
ptziegler authored and azoitl committed Mar 17, 2024
1 parent c51b966 commit 19274a2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2023 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -25,6 +25,7 @@
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
FanRouterTest.class,
ShortestPathRoutingTest.class,
XYLayoutTest.class,
TextFlowWrapTest.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*******************************************************************************
* Copyright (c) Patrick Ziegler and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Patrick Ziegler - initial API and implementation
*******************************************************************************/

package org.eclipse.draw2d.test;

import static org.junit.Assert.assertEquals;

import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.FanRouter;
import org.eclipse.draw2d.PolylineConnection;
import org.eclipse.draw2d.XYAnchor;
import org.eclipse.draw2d.geometry.Point;

import org.junit.Before;
import org.junit.Test;

public class FanRouterTest {
FanRouter router;
Connection connection;
ConnectionAnchor sourceAnchor;
ConnectionAnchor targetAnchor;

@Before
public void setUp() {
sourceAnchor = new XYAnchor(new Point(0, 0));
targetAnchor = new XYAnchor(new Point(0, 50));

connection = new PolylineConnection();
connection.setSourceAnchor(sourceAnchor);
connection.setTargetAnchor(targetAnchor);

router = new FanRouter();
}

/**
* When routing the "same" connection multiple times, no additional break point
* needs to be created.
*/
@Test
public void testRouteSameConnection() {
router.route(connection);
assertEquals(connection.getPoints().size(), 2);

router.route(connection);
assertEquals(connection.getPoints().size(), 2);
}
}
11 changes: 5 additions & 6 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/FanRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.PrecisionPoint;
import org.eclipse.draw2d.geometry.Ray;

/**
Expand Down Expand Up @@ -61,17 +62,15 @@ protected void handleCollision(PointList points, int index) {
}
double length = ray.length();

double xSeparation = separation * ray.x / length;
double ySeparation = separation * ray.y / length;
double xSeparation = separation * ray.x / length * (index / 2);
double ySeparation = separation * ray.y / length * (index / 2);

Point bendPoint;

if (index % 2 == 0) {
bendPoint = new Point(midPoint.x + (int) ((index / 2.0) * -1.0 * ySeparation),
midPoint.y + (int) ((index / 2.0) * xSeparation));
bendPoint = new PrecisionPoint(midPoint.x + (-1 * ySeparation), midPoint.y + xSeparation);
} else {
bendPoint = new Point(midPoint.x + (int) ((index / 2.0) * ySeparation),
midPoint.y + (int) ((index / 2.0) * -1.0 * xSeparation));
bendPoint = new PrecisionPoint(midPoint.x + ySeparation, midPoint.y + (-1 * xSeparation));
}
if (!bendPoint.equals(midPoint)) {
points.insertPoint(bendPoint, 1);
Expand Down

0 comments on commit 19274a2

Please sign in to comment.