Added a method to the Location class for calculating the distance to another Location object

This commit is contained in:
Mads Boddum
2015-09-26 01:55:12 +02:00
parent 98143d8092
commit 8125f0b447
+13
View File
@@ -263,7 +263,20 @@ public class Location implements Encodable, Serializable {
point.decode(data);
}
@Override
public String toString() {
return String.format("Location[TRN=%s, %s %s]", terrain, point, orientation);
}
/**
* @param destination to get the distance for
* @return the distance between {@code this} and destination, which is ALWAYS positive.
*/
public double distanceTo(Location destination) {
double deltaX = destination.getX() - getX();
double deltaY = destination.getY() - getY();
double deltaZ = destination.getZ() - getZ();
return Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2) + Math.pow(deltaZ, 2));
}
}