2010-10-02 21:52:42 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Albert
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public class Vector {
|
2010-10-11 18:17:32 +00:00
|
|
|
protected final double x, y, z;
|
2010-10-02 21:52:42 +00:00
|
|
|
|
2010-10-03 19:43:30 +00:00
|
|
|
/**
|
2010-10-13 01:03:56 +00:00
|
|
|
* Construct the Vector object.
|
2010-10-11 08:22:47 +00:00
|
|
|
*
|
2010-10-03 19:43:30 +00:00
|
|
|
* @param x
|
|
|
|
* @param y
|
|
|
|
* @param z
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector(double x, double y, double z) {
|
2010-10-02 21:52:42 +00:00
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.z = z;
|
|
|
|
}
|
|
|
|
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
2010-10-13 01:03:56 +00:00
|
|
|
* Construct the Vector object.
|
2010-10-11 08:22:47 +00:00
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @param y
|
|
|
|
* @param z
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector(int x, int y, int z) {
|
2010-10-11 08:22:47 +00:00
|
|
|
this.x = (double)x;
|
|
|
|
this.y = (double)y;
|
|
|
|
this.z = (double)z;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-13 01:03:56 +00:00
|
|
|
* Construct the Vector object.
|
2010-10-11 08:22:47 +00:00
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @param y
|
|
|
|
* @param z
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector(float x, float y, float z) {
|
2010-10-11 08:22:47 +00:00
|
|
|
this.x = (double)x;
|
|
|
|
this.y = (double)y;
|
|
|
|
this.z = (double)z;
|
|
|
|
}
|
|
|
|
|
2010-10-11 18:17:32 +00:00
|
|
|
/**
|
2010-10-13 01:03:56 +00:00
|
|
|
* Construct the Vector object.
|
2010-10-11 18:17:32 +00:00
|
|
|
*
|
|
|
|
* @param pt
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector(Vector pt) {
|
2010-10-11 18:17:32 +00:00
|
|
|
this.x = pt.x;
|
|
|
|
this.y = pt.y;
|
|
|
|
this.z = pt.z;
|
|
|
|
}
|
|
|
|
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
2010-10-13 01:03:56 +00:00
|
|
|
* Construct the Vector object.
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector() {
|
2010-10-11 08:22:47 +00:00
|
|
|
this.x = 0;
|
|
|
|
this.y = 0;
|
|
|
|
this.z = 0;
|
|
|
|
}
|
|
|
|
|
2010-10-02 21:52:42 +00:00
|
|
|
/**
|
|
|
|
* @return the x
|
|
|
|
*/
|
2010-10-11 08:22:47 +00:00
|
|
|
public double getX() {
|
2010-10-02 21:52:42 +00:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
|
|
|
* @return the x
|
|
|
|
*/
|
|
|
|
public int getBlockX() {
|
2010-10-17 22:17:24 +00:00
|
|
|
return (int)Math.round(x);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
2010-10-02 21:52:42 +00:00
|
|
|
|
2010-10-18 00:39:20 +00:00
|
|
|
/**
|
|
|
|
* Set X.
|
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @return new vector
|
|
|
|
*/
|
|
|
|
public Vector setX(double x) {
|
|
|
|
return new Vector(x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set X.
|
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @return new vector
|
|
|
|
*/
|
|
|
|
public Vector setX(int x) {
|
|
|
|
return new Vector(x, y, z);
|
|
|
|
}
|
|
|
|
|
2010-10-02 21:52:42 +00:00
|
|
|
/**
|
|
|
|
* @return the y
|
|
|
|
*/
|
2010-10-11 08:22:47 +00:00
|
|
|
public double getY() {
|
2010-10-02 21:52:42 +00:00
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
|
|
|
* @return the y
|
|
|
|
*/
|
|
|
|
public int getBlockY() {
|
2010-10-17 22:17:24 +00:00
|
|
|
return (int)Math.round(y);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 00:39:20 +00:00
|
|
|
/**
|
|
|
|
* Set Y.
|
|
|
|
*
|
|
|
|
* @param y
|
|
|
|
* @return new vector
|
|
|
|
*/
|
|
|
|
public Vector setY(double y) {
|
|
|
|
return new Vector(x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set Y.
|
|
|
|
*
|
|
|
|
* @param y
|
|
|
|
* @return new vector
|
|
|
|
*/
|
|
|
|
public Vector setY(int y) {
|
|
|
|
return new Vector(x, y, z);
|
|
|
|
}
|
|
|
|
|
2010-10-02 21:52:42 +00:00
|
|
|
/**
|
|
|
|
* @return the z
|
|
|
|
*/
|
2010-10-11 08:22:47 +00:00
|
|
|
public double getZ() {
|
2010-10-02 21:52:42 +00:00
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
|
|
|
* @return the z
|
|
|
|
*/
|
|
|
|
public int getBlockZ() {
|
2010-10-17 22:17:24 +00:00
|
|
|
return (int)Math.round(z);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 00:39:20 +00:00
|
|
|
/**
|
|
|
|
* Set Z.
|
|
|
|
*
|
|
|
|
* @param z
|
|
|
|
* @return new vector
|
|
|
|
*/
|
|
|
|
public Vector setZ(double z) {
|
|
|
|
return new Vector(x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set Z.
|
|
|
|
*
|
|
|
|
* @param z
|
|
|
|
* @return new vector
|
|
|
|
*/
|
|
|
|
public Vector setZ(int z) {
|
|
|
|
return new Vector(x, y, z);
|
|
|
|
}
|
|
|
|
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
|
|
|
* Adds two points.
|
|
|
|
*
|
|
|
|
* @param other
|
|
|
|
* @return New point
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector add(Vector other) {
|
|
|
|
return new Vector(x + other.x, y + other.y, z + other.z);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds two points.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @param x
|
|
|
|
* @param y
|
|
|
|
* @param z
|
2010-10-11 08:22:47 +00:00
|
|
|
* @return New point
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector add(double x, double y, double z) {
|
|
|
|
return new Vector(this.x + x, this.y + y, this.z + z);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds two points.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @param x
|
|
|
|
* @param y
|
|
|
|
* @param z
|
2010-10-11 08:22:47 +00:00
|
|
|
* @return New point
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector add(int x, int y, int z) {
|
|
|
|
return new Vector(this.x + x, this.y + y, this.z + z);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds points.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @param others
|
2010-10-11 08:22:47 +00:00
|
|
|
* @return New point
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector add(Vector ... others) {
|
2010-10-11 08:22:47 +00:00
|
|
|
double newX = x, newY = y, newZ = z;
|
|
|
|
|
|
|
|
for (int i = 0; i < others.length; i++) {
|
|
|
|
newX += others[i].x;
|
|
|
|
newY += others[i].y;
|
|
|
|
newZ += others[i].z;
|
|
|
|
}
|
2010-10-13 01:03:56 +00:00
|
|
|
return new Vector(newX, newY, newZ);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subtracts two points.
|
|
|
|
*
|
|
|
|
* @param other
|
|
|
|
* @return New point
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector subtract(Vector other) {
|
|
|
|
return new Vector(x - other.x, y - other.y, z - other.z);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subtract two points.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @param x
|
|
|
|
* @param y
|
|
|
|
* @param z
|
2010-10-11 08:22:47 +00:00
|
|
|
* @return New point
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector subtract(double x, double y, double z) {
|
|
|
|
return new Vector(this.x - x, this.y - y, this.z - z);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subtract two points.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @param x
|
|
|
|
* @param y
|
|
|
|
* @param z
|
2010-10-11 08:22:47 +00:00
|
|
|
* @return New point
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector subtract(int x, int y, int z) {
|
|
|
|
return new Vector(this.x - x, this.y - y, this.z - z);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subtract points.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @param others
|
2010-10-11 08:22:47 +00:00
|
|
|
* @return New point
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector subtract(Vector ... others) {
|
2010-10-11 08:22:47 +00:00
|
|
|
double newX = x, newY = y, newZ = z;
|
|
|
|
|
|
|
|
for (int i = 0; i < others.length; i++) {
|
|
|
|
newX -= others[i].x;
|
|
|
|
newY -= others[i].y;
|
|
|
|
newZ -= others[i].z;
|
|
|
|
}
|
2010-10-13 01:03:56 +00:00
|
|
|
return new Vector(newX, newY, newZ);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Multiplies two points.
|
|
|
|
*
|
|
|
|
* @param other
|
|
|
|
* @return New point
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector multiply(Vector other) {
|
|
|
|
return new Vector(x * other.x, y * other.y, z * other.z);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Multiply two points.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @param x
|
|
|
|
* @param y
|
|
|
|
* @param z
|
2010-10-11 08:22:47 +00:00
|
|
|
* @return New point
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector multiply(double x, double y, double z) {
|
|
|
|
return new Vector(this.x * x, this.y * y, this.z * z);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Multiply two points.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @param x
|
|
|
|
* @param y
|
|
|
|
* @param z
|
2010-10-11 08:22:47 +00:00
|
|
|
* @return New point
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector multiply(int x, int y, int z) {
|
|
|
|
return new Vector(this.x * x, this.y * y, this.z * z);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Multiply points.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @param others
|
2010-10-11 08:22:47 +00:00
|
|
|
* @return New point
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector multiply(Vector ... others) {
|
2010-10-11 08:22:47 +00:00
|
|
|
double newX = x, newY = y, newZ = z;
|
|
|
|
|
|
|
|
for (int i = 0; i < others.length; i++) {
|
|
|
|
newX *= others[i].x;
|
|
|
|
newY *= others[i].y;
|
|
|
|
newZ *= others[i].z;
|
|
|
|
}
|
2010-10-13 01:03:56 +00:00
|
|
|
return new Vector(newX, newY, newZ);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
2010-10-13 04:41:06 +00:00
|
|
|
/**
|
|
|
|
* Scalar multiplication.
|
|
|
|
*
|
|
|
|
* @param n
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector multiply(double n) {
|
|
|
|
return new Vector(this.x * n, this.y * n, this.z * n);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scalar multiplication.
|
|
|
|
*
|
|
|
|
* @param n
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector multiply(float n) {
|
|
|
|
return new Vector(this.x * n, this.y * n, this.z * n);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scalar multiplication.
|
|
|
|
*
|
|
|
|
* @param n
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector multiply(int n) {
|
|
|
|
return new Vector(this.x * n, this.y * n, this.z * n);
|
|
|
|
}
|
|
|
|
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
|
|
|
* Divide two points.
|
|
|
|
*
|
|
|
|
* @param other
|
|
|
|
* @return New point
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector divide(Vector other) {
|
|
|
|
return new Vector(x / other.x, y / other.y, z / other.z);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Divide two points.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @param x
|
|
|
|
* @param y
|
|
|
|
* @param z
|
2010-10-11 08:22:47 +00:00
|
|
|
* @return New point
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector divide(double x, double y, double z) {
|
|
|
|
return new Vector(this.x / x, this.y / y, this.z / z);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Divide two points.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @param x
|
|
|
|
* @param y
|
|
|
|
* @param z
|
2010-10-11 08:22:47 +00:00
|
|
|
* @return New point
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public Vector divide(int x, int y, int z) {
|
|
|
|
return new Vector(this.x / x, this.y / y, this.z / z);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
2010-10-13 23:49:35 +00:00
|
|
|
/**
|
|
|
|
* Scalar division.
|
|
|
|
*
|
|
|
|
* @param n
|
|
|
|
* @return new point
|
|
|
|
*/
|
|
|
|
public Vector divide(int n) {
|
|
|
|
return new Vector(x / n, y / n, z / n);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scalar division.
|
|
|
|
*
|
|
|
|
* @param n
|
|
|
|
* @return new point
|
|
|
|
*/
|
|
|
|
public Vector divide(double n) {
|
|
|
|
return new Vector(x / n, y / n, z / n);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scalar division.
|
|
|
|
*
|
|
|
|
* @param n
|
|
|
|
* @return new point
|
|
|
|
*/
|
|
|
|
public Vector divide(float n) {
|
|
|
|
return new Vector(x / n, y / n, z / n);
|
|
|
|
}
|
|
|
|
|
2010-10-11 18:17:32 +00:00
|
|
|
/**
|
|
|
|
* Get the distance away from a point.
|
|
|
|
*
|
|
|
|
* @param pt
|
|
|
|
* @return distance
|
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public double distance(Vector pt) {
|
2010-10-11 18:17:32 +00:00
|
|
|
return Math.sqrt(Math.pow(pt.x - x, 2) +
|
|
|
|
Math.pow(pt.y - y, 2) +
|
|
|
|
Math.pow(pt.z - z, 2));
|
|
|
|
}
|
|
|
|
|
2010-10-18 20:51:43 +00:00
|
|
|
/**
|
|
|
|
* Checks to see if a vector is contained with another.
|
|
|
|
*
|
|
|
|
* @param min
|
|
|
|
* @param max
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean containedWithin(Vector min, Vector max) {
|
|
|
|
return x >= min.getX() && x <= max.getX()
|
|
|
|
&& y >= min.getY() && z <= max.getY()
|
|
|
|
&& z >= min.getZ() && z <= max.getY();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if a vector is contained with another.
|
|
|
|
*
|
|
|
|
* @param min
|
|
|
|
* @param max
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean containedWithinBlock(Vector min, Vector max) {
|
|
|
|
return getBlockX() >= min.getBlockX() && getBlockX() <= max.getBlockX()
|
|
|
|
&& getBlockY() >= min.getBlockY() && getBlockY() <= max.getBlockY()
|
|
|
|
&& getBlockZ() >= min.getBlockZ() && getBlockZ() <= max.getBlockY();
|
|
|
|
}
|
|
|
|
|
2010-10-25 08:07:10 +00:00
|
|
|
/**
|
|
|
|
* Clamp the Y component.
|
|
|
|
*
|
|
|
|
* @param min
|
|
|
|
* @param max
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Vector clampY(int min, int max) {
|
|
|
|
return new Vector(x, Math.max(min, Math.min(max, y)), z);
|
|
|
|
}
|
|
|
|
|
2010-10-13 17:08:53 +00:00
|
|
|
/**
|
|
|
|
* 2D transformation.
|
|
|
|
*
|
|
|
|
* @param vec
|
|
|
|
* @param angle in degrees
|
|
|
|
* @param aboutX
|
|
|
|
* @param aboutY
|
|
|
|
* @param translateX
|
|
|
|
* @param translateY
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Vector transform2D(double angle,
|
|
|
|
double aboutX, double aboutZ, double translateX, double translateZ) {
|
|
|
|
angle = Math.toRadians(angle);
|
|
|
|
double x = this.x;
|
|
|
|
double z = this.z;
|
|
|
|
double x2 = x * Math.cos(angle) - z * Math.sin(angle);
|
|
|
|
double z2 = x * Math.sin(angle) + z * Math.cos(angle);
|
|
|
|
return new Vector(x2 + aboutX + translateX,
|
|
|
|
y,
|
|
|
|
z2 + aboutZ + translateZ);
|
|
|
|
}
|
|
|
|
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
|
|
|
* Get a block point from a point.
|
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @param y
|
|
|
|
* @param z
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return point
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
2010-10-13 01:03:56 +00:00
|
|
|
public static Vector toBlockPoint(double x, double y, double z) {
|
|
|
|
return new Vector((int)Math.floor(x),
|
2010-10-11 08:22:47 +00:00
|
|
|
(int)Math.floor(y),
|
|
|
|
(int)Math.floor(z));
|
|
|
|
}
|
|
|
|
|
2010-10-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* Checks if another object is equivalent.
|
|
|
|
*
|
|
|
|
* @param obj
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return whether the other object is equivalent
|
2010-10-03 19:43:30 +00:00
|
|
|
*/
|
|
|
|
@Override
|
2010-10-02 21:52:42 +00:00
|
|
|
public boolean equals(Object obj) {
|
2010-10-13 01:03:56 +00:00
|
|
|
if (!(obj instanceof Vector)) {
|
2010-10-02 21:52:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-10-13 01:03:56 +00:00
|
|
|
Vector other = (Vector)obj;
|
2010-10-11 08:22:47 +00:00
|
|
|
return other.x == this.x && other.y == this.y && other.z == this.z;
|
2010-10-04 00:29:17 +00:00
|
|
|
|
2010-10-02 21:52:42 +00:00
|
|
|
}
|
|
|
|
|
2010-10-03 19:43:30 +00:00
|
|
|
/**
|
|
|
|
* Gets the hash code.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return hash code
|
2010-10-03 19:43:30 +00:00
|
|
|
*/
|
|
|
|
@Override
|
2010-10-02 21:52:42 +00:00
|
|
|
public int hashCode() {
|
2010-10-11 16:44:22 +00:00
|
|
|
return ((new Double(x)).hashCode() >> 13) ^
|
|
|
|
((new Double(y)).hashCode() >> 7) ^
|
|
|
|
(new Double(z)).hashCode();
|
2010-10-02 21:52:42 +00:00
|
|
|
}
|
2010-10-11 18:17:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns string representation "(x, y, z)".
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "(" + x + ", " + y + ", " + z + ")";
|
|
|
|
}
|
2010-10-11 18:21:43 +00:00
|
|
|
|
|
|
|
/**
|
2010-10-13 01:03:56 +00:00
|
|
|
* Gets a BlockVector version.
|
2010-10-11 18:21:43 +00:00
|
|
|
*
|
2010-10-13 01:03:56 +00:00
|
|
|
* @return BlockVector
|
2010-10-11 18:21:43 +00:00
|
|
|
*/
|
2010-10-13 05:38:05 +00:00
|
|
|
public BlockVector toBlockVector() {
|
2010-10-13 01:03:56 +00:00
|
|
|
return new BlockVector(this);
|
2010-10-11 18:21:43 +00:00
|
|
|
}
|
2010-10-02 21:52:42 +00:00
|
|
|
}
|