From da4480ab49cb72f488f521427164d235856b28c4 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 8 Jan 2011 10:59:06 -0800 Subject: [PATCH] Did some minor Vector optimization. --- src/com/sk89q/worldedit/EditSession.java | 3 ++- src/com/sk89q/worldedit/Vector.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/com/sk89q/worldedit/EditSession.java b/src/com/sk89q/worldedit/EditSession.java index 3c8e1d0c4..1d2f4c6a0 100755 --- a/src/com/sk89q/worldedit/EditSession.java +++ b/src/com/sk89q/worldedit/EditSession.java @@ -1579,6 +1579,7 @@ public class EditSession { public int simulateSnow(Vector pos, int radius) throws MaxChangedBlocksException { int affected = 0; + int radiusSq = (int)Math.pow(radius, 2); int ox = pos.getBlockX(); int oy = pos.getBlockY(); @@ -1589,7 +1590,7 @@ public class EditSession { for (int x = ox - radius; x <= ox + radius; x++) { for (int z = oz - radius; z <= oz + radius; z++) { - if ((new Vector(x, oy, z)).distance(pos) > radius) { + if ((new Vector(x, oy, z)).distanceSq(pos) > radiusSq) { continue; } diff --git a/src/com/sk89q/worldedit/Vector.java b/src/com/sk89q/worldedit/Vector.java index a499e4d07..055d02509 100644 --- a/src/com/sk89q/worldedit/Vector.java +++ b/src/com/sk89q/worldedit/Vector.java @@ -446,6 +446,18 @@ public class Vector { Math.pow(pt.z - z, 2)); } + /** + * Get the distance away from a point, squared. + * + * @param pt + * @return distance + */ + public double distanceSq(Vector pt) { + return Math.pow(pt.x - x, 2) + + Math.pow(pt.y - y, 2) + + Math.pow(pt.z - z, 2); + } + /** * Checks to see if a vector is contained with another. *