From 0620ced63c0b62e0f759901683754d51731f44a0 Mon Sep 17 00:00:00 2001 From: asofold Date: Tue, 29 Jan 2013 03:20:37 +0100 Subject: [PATCH] Add utility methods for 2d-distance. --- .../nocheatplus/utilities/CheckUtils.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/utilities/CheckUtils.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/utilities/CheckUtils.java index 6ddc2b23..df5534af 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/utilities/CheckUtils.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/utilities/CheckUtils.java @@ -67,7 +67,7 @@ public class CheckUtils { } /** - * Distance of two locations. This is obsolete, since it has been fixed. To ignore world checks it might be "useful". + * 3D-distance of two locations. This is obsolete, since it has been fixed. To ignore world checks it might be "useful". * * @param location1 * the location1 @@ -81,7 +81,7 @@ public class CheckUtils { } /** - * Distance. + * 3D-distance. * @param x1 * @param y1 * @param z1 @@ -96,6 +96,31 @@ public class CheckUtils { final double dz = Math.abs(z1 - z2); return Math.sqrt(dx * dx + dy * dy + dz * dz); } + + /** + * 2D-distance in x-z plane. + * @param location1 + * @param location2 + * @return + */ + public static final double xzDistance(final Location location1, final Location location2) + { + return distance(location1.getX(), location1.getZ(), location2.getX(), location2.getZ()); + } + + /** + * 2D-distance. + * @param x1 + * @param z1 + * @param x2 + * @param z2 + * @return + */ + public static final double distance(final double x1, final double z1, final double x2, final double z2) { + final double dx = Math.abs(x1 - x2); + final double dz = Math.abs(z1 - z2); + return Math.sqrt(dx * dx + dz * dz); + } /** * Return if the two Strings are similar based on the given threshold.