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-gef#383
  • Loading branch information
ptziegler committed Mar 17, 2024
1 parent 64bd301 commit e0412ea
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 8 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);
}
}
2 changes: 1 addition & 1 deletion org.eclipse.draw2d/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.draw2d;singleton:=true
Bundle-Version: 3.15.0.qualifier
Bundle-Version: 3.15.100.qualifier
Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.draw2d,
Expand Down
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 e0412ea

Please sign in to comment.