13
0
geforkt von Mirrors/Paper

Revert finite checks in locations. Fixes SPIGOT-628 and others

By: md_5 <git@md-5.net>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2015-02-28 09:43:52 +11:00
Ursprung 925591bd64
Commit 76a64b3e2d
3 geänderte Dateien mit 115 neuen und 92 gelöschten Zeilen

Datei anzeigen

@ -43,12 +43,12 @@ public class Location implements Cloneable, ConfigurationSerializable {
* @param pitch The absolute rotation on the y-plane, in degrees * @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) { public Location(final World world, final double x, final double y, final double z, final float yaw, final float pitch) {
setWorld(world); this.world = world;
setX(x); this.x = x;
setY(y); this.y = y;
setZ(z); this.z = z;
setPitch(pitch); this.pitch = pitch;
setYaw(yaw); this.yaw = yaw;
} }
/** /**
@ -93,7 +93,6 @@ public class Location implements Cloneable, ConfigurationSerializable {
* @param x X-coordinate * @param x X-coordinate
*/ */
public void setX(double x) { public void setX(double x) {
checkFinite(x, "x must be finite");
this.x = x; this.x = x;
} }
@ -122,7 +121,6 @@ public class Location implements Cloneable, ConfigurationSerializable {
* @param y y-coordinate * @param y y-coordinate
*/ */
public void setY(double y) { public void setY(double y) {
checkFinite(y, "y must be finite");
this.y = y; this.y = y;
} }
@ -151,7 +149,6 @@ public class Location implements Cloneable, ConfigurationSerializable {
* @param z z-coordinate * @param z z-coordinate
*/ */
public void setZ(double z) { public void setZ(double z) {
checkFinite(z, "z must be finite");
this.z = z; this.z = z;
} }
@ -189,7 +186,6 @@ public class Location implements Cloneable, ConfigurationSerializable {
* @param yaw new rotation's yaw * @param yaw new rotation's yaw
*/ */
public void setYaw(float yaw) { public void setYaw(float yaw) {
checkFinite(yaw, "yaw must be finite");
this.yaw = yaw; this.yaw = yaw;
} }
@ -224,7 +220,6 @@ public class Location implements Cloneable, ConfigurationSerializable {
* @param pitch new incline's pitch * @param pitch new incline's pitch
*/ */
public void setPitch(float pitch) { public void setPitch(float pitch) {
checkFinite(pitch, "pitch must be finite");
this.pitch = pitch; this.pitch = pitch;
} }
@ -288,17 +283,17 @@ public class Location implements Cloneable, ConfigurationSerializable {
final double z = vector.getZ(); final double z = vector.getZ();
if (x == 0 && z == 0) { if (x == 0 && z == 0) {
setPitch(vector.getY() > 0 ? -90 : 90); pitch = vector.getY() > 0 ? -90 : 90;
return this; return this;
} }
double theta = Math.atan2(-x, z); 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 x2 = NumberConversions.square(x);
double z2 = NumberConversions.square(z); double z2 = NumberConversions.square(z);
double xz = Math.sqrt(x2 + z2); 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; return this;
} }
@ -316,9 +311,9 @@ public class Location implements Cloneable, ConfigurationSerializable {
throw new IllegalArgumentException("Cannot add Locations of differing worlds"); throw new IllegalArgumentException("Cannot add Locations of differing worlds");
} }
setX(getX() + vec.getX()); x += vec.x;
setY(getY() + vec.getY()); y += vec.y;
setZ(getZ() + vec.getZ()); z += vec.z;
return this; return this;
} }
@ -330,9 +325,9 @@ public class Location implements Cloneable, ConfigurationSerializable {
* @return the same location * @return the same location
*/ */
public Location add(Vector vec) { public Location add(Vector vec) {
setX(getX() + vec.getX()); this.x += vec.getX();
setY(getY() + vec.getY()); this.y += vec.getY();
setZ(getZ() + vec.getZ()); this.z += vec.getZ();
return this; return this;
} }
@ -346,9 +341,9 @@ public class Location implements Cloneable, ConfigurationSerializable {
* @return the same location * @return the same location
*/ */
public Location add(double x, double y, double z) { public Location add(double x, double y, double z) {
setX(getX() + x); this.x += x;
setY(getY() + y); this.y += y;
setZ(getZ() + z); this.z += z;
return this; return this;
} }
@ -365,9 +360,9 @@ public class Location implements Cloneable, ConfigurationSerializable {
throw new IllegalArgumentException("Cannot add Locations of differing worlds"); throw new IllegalArgumentException("Cannot add Locations of differing worlds");
} }
setX(getX() - vec.getX()); x -= vec.x;
setY(getY() - vec.getY()); y -= vec.y;
setZ(getZ() - vec.getZ()); z -= vec.z;
return this; return this;
} }
@ -379,9 +374,9 @@ public class Location implements Cloneable, ConfigurationSerializable {
* @return the same location * @return the same location
*/ */
public Location subtract(Vector vec) { public Location subtract(Vector vec) {
setX(getX() - vec.getX()); this.x -= vec.getX();
setY(getY() - vec.getY()); this.y -= vec.getY();
setZ(getZ() - vec.getZ()); this.z -= vec.getZ();
return this; return this;
} }
@ -396,9 +391,9 @@ public class Location implements Cloneable, ConfigurationSerializable {
* @return the same location * @return the same location
*/ */
public Location subtract(double x, double y, double z) { public Location subtract(double x, double y, double z) {
setX(getX() - x); this.x -= x;
setY(getY() - y); this.y -= y;
setZ(getZ() - z); this.z -= z;
return this; return this;
} }
@ -473,9 +468,9 @@ public class Location implements Cloneable, ConfigurationSerializable {
* @return the same location * @return the same location
*/ */
public Location multiply(double m) { public Location multiply(double m) {
setX(getX() * m); x *= m;
setY(getY() * m); y *= m;
setZ(getZ() * m); z *= m;
return this; return this;
} }
@ -486,9 +481,9 @@ public class Location implements Cloneable, ConfigurationSerializable {
* @return the same location * @return the same location
*/ */
public Location zero() { public Location zero() {
setX(0D); x = 0;
setY(0D); y = 0;
setZ(0D); z = 0;
return this; return this;
} }

Datei anzeigen

@ -16,7 +16,9 @@ public class BlockVector extends Vector {
* Construct the vector with all components as 0. * Construct the vector with all components as 0.
*/ */
public BlockVector() { 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. * @param vec The other vector.
*/ */
public BlockVector(Vector vec) { 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 * @param z Z component
*/ */
public BlockVector(int x, int y, int z) { 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 * @param z Z component
*/ */
public BlockVector(double x, double y, double z) { 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 * @param z Z component
*/ */
public BlockVector(float x, float y, float z) { public BlockVector(float x, float y, float z) {
super(x, y, z); this.x = x;
this.y = y;
this.z = z;
} }
/** /**

Datei anzeigen

@ -34,7 +34,9 @@ public class Vector implements Cloneable, ConfigurationSerializable {
* Construct the vector with all components as 0. * Construct the vector with all components as 0.
*/ */
public Vector() { 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 * @param z Z component
*/ */
public Vector(int x, int y, int z) { 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 * @param z Z component
*/ */
public Vector(double x, double y, double z) { public Vector(double x, double y, double z) {
// use setters for range checks this.x = x;
setX(x); this.y = y;
setY(y); this.z = z;
setZ(z);
} }
/** /**
@ -70,7 +73,9 @@ public class Vector implements Cloneable, ConfigurationSerializable {
* @param z Z component * @param z Z component
*/ */
public Vector(float x, float y, float z) { 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 * @return the same vector
*/ */
public Vector add(Vector vec) { public Vector add(Vector vec) {
setX(getX() + vec.getX()); x += vec.x;
setY(getY() + vec.getY()); y += vec.y;
setZ(getZ() + vec.getZ()); z += vec.z;
return this; return this;
} }
@ -93,9 +98,9 @@ public class Vector implements Cloneable, ConfigurationSerializable {
* @return the same vector * @return the same vector
*/ */
public Vector subtract(Vector vec) { public Vector subtract(Vector vec) {
setX(getX() - vec.getX()); x -= vec.x;
setY(getY() - vec.getY()); y -= vec.y;
setZ(getZ() - vec.getZ()); z -= vec.z;
return this; return this;
} }
@ -106,9 +111,9 @@ public class Vector implements Cloneable, ConfigurationSerializable {
* @return the same vector * @return the same vector
*/ */
public Vector multiply(Vector vec) { public Vector multiply(Vector vec) {
setX(getX() * vec.getX()); x *= vec.x;
setY(getY() * vec.getY()); y *= vec.y;
setZ(getZ() * vec.getZ()); z *= vec.z;
return this; return this;
} }
@ -119,9 +124,9 @@ public class Vector implements Cloneable, ConfigurationSerializable {
* @return the same vector * @return the same vector
*/ */
public Vector divide(Vector vec) { public Vector divide(Vector vec) {
setX(getX() / vec.getX()); x /= vec.x;
setY(getY() / vec.getY()); y /= vec.y;
setZ(getZ() / vec.getZ()); z /= vec.z;
return this; return this;
} }
@ -132,9 +137,9 @@ public class Vector implements Cloneable, ConfigurationSerializable {
* @return the same vector * @return the same vector
*/ */
public Vector copy(Vector vec) { public Vector copy(Vector vec) {
setX(vec.getX()); x = vec.x;
setY(vec.getY()); y = vec.y;
setZ(vec.getZ()); z = vec.z;
return this; return this;
} }
@ -203,9 +208,9 @@ public class Vector implements Cloneable, ConfigurationSerializable {
* @return this same vector (now a midpoint) * @return this same vector (now a midpoint)
*/ */
public Vector midpoint(Vector other) { public Vector midpoint(Vector other) {
setX((getX() + other.getX()) / 2); x = (x + other.x) / 2;
setY((getY() + other.getY()) / 2); y = (y + other.y) / 2;
setZ((getZ() + other.getZ()) / 2); z = (z + other.z) / 2;
return this; return this;
} }
@ -230,7 +235,10 @@ public class Vector implements Cloneable, ConfigurationSerializable {
* @return the same vector * @return the same vector
*/ */
public Vector multiply(int m) { 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 * @return the same vector
*/ */
public Vector multiply(double m) { public Vector multiply(double m) {
setX(getX() * m); x *= m;
setY(getY() * m); y *= m;
setZ(getZ() * m); z *= m;
return this; return this;
} }
@ -255,7 +263,10 @@ public class Vector implements Cloneable, ConfigurationSerializable {
* @return the same vector * @return the same vector
*/ */
public Vector multiply(float m) { 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 * @return the same vector
*/ */
public Vector crossProduct(Vector o) { public Vector crossProduct(Vector o) {
double newX = getY() * o.getZ() - o.getY() * getZ(); double newX = y * o.z - o.y * z;
double newY = getZ() * o.getX() - o.getZ() * getX(); double newY = z * o.x - o.z * x;
double newZ = getX() * o.getY() - o.getX() * getY(); double newZ = x * o.y - o.x * y;
setX(newX); x = newX;
setY(newY); y = newY;
setZ(newZ); z = newZ;
return this; return this;
} }
@ -300,7 +311,11 @@ public class Vector implements Cloneable, ConfigurationSerializable {
public Vector normalize() { public Vector normalize() {
double length = length(); 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 * @return the same vector
*/ */
public Vector zero() { public Vector zero() {
setX(0D); x = 0;
setY(0D); y = 0;
setZ(0D); z = 0;
return this; return this;
} }
@ -404,7 +419,8 @@ public class Vector implements Cloneable, ConfigurationSerializable {
* @return This vector. * @return This vector.
*/ */
public Vector setX(int x) { 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. * @return This vector.
*/ */
public Vector setX(double x) { public Vector setX(double x) {
checkFinite(x, "x must be finite");
this.x = x; this.x = x;
return this; return this;
} }
@ -426,7 +441,8 @@ public class Vector implements Cloneable, ConfigurationSerializable {
* @return This vector. * @return This vector.
*/ */
public Vector setX(float x) { 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. * @return This vector.
*/ */
public Vector setY(int y) { 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. * @return This vector.
*/ */
public Vector setY(double y) { public Vector setY(double y) {
checkFinite(y, "y must be finite");
this.y = y; this.y = y;
return this; return this;
} }
@ -458,7 +474,8 @@ public class Vector implements Cloneable, ConfigurationSerializable {
* @return This vector. * @return This vector.
*/ */
public Vector setY(float y) { 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. * @return This vector.
*/ */
public Vector setZ(int z) { 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. * @return This vector.
*/ */
public Vector setZ(double z) { public Vector setZ(double z) {
checkFinite(z, "z must be finite");
this.z = z; this.z = z;
return this; return this;
} }
@ -490,7 +507,8 @@ public class Vector implements Cloneable, ConfigurationSerializable {
* @return This vector. * @return This vector.
*/ */
public Vector setZ(float z) { public Vector setZ(float z) {
return setZ((double) z); this.z = z;
return this;
} }
/** /**