Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce getDistanceSquared for deprecated getDistance2 #21 #573

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ public void testGetDifferencePoint() {

@SuppressWarnings("static-method")
@Test
public void testGetDistance2Point() {
assertEquals(25, new Point(4, 7).getDistance2(new Point(1, 3)));
assertEquals(25, new Point(-1, -2).getDistance2(new Point(-5, 1)));
public void testGetDistanceSquaredPoint() {
assertEquals(25, new Point(4, 7).getDistanceSquared(new Point(1, 3)));
assertEquals(25, new Point(-1, -2).getDistanceSquared(new Point(-5, 1)));
}

@SuppressWarnings("static-method")
Expand Down
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.17.100.qualifier
Bundle-Version: 3.18.0.qualifier
Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.draw2d,
Expand Down
15 changes: 14 additions & 1 deletion org.eclipse.draw2d/src/org/eclipse/draw2d/geometry/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,23 @@ public double getDistance(Point p) {
* @return distance<sup>2</sup>
* @since 2.0
* @noreference This method is not intended to be referenced by clients.
* @deprecated Use {@link #getDistance(Point)} and square the result instead.
* @deprecated Use {@link #getDistanceSquared(Point)}.
*/
@Deprecated(since = "3.7", forRemoval = true)
public int getDistance2(Point p) {
return getDistanceSquared(p);
}

/**
* Calculates the distance squared between this Point and the one specified. If
* the distance squared is larger than the maximum integer value, then
* <code>Integer.MAX_VALUE</code> will be returned.
*
* @param p The reference Point
* @return distance<sup>2</sup>
* @since 3.18
*/
public int getDistanceSquared(Point p) {
long i = p.x() - x;
long j = p.y() - y;
long result = i * i + j * j;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public ConnectionAnchor connectionAnchorAt(Point p) {

for (ConnectionAnchor c : getSourceConnectionAnchors()) {
Point p2 = c.getLocation(null);
long d = p.getDistance2(p2);
long d = p.getDistanceSquared(p2);
if (d < min) {
min = d;
closest = c;
}
}
for (ConnectionAnchor c : getTargetConnectionAnchors()) {
Point p2 = c.getLocation(null);
long d = p.getDistance2(p2);
long d = p.getDistanceSquared(p2);
if (d < min) {
min = d;
closest = c;
Expand Down Expand Up @@ -70,7 +70,7 @@ public ConnectionAnchor getSourceConnectionAnchorAt(Point p) {

for (ConnectionAnchor c : getSourceConnectionAnchors()) {
Point p2 = c.getLocation(null);
long d = p.getDistance2(p2);
long d = p.getDistanceSquared(p2);
if (d < min) {
min = d;
closest = c;
Expand All @@ -89,7 +89,7 @@ public ConnectionAnchor getTargetConnectionAnchorAt(Point p) {

for (ConnectionAnchor c : getTargetConnectionAnchors()) {
Point p2 = c.getLocation(null);
long d = p.getDistance2(p2);
long d = p.getDistanceSquared(p2);
if (d < min) {
min = d;
closest = c;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ private void setReferencePoints(BendpointRequest request) {
// points include the bend points as well as start and end, which we may
// leave out when searching for the bend point index
for (int i = 1; i < points.size() - 1; i++) {
if (smallestDistance == -1 || points.getPoint(i).getDistance2(bp) < smallestDistance) {
if (smallestDistance == -1 || points.getPoint(i).getDistanceSquared(bp) < smallestDistance) {
bpIndex = i;
smallestDistance = points.getPoint(i).getDistance2(bp);
smallestDistance = points.getPoint(i).getDistanceSquared(bp);
if (smallestDistance == 0) {
break;
}
Expand Down
Loading