diff options
author | md_5 <git@md-5.net> | 2015-02-28 09:43:52 +1100 |
---|---|---|
committer | md_5 <git@md-5.net> | 2015-02-28 09:43:52 +1100 |
commit | 1d2509b99fb10b3bd6f597e63805f85b49d5a055 (patch) | |
tree | 8dd1af4bfaa8d19ca1e2ce307a620135ed654b7c | |
parent | 2b22e68f5a98e69f0ab92f7e8ad6653e8ecc0599 (diff) | |
download | bukkit-1d2509b99fb10b3bd6f597e63805f85b49d5a055.tar bukkit-1d2509b99fb10b3bd6f597e63805f85b49d5a055.tar.gz bukkit-1d2509b99fb10b3bd6f597e63805f85b49d5a055.tar.lz bukkit-1d2509b99fb10b3bd6f597e63805f85b49d5a055.tar.xz bukkit-1d2509b99fb10b3bd6f597e63805f85b49d5a055.zip |
Revert finite checks in locations. Fixes SPIGOT-628 and others
-rw-r--r-- | src/main/java/org/bukkit/Location.java | 71 | ||||
-rw-r--r-- | src/main/java/org/bukkit/util/BlockVector.java | 20 | ||||
-rw-r--r-- | src/main/java/org/bukkit/util/Vector.java | 116 |
3 files changed, 115 insertions, 92 deletions
diff --git a/src/main/java/org/bukkit/Location.java b/src/main/java/org/bukkit/Location.java index 583dbe8f..e7af316d 100644 --- a/src/main/java/org/bukkit/Location.java +++ b/src/main/java/org/bukkit/Location.java @@ -43,12 +43,12 @@ public class Location implements Cloneable, ConfigurationSerializable { * @param pitch The absolute rotation on the y-plane, in degrees */ public Location(final World world, final double x, final double y, final double z, final float yaw, final float pitch) { - setWorld(world); - setX(x); - setY(y); - setZ(z); - setPitch(pitch); - setYaw(yaw); + this.world = world; + this.x = x; + this.y = y; + this.z = z; + this.pitch = pitch; + this.yaw = yaw; } /** @@ -93,7 +93,6 @@ public class Location implements Cloneable, ConfigurationSerializable { * @param x X-coordinate */ public void setX(double x) { - checkFinite(x, "x must be finite"); this.x = x; } @@ -122,7 +121,6 @@ public class Location implements Cloneable, ConfigurationSerializable { * @param y y-coordinate */ public void setY(double y) { - checkFinite(y, "y must be finite"); this.y = y; } @@ -151,7 +149,6 @@ public class Location implements Cloneable, ConfigurationSerializable { * @param z z-coordinate */ public void setZ(double z) { - checkFinite(z, "z must be finite"); this.z = z; } @@ -189,7 +186,6 @@ public class Location implements Cloneable, ConfigurationSerializable { * @param yaw new rotation's yaw */ public void setYaw(float yaw) { - checkFinite(yaw, "yaw must be finite"); this.yaw = yaw; } @@ -224,7 +220,6 @@ public class Location implements Cloneable, ConfigurationSerializable { * @param pitch new incline's pitch */ public void setPitch(float pitch) { - checkFinite(pitch, "pitch must be finite"); this.pitch = pitch; } @@ -288,17 +283,17 @@ public class Location implements Cloneable, ConfigurationSerializable { final double z = vector.getZ(); if (x == 0 && z == 0) { - setPitch(vector.getY() > 0 ? -90 : 90); + pitch = vector.getY() > 0 ? -90 : 90; return this; } double theta = Math.atan2(-x, z); - setYaw((float) Math.toDegrees((theta + _2PI) % _2PI)); + yaw = (float) Math.toDegrees((theta + _2PI) % _2PI); double x2 = NumberConversions.square(x); double z2 = NumberConversions.square(z); double xz = Math.sqrt(x2 + z2); - setPitch((float) Math.toDegrees(Math.atan(-vector.getY() / xz))); + pitch = (float) Math.toDegrees(Math.atan(-vector.getY() / xz)); return this; } @@ -316,9 +311,9 @@ public class Location implements Cloneable, ConfigurationSerializable { throw new IllegalArgumentException("Cannot add Locations of differing worlds"); } - setX(getX() + vec.getX()); - setY(getY() + vec.getY()); - setZ(getZ() + vec.getZ()); + x += vec.x; + y += vec.y; + z += vec.z; return this; } @@ -330,9 +325,9 @@ public class Location implements Cloneable, ConfigurationSerializable { * @return the same location */ public Location add(Vector vec) { - setX(getX() + vec.getX()); - setY(getY() + vec.getY()); - setZ(getZ() + vec.getZ()); + this.x += vec.getX(); + this.y += vec.getY(); + this.z += vec.getZ(); return this; } @@ -346,9 +341,9 @@ public class Location implements Cloneable, ConfigurationSerializable { * @return the same location */ public Location add(double x, double y, double z) { - setX(getX() + x); - setY(getY() + y); - setZ(getZ() + z); + this.x += x; + this.y += y; + this.z += z; return this; } @@ -365,9 +360,9 @@ public class Location implements Cloneable, ConfigurationSerializable { throw new IllegalArgumentException("Cannot add Locations of differing worlds"); } - setX(getX() - vec.getX()); - setY(getY() - vec.getY()); - setZ(getZ() - vec.getZ()); + x -= vec.x; + y -= vec.y; + z -= vec.z; return this; } @@ -379,9 +374,9 @@ public class Location implements Cloneable, ConfigurationSerializable { * @return the same location */ public Location subtract(Vector vec) { - setX(getX() - vec.getX()); - setY(getY() - vec.getY()); - setZ(getZ() - vec.getZ()); + this.x -= vec.getX(); + this.y -= vec.getY(); + this.z -= vec.getZ(); return this; } @@ -396,9 +391,9 @@ public class Location implements Cloneable, ConfigurationSerializable { * @return the same location */ public Location subtract(double x, double y, double z) { - setX(getX() - x); - setY(getY() - y); - setZ(getZ() - z); + this.x -= x; + this.y -= y; + this.z -= z; return this; } @@ -473,9 +468,9 @@ public class Location implements Cloneable, ConfigurationSerializable { * @return the same location */ public Location multiply(double m) { - setX(getX() * m); - setY(getY() * m); - setZ(getZ() * m); + x *= m; + y *= m; + z *= m; return this; } @@ -486,9 +481,9 @@ public class Location implements Cloneable, ConfigurationSerializable { * @return the same location */ public Location zero() { - setX(0D); - setY(0D); - setZ(0D); + x = 0; + y = 0; + z = 0; return this; } diff --git a/src/main/java/org/bukkit/util/BlockVector.java b/src/main/java/org/bukkit/util/BlockVector.java index 9f5bef22..bdf8f6d5 100644 --- a/src/main/java/org/bukkit/util/BlockVector.java +++ b/src/main/java/org/bukkit/util/BlockVector.java @@ -16,7 +16,9 @@ public class BlockVector extends Vector { * Construct the vector with all components as 0. */ public BlockVector() { - super(); + this.x = 0; + this.y = 0; + this.z = 0; } /** @@ -25,7 +27,9 @@ public class BlockVector extends Vector { * @param vec The other vector. */ public BlockVector(Vector vec) { - this(vec.getX(), vec.getY(), vec.getZ()); + this.x = vec.getX(); + this.y = vec.getY(); + this.z = vec.getZ(); } /** @@ -36,7 +40,9 @@ public class BlockVector extends Vector { * @param z Z component */ public BlockVector(int x, int y, int z) { - super(x, y, z); + this.x = x; + this.y = y; + this.z = z; } /** @@ -47,7 +53,9 @@ public class BlockVector extends Vector { * @param z Z component */ public BlockVector(double x, double y, double z) { - super(x, y, z); + this.x = x; + this.y = y; + this.z = z; } /** @@ -58,7 +66,9 @@ public class BlockVector extends Vector { * @param z Z component */ public BlockVector(float x, float y, float z) { - super(x, y, z); + this.x = x; + this.y = y; + this.z = z; } /** diff --git a/src/main/java/org/bukkit/util/Vector.java b/src/main/java/org/bukkit/util/Vector.java index be8cf41a..685148ec 100644 --- a/src/main/java/org/bukkit/util/Vector.java +++ b/src/main/java/org/bukkit/util/Vector.java @@ -34,7 +34,9 @@ public class Vector implements Cloneable, ConfigurationSerializable { * Construct the vector with all components as 0. */ public Vector() { - this(0, 0, 0); + this.x = 0; + this.y = 0; + this.z = 0; } /** @@ -45,7 +47,9 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @param z Z component */ public Vector(int x, int y, int z) { - this((double) x, (double) y, (double) z); + this.x = x; + this.y = y; + this.z = z; } /** @@ -56,10 +60,9 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @param z Z component */ public Vector(double x, double y, double z) { - // use setters for range checks - setX(x); - setY(y); - setZ(z); + this.x = x; + this.y = y; + this.z = z; } /** @@ -70,7 +73,9 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @param z Z component */ public Vector(float x, float y, float z) { - this((double) x, (double) y, (double) z); + this.x = x; + this.y = y; + this.z = z; } /** @@ -80,9 +85,9 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return the same vector */ public Vector add(Vector vec) { - setX(getX() + vec.getX()); - setY(getY() + vec.getY()); - setZ(getZ() + vec.getZ()); + x += vec.x; + y += vec.y; + z += vec.z; return this; } @@ -93,9 +98,9 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return the same vector */ public Vector subtract(Vector vec) { - setX(getX() - vec.getX()); - setY(getY() - vec.getY()); - setZ(getZ() - vec.getZ()); + x -= vec.x; + y -= vec.y; + z -= vec.z; return this; } @@ -106,9 +111,9 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return the same vector */ public Vector multiply(Vector vec) { - setX(getX() * vec.getX()); - setY(getY() * vec.getY()); - setZ(getZ() * vec.getZ()); + x *= vec.x; + y *= vec.y; + z *= vec.z; return this; } @@ -119,9 +124,9 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return the same vector */ public Vector divide(Vector vec) { - setX(getX() / vec.getX()); - setY(getY() / vec.getY()); - setZ(getZ() / vec.getZ()); + x /= vec.x; + y /= vec.y; + z /= vec.z; return this; } @@ -132,9 +137,9 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return the same vector */ public Vector copy(Vector vec) { - setX(vec.getX()); - setY(vec.getY()); - setZ(vec.getZ()); + x = vec.x; + y = vec.y; + z = vec.z; return this; } @@ -203,9 +208,9 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return this same vector (now a midpoint) */ public Vector midpoint(Vector other) { - setX((getX() + other.getX()) / 2); - setY((getY() + other.getY()) / 2); - setZ((getZ() + other.getZ()) / 2); + x = (x + other.x) / 2; + y = (y + other.y) / 2; + z = (z + other.z) / 2; return this; } @@ -230,7 +235,10 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return the same vector */ public Vector multiply(int m) { - return multiply((double) m); + x *= m; + y *= m; + z *= m; + return this; } /** @@ -241,9 +249,9 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return the same vector */ public Vector multiply(double m) { - setX(getX() * m); - setY(getY() * m); - setZ(getZ() * m); + x *= m; + y *= m; + z *= m; return this; } @@ -255,7 +263,10 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return the same vector */ public Vector multiply(float m) { - return multiply((double) m); + x *= m; + y *= m; + z *= m; + return this; } /** @@ -282,13 +293,13 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return the same vector */ public Vector crossProduct(Vector o) { - double newX = getY() * o.getZ() - o.getY() * getZ(); - double newY = getZ() * o.getX() - o.getZ() * getX(); - double newZ = getX() * o.getY() - o.getX() * getY(); + double newX = y * o.z - o.y * z; + double newY = z * o.x - o.z * x; + double newZ = x * o.y - o.x * y; - setX(newX); - setY(newY); - setZ(newZ); + x = newX; + y = newY; + z = newZ; return this; } @@ -300,7 +311,11 @@ public class Vector implements Cloneable, ConfigurationSerializable { public Vector normalize() { double length = length(); - return multiply(1 / length); + x /= length; + y /= length; + z /= length; + + return this; } /** @@ -309,9 +324,9 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return the same vector */ public Vector zero() { - setX(0D); - setY(0D); - setZ(0D); + x = 0; + y = 0; + z = 0; return this; } @@ -404,7 +419,8 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return This vector. */ public Vector setX(int x) { - return setX((double) x); + this.x = x; + return this; } /** @@ -414,7 +430,6 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return This vector. */ public Vector setX(double x) { - checkFinite(x, "x must be finite"); this.x = x; return this; } @@ -426,7 +441,8 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return This vector. */ public Vector setX(float x) { - return setX((double) x); + this.x = x; + return this; } /** @@ -436,7 +452,8 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return This vector. */ public Vector setY(int y) { - return setY((double) y); + this.y = y; + return this; } /** @@ -446,7 +463,6 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return This vector. */ public Vector setY(double y) { - checkFinite(y, "y must be finite"); this.y = y; return this; } @@ -458,7 +474,8 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return This vector. */ public Vector setY(float y) { - return setY((double) y); + this.y = y; + return this; } /** @@ -468,7 +485,8 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return This vector. */ public Vector setZ(int z) { - return setZ((double) z); + this.z = z; + return this; } /** @@ -478,7 +496,6 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return This vector. */ public Vector setZ(double z) { - checkFinite(z, "z must be finite"); this.z = z; return this; } @@ -490,7 +507,8 @@ public class Vector implements Cloneable, ConfigurationSerializable { * @return This vector. */ public Vector setZ(float z) { - return setZ((double) z); + this.z = z; + return this; } /** |