2010-10-20 09:12:16 +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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2011-02-18 23:49:50 +00:00
|
|
|
* @author sk89q
|
2010-10-20 09:12:16 +00:00
|
|
|
*/
|
|
|
|
public class Vector2D {
|
|
|
|
protected final double x, z;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the Vector2D object.
|
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @param z
|
|
|
|
*/
|
|
|
|
public Vector2D(double x, double z) {
|
|
|
|
this.x = x;
|
|
|
|
this.z = z;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the Vector2D object.
|
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @param z
|
|
|
|
*/
|
|
|
|
public Vector2D(int x, int z) {
|
2011-11-23 01:29:48 +00:00
|
|
|
this.x = (double) x;
|
|
|
|
this.z = (double) z;
|
2010-10-20 09:12:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the Vector2D object.
|
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @param z
|
|
|
|
*/
|
|
|
|
public Vector2D(float x, float z) {
|
2011-11-23 01:29:48 +00:00
|
|
|
this.x = (double) x;
|
|
|
|
this.z = (double) z;
|
2010-10-20 09:12:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the Vector2D object.
|
|
|
|
*
|
|
|
|
* @param pt
|
|
|
|
*/
|
|
|
|
public Vector2D(Vector2D pt) {
|
|
|
|
this.x = pt.x;
|
|
|
|
this.z = pt.z;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the Vector2D object.
|
|
|
|
*/
|
|
|
|
public Vector2D() {
|
|
|
|
this.x = 0;
|
|
|
|
this.z = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the x
|
|
|
|
*/
|
|
|
|
public double getX() {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the x
|
|
|
|
*/
|
|
|
|
public int getBlockX() {
|
2011-09-24 19:24:10 +00:00
|
|
|
return (int) Math.round(x);
|
2010-10-20 09:12:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set X.
|
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @return new vector
|
|
|
|
*/
|
|
|
|
public Vector2D setX(double x) {
|
|
|
|
return new Vector2D(x, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set X.
|
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @return new vector
|
|
|
|
*/
|
|
|
|
public Vector2D setX(int x) {
|
|
|
|
return new Vector2D(x, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the z
|
|
|
|
*/
|
|
|
|
public double getZ() {
|
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the z
|
|
|
|
*/
|
|
|
|
public int getBlockZ() {
|
2011-09-24 19:24:10 +00:00
|
|
|
return (int) Math.round(z);
|
2010-10-20 09:12:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set Z.
|
|
|
|
*
|
|
|
|
* @param z
|
|
|
|
* @return new vector
|
|
|
|
*/
|
|
|
|
public Vector2D setZ(double z) {
|
|
|
|
return new Vector2D(x, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set Z.
|
|
|
|
*
|
|
|
|
* @param z
|
|
|
|
* @return new vector
|
|
|
|
*/
|
|
|
|
public Vector2D setZ(int z) {
|
|
|
|
return new Vector2D(x, z);
|
|
|
|
}
|
|
|
|
|
2011-02-20 01:44:39 +00:00
|
|
|
/**
|
|
|
|
* Gets a BlockVector version.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-02-20 01:44:39 +00:00
|
|
|
* @return BlockVector
|
|
|
|
*/
|
|
|
|
public BlockVector2D toBlockVector2D() {
|
|
|
|
return new BlockVector2D(this);
|
|
|
|
}
|
|
|
|
|
2010-10-20 09:12:16 +00:00
|
|
|
/**
|
|
|
|
* Checks if another object is equivalent.
|
|
|
|
*
|
|
|
|
* @param obj
|
|
|
|
* @return whether the other object is equivalent
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (!(obj instanceof Vector2D)) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-24 19:24:10 +00:00
|
|
|
Vector other = (Vector) obj;
|
2010-10-20 09:12:16 +00:00
|
|
|
return other.x == this.x && other.z == this.z;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the hash code.
|
|
|
|
*
|
|
|
|
* @return hash code
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return ((new Double(x)).hashCode() >> 13) ^
|
|
|
|
(new Double(z)).hashCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns string representation "(x, y, z)".
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "(" + x + ", " + z + ")";
|
|
|
|
}
|
2012-01-02 23:41:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a 3D vector by adding a zero Y component to this vector.
|
|
|
|
*
|
|
|
|
* @return Vector
|
|
|
|
*/
|
|
|
|
public Vector toVector() {
|
|
|
|
return new Vector(x, 0, z);
|
|
|
|
}
|
2010-10-20 09:12:16 +00:00
|
|
|
}
|