mirror of
https://github.com/ProjectSWGCore/Holocore.git
synced 2026-10-12 02:13:42 -04:00
Added a method to the Location class for calculating the distance to another Location object
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user