/** * Sets the value of this vector to the (x, y, z, w) values of the provided source vector. * * @param source * @return this vector for chaining * @throws NullPointerException if source is null. */ public Vector4 set(final ReadOnlyVector4 source) { setX(source.getX()); setY(source.getY()); setZ(source.getZ()); setW(source.getW()); return this; }
/** * Performs a linear interpolation between this vector and the given end vector, using the given * scalar as a percent. iow, if changeAmnt is closer to 0, the result will be closer to the * current value of this vector and if it is closer to 1, the result will be closer to the end * value. The result is stored back in this vector. * * @param endVec * @param scalar * @return this vector for chaining * @throws NullPointerException if endVec is null. */ public Vector4 lerpLocal(final ReadOnlyVector4 endVec, final double scalar) { setX((1.0 - scalar) * getX() + scalar * endVec.getX()); setY((1.0 - scalar) * getY() + scalar * endVec.getY()); setZ((1.0 - scalar) * getZ() + scalar * endVec.getZ()); setW((1.0 - scalar) * getW() + scalar * endVec.getW()); return this; }
/** * Divides the values of this vector by the given scale values and returns the result in store. * * @param scale * @param store the vector to store the result in for return. If null, a new vector object is * created and returned. * @return a new vector (this.x / scale.x, this.y / scale.y, this.z / scale.z, this.w / scale.w) */ @Override public Vector4 divide(final ReadOnlyVector4 scale, final Vector4 store) { Vector4 result = store; if (result == null) { result = new Vector4(); } return result.set( getX() / scale.getX(), getY() / scale.getY(), getZ() / scale.getZ(), getW() / scale.getW()); }
/** * Performs a linear interpolation between this vector and the given end vector, using the given * scalar as a percent. iow, if changeAmnt is closer to 0, the result will be closer to the * current value of this vector and if it is closer to 1, the result will be closer to the end * value. The result is returned as a new vector object. * * @param endVec * @param scalar * @param store the vector to store the result in for return. If null, a new vector object is * created and returned. * @return a new vector as described above. * @throws NullPointerException if endVec is null. */ @Override public Vector4 lerp(final ReadOnlyVector4 endVec, final double scalar, final Vector4 store) { Vector4 result = store; if (result == null) { result = new Vector4(); } final double x = (1.0 - scalar) * getX() + scalar * endVec.getX(); final double y = (1.0 - scalar) * getY() + scalar * endVec.getY(); final double z = (1.0 - scalar) * getZ() + scalar * endVec.getZ(); final double w = (1.0 - scalar) * getW() + scalar * endVec.getW(); return result.set(x, y, z, w); }
/** * Scales this vector by multiplying its values with a given scale value, then adding a given * "add" value. The result is store in the given store parameter. * * @param scale the value to multiply by. * @param add the value to add * @param store the vector to store the result in for return. If null, a new vector object is * created and returned. * @return the store variable */ @Override public Vector4 scaleAdd(final double scale, final ReadOnlyVector4 add, final Vector4 store) { Vector4 result = store; if (result == null) { result = new Vector4(); } result.setX(_x * scale + add.getX()); result.setY(_y * scale + add.getY()); result.setZ(_z * scale + add.getZ()); result.setW(_w * scale + add.getW()); return result; }
/** * @param o the object to compare for equality * @return true if this vector and the provided vector have the same x, y, z and w values. */ @Override public boolean equals(final Object o) { if (this == o) { return true; } if (!(o instanceof ReadOnlyVector4)) { return false; } final ReadOnlyVector4 comp = (ReadOnlyVector4) o; return getX() == comp.getX() && getY() == comp.getY() && getZ() == comp.getZ() && getW() == comp.getW(); }
/** * Check a vector... if it is null or its doubles are NaN or infinite, return false. Else return * true. * * @param vector the vector to check * @return true or false as stated above. */ public static boolean isValid(final ReadOnlyVector4 vector) { if (vector == null) { return false; } if (Double.isNaN(vector.getX()) || Double.isNaN(vector.getY()) || Double.isNaN(vector.getZ()) || Double.isNaN(vector.getW())) { return false; } if (Double.isInfinite(vector.getX()) || Double.isInfinite(vector.getY()) || Double.isInfinite(vector.getZ()) || Double.isInfinite(vector.getW())) { return false; } return true; }
/** * @param vec * @return the dot product of this vector with the x, y, z, w values of the given vector. * @throws NullPointerException if vec is null. */ @Override public double dot(final ReadOnlyVector4 vec) { return dot(vec.getX(), vec.getY(), vec.getZ(), vec.getW()); }
/** * @param destination * @return the squared distance between the point described by this vector and the given * destination point. When comparing the relative distance between two points it is usually * sufficient to compare the squared distances, thus avoiding an expensive square root * operation. * @throws NullPointerException if destination is null. */ @Override public double distanceSquared(final ReadOnlyVector4 destination) { return distanceSquared( destination.getX(), destination.getY(), destination.getZ(), destination.getW()); }
/** * Constructs a new vector set to the (x, y, z, w) values of the given source vector. * * @param src */ public Vector4(final ReadOnlyVector4 src) { this(src.getX(), src.getY(), src.getZ(), src.getW()); }
/** * Internally modifies the values of this vector by dividing them each by the given scale values. * * @param scale * @return this vector for chaining */ public Vector4 divideLocal(final ReadOnlyVector4 scale) { return set( getX() / scale.getX(), getY() / scale.getY(), getZ() / scale.getZ(), getW() / scale.getW()); }
/** * Internally modifies the values of this vector by multiplying them each by the given scale * values. * * @param scale * @return this vector for chaining */ public Vector4 multiplyLocal(final ReadOnlyVector4 scale) { return set( getX() * scale.getX(), getY() * scale.getY(), getZ() * scale.getZ(), getW() * scale.getW()); }
/** * Decrements the values of this vector by the x, y, z and w values from the given source vector. * * @param source * @return this vector for chaining * @throws NullPointerException if source is null. */ public Vector4 subtractLocal(final ReadOnlyVector4 source) { return subtractLocal(source.getX(), source.getY(), source.getZ(), source.getW()); }
/** * Subtracts the values of the given source vector from those of this vector and returns them in * store. * * @param source * @param store the vector to store the result in for return. If null, a new vector object is * created and returned. * @return (this.x - source.x, this.y - source.y, this.z - source.z, this.w - source.w) * @throws NullPointerException if source is null. */ @Override public Vector4 subtract(final ReadOnlyVector4 source, final Vector4 store) { return subtract(source.getX(), source.getY(), source.getZ(), source.getW(), store); }
/** * Increments the values of this vector with the x, y, z and w values of the given vector. * * @param source * @return this vector for chaining * @throws NullPointerException if source is null. */ public Vector4 addLocal(final ReadOnlyVector4 source) { return addLocal(source.getX(), source.getY(), source.getZ(), source.getW()); }
/** * Adds the values of the given source vector to those of this vector and returns them in store. * * @param source * @param store the vector to store the result in for return. If null, a new vector object is * created and returned. * @return (this.x + source.x, this.y + source.y, this.z + source.z, this.w + source.w) * @throws NullPointerException if source is null. */ @Override public Vector4 add(final ReadOnlyVector4 source, final Vector4 store) { return add(source.getX(), source.getY(), source.getZ(), source.getW(), store); }