2010-10-20 09:12:16 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
2012-01-05 21:38:23 +00:00
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
|
2010-10-20 09:12:16 +00:00
|
|
|
*
|
|
|
|
* 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 {
|
2013-08-04 09:51:17 +00:00
|
|
|
public static final Vector2D ZERO = new Vector2D(0, 0);
|
|
|
|
public static final Vector2D UNIT_X = new Vector2D(1, 0);
|
|
|
|
public static final Vector2D UNIT_Z = new Vector2D(0, 1);
|
|
|
|
public static final Vector2D ONE = new Vector2D(1, 1);
|
|
|
|
|
2010-10-20 09:12:16 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-01-03 00:07:05 +00:00
|
|
|
/**
|
|
|
|
* Adds two points.
|
|
|
|
*
|
|
|
|
* @param other
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector2D add(Vector2D other) {
|
|
|
|
return new Vector2D(x + other.x, z + other.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds two points.
|
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @param z
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector2D add(double x, double z) {
|
|
|
|
return new Vector2D(this.x + x, this.z + z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds two points.
|
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @param z
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector2D add(int x, int z) {
|
|
|
|
return new Vector2D(this.x + x, this.z + z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds points.
|
|
|
|
*
|
|
|
|
* @param others
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector2D add(Vector2D... others) {
|
|
|
|
double newX = x, newZ = z;
|
|
|
|
|
|
|
|
for (int i = 0; i < others.length; ++i) {
|
|
|
|
newX += others[i].x;
|
|
|
|
newZ += others[i].z;
|
|
|
|
}
|
|
|
|
return new Vector2D(newX, newZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subtracts two points.
|
|
|
|
*
|
|
|
|
* @param other
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector2D subtract(Vector2D other) {
|
|
|
|
return new Vector2D(x - other.x, z - other.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subtract two points.
|
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @param z
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector2D subtract(double x, double z) {
|
|
|
|
return new Vector2D(this.x - x, this.z - z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subtract two points.
|
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @param z
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector2D subtract(int x, int z) {
|
|
|
|
return new Vector2D(this.x - x, this.z - z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subtract points.
|
|
|
|
*
|
|
|
|
* @param others
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector2D subtract(Vector2D... others) {
|
|
|
|
double newX = x, newZ = z;
|
|
|
|
|
|
|
|
for (int i = 0; i < others.length; ++i) {
|
|
|
|
newX -= others[i].x;
|
|
|
|
newZ -= others[i].z;
|
|
|
|
}
|
|
|
|
return new Vector2D(newX, newZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-05 15:08:53 +00:00
|
|
|
* Component-wise multiplication
|
2012-01-03 00:07:05 +00:00
|
|
|
*
|
|
|
|
* @param other
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector2D multiply(Vector2D other) {
|
|
|
|
return new Vector2D(x * other.x, z * other.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-05 15:08:53 +00:00
|
|
|
* Component-wise multiplication
|
2012-01-03 00:07:05 +00:00
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @param z
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector2D multiply(double x, double z) {
|
|
|
|
return new Vector2D(this.x * x, this.z * z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-05 15:08:53 +00:00
|
|
|
* Component-wise multiplication
|
2012-01-03 00:07:05 +00:00
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @param z
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector2D multiply(int x, int z) {
|
|
|
|
return new Vector2D(this.x * x, this.z * z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-05 15:08:53 +00:00
|
|
|
* Component-wise multiplication
|
2012-01-03 00:07:05 +00:00
|
|
|
*
|
|
|
|
* @param others
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector2D multiply(Vector2D... others) {
|
|
|
|
double newX = x, newZ = z;
|
|
|
|
|
|
|
|
for (int i = 0; i < others.length; ++i) {
|
|
|
|
newX *= others[i].x;
|
|
|
|
newZ *= others[i].z;
|
|
|
|
}
|
|
|
|
return new Vector2D(newX, newZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scalar multiplication.
|
|
|
|
*
|
|
|
|
* @param n
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector2D multiply(double n) {
|
|
|
|
return new Vector2D(this.x * n, this.z * n);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scalar multiplication.
|
|
|
|
*
|
|
|
|
* @param n
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector2D multiply(float n) {
|
|
|
|
return new Vector2D(this.x * n, this.z * n);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scalar multiplication.
|
|
|
|
*
|
|
|
|
* @param n
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector2D multiply(int n) {
|
|
|
|
return new Vector2D(this.x * n, this.z * n);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-05 15:08:53 +00:00
|
|
|
* Component-wise division
|
2012-01-03 00:07:05 +00:00
|
|
|
*
|
|
|
|
* @param other
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector2D divide(Vector2D other) {
|
|
|
|
return new Vector2D(x / other.x, z / other.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-05 15:08:53 +00:00
|
|
|
* Component-wise division
|
2012-01-03 00:07:05 +00:00
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @param z
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector2D divide(double x, double z) {
|
|
|
|
return new Vector2D(this.x / x, this.z / z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-05 15:08:53 +00:00
|
|
|
* Component-wise division
|
2012-01-03 00:07:05 +00:00
|
|
|
*
|
|
|
|
* @param x
|
|
|
|
* @param z
|
|
|
|
* @return New point
|
|
|
|
*/
|
|
|
|
public Vector2D divide(int x, int z) {
|
|
|
|
return new Vector2D(this.x / x, this.z / z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scalar division.
|
|
|
|
*
|
|
|
|
* @param n
|
|
|
|
* @return new point
|
|
|
|
*/
|
|
|
|
public Vector2D divide(int n) {
|
|
|
|
return new Vector2D(x / n, z / n);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scalar division.
|
|
|
|
*
|
|
|
|
* @param n
|
|
|
|
* @return new point
|
|
|
|
*/
|
|
|
|
public Vector2D divide(double n) {
|
|
|
|
return new Vector2D(x / n, z / n);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scalar division.
|
|
|
|
*
|
|
|
|
* @param n
|
|
|
|
* @return new point
|
|
|
|
*/
|
|
|
|
public Vector2D divide(float n) {
|
|
|
|
return new Vector2D(x / n, z / n);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the length of the vector.
|
|
|
|
*
|
|
|
|
* @return length
|
|
|
|
*/
|
|
|
|
public double length() {
|
|
|
|
return Math.sqrt(x * x + z * z);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the length^2 of the vector.
|
|
|
|
*
|
|
|
|
* @return length^2
|
|
|
|
*/
|
|
|
|
public double lengthSq() {
|
|
|
|
return x * x + z * z;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the distance away from a point.
|
|
|
|
*
|
|
|
|
* @param pt
|
|
|
|
* @return distance
|
|
|
|
*/
|
|
|
|
public double distance(Vector2D pt) {
|
|
|
|
return Math.sqrt(Math.pow(pt.x - x, 2) +
|
|
|
|
Math.pow(pt.z - z, 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the distance away from a point, squared.
|
|
|
|
*
|
|
|
|
* @param pt
|
|
|
|
* @return distance
|
|
|
|
*/
|
|
|
|
public double distanceSq(Vector2D pt) {
|
|
|
|
return Math.pow(pt.x - x, 2) +
|
|
|
|
Math.pow(pt.z - z, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the normalized vector.
|
|
|
|
*
|
|
|
|
* @return vector
|
|
|
|
*/
|
|
|
|
public Vector2D normalize() {
|
|
|
|
return divide(length());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the dot product of this and another vector.
|
|
|
|
*
|
|
|
|
* @param other
|
|
|
|
* @return the dot product of this and the other vector
|
|
|
|
*/
|
|
|
|
public double dot(Vector2D other) {
|
|
|
|
return x * other.x + z * other.z;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if a vector is contained with another.
|
|
|
|
*
|
|
|
|
* @param min
|
|
|
|
* @param max
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean containedWithin(Vector2D min, Vector2D max) {
|
2012-01-08 15:27:15 +00:00
|
|
|
return x >= min.x && x <= max.x
|
|
|
|
&& z >= min.z && z <= max.z;
|
2012-01-03 00:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if a vector is contained with another.
|
|
|
|
*
|
|
|
|
* @param min
|
|
|
|
* @param max
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean containedWithinBlock(Vector2D min, Vector2D max) {
|
|
|
|
return getBlockX() >= min.getBlockX() && getBlockX() <= max.getBlockX()
|
|
|
|
&& getBlockZ() >= min.getBlockZ() && getBlockZ() <= max.getBlockZ();
|
|
|
|
}
|
|
|
|
|
2012-01-03 02:54:01 +00:00
|
|
|
/**
|
|
|
|
* Rounds all components down.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Vector2D floor() {
|
|
|
|
return new Vector2D(Math.floor(x), Math.floor(z));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rounds all components up.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Vector2D ceil() {
|
|
|
|
return new Vector2D(Math.ceil(x), Math.ceil(z));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-05 15:08:53 +00:00
|
|
|
* Rounds all components to the closest integer.<br>
|
|
|
|
*<br>
|
|
|
|
* Components < 0.5 are rounded down, otherwise up
|
2012-01-03 02:54:01 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Vector2D round() {
|
|
|
|
return new Vector2D(Math.floor(x + 0.5), Math.floor(z + 0.5));
|
|
|
|
}
|
|
|
|
|
2012-03-13 09:05:33 +00:00
|
|
|
/**
|
|
|
|
* Returns a vector with the absolute values of the components of this vector.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Vector2D positive() {
|
|
|
|
return new Vector2D(Math.abs(x), Math.abs(z));
|
|
|
|
}
|
|
|
|
|
2012-01-03 00:07:05 +00:00
|
|
|
/**
|
|
|
|
* 2D transformation.
|
|
|
|
*
|
|
|
|
* @param angle in degrees
|
2012-01-05 14:57:54 +00:00
|
|
|
* @param aboutX about which x coordinate to rotate
|
|
|
|
* @param aboutZ about which z coordinate to rotate
|
|
|
|
* @param translateX what to add after rotation
|
|
|
|
* @param translateZ what to add after rotation
|
2012-01-03 00:07:05 +00:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Vector2D transform2D(double angle,
|
|
|
|
double aboutX, double aboutZ, double translateX, double translateZ) {
|
|
|
|
angle = Math.toRadians(angle);
|
2012-01-05 14:57:54 +00:00
|
|
|
double x = this.x - aboutX;
|
|
|
|
double z = this.z - aboutZ;
|
2012-01-03 00:07:05 +00:00
|
|
|
double x2 = x * Math.cos(angle) - z * Math.sin(angle);
|
|
|
|
double z2 = x * Math.sin(angle) + z * Math.cos(angle);
|
2012-01-05 14:57:54 +00:00
|
|
|
return new Vector2D(
|
|
|
|
x2 + aboutX + translateX,
|
|
|
|
z2 + aboutZ + translateZ
|
|
|
|
);
|
2012-01-03 00:07:05 +00:00
|
|
|
}
|
|
|
|
|
2012-01-05 20:07:24 +00:00
|
|
|
public boolean isCollinearWith(Vector2D other) {
|
|
|
|
if (x == 0 && z == 0) {
|
|
|
|
// this is a zero vector
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
final double otherX = other.x;
|
|
|
|
final double otherZ = other.z;
|
|
|
|
|
|
|
|
if (otherX == 0 && otherZ == 0) {
|
|
|
|
// other is a zero vector
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((x == 0) != (otherX == 0)) return false;
|
|
|
|
if ((z == 0) != (otherZ == 0)) return false;
|
|
|
|
|
|
|
|
final double quotientX = otherX / x;
|
|
|
|
if (!Double.isNaN(quotientX)) {
|
|
|
|
return other.equals(multiply(quotientX));
|
|
|
|
}
|
|
|
|
|
|
|
|
final double quotientZ = otherZ / z;
|
|
|
|
if (!Double.isNaN(quotientZ)) {
|
|
|
|
return other.equals(multiply(quotientZ));
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new RuntimeException("This should not happen");
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2012-01-05 15:08:53 +00:00
|
|
|
|
2012-01-02 23:58:00 +00:00
|
|
|
Vector2D other = (Vector2D) 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);
|
|
|
|
}
|
2012-01-03 00:07:05 +00:00
|
|
|
|
2012-01-03 13:11:55 +00:00
|
|
|
/**
|
|
|
|
* Creates a 3D vector by adding the specified Y component to this vector.
|
|
|
|
*
|
|
|
|
* @return Vector
|
|
|
|
*/
|
|
|
|
public Vector toVector(double y) {
|
|
|
|
return new Vector(x, y, z);
|
|
|
|
}
|
|
|
|
|
2012-01-03 00:07:05 +00:00
|
|
|
/**
|
|
|
|
* Gets the minimum components of two vectors.
|
|
|
|
*
|
|
|
|
* @param v1
|
|
|
|
* @param v2
|
|
|
|
* @return minimum
|
|
|
|
*/
|
|
|
|
public static Vector2D getMinimum(Vector2D v1, Vector2D v2) {
|
|
|
|
return new Vector2D(
|
|
|
|
Math.min(v1.x, v2.x),
|
|
|
|
Math.min(v1.z, v2.z)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the maximum components of two vectors.
|
|
|
|
*
|
|
|
|
* @param v1
|
|
|
|
* @param v2
|
|
|
|
* @return maximum
|
|
|
|
*/
|
|
|
|
public static Vector2D getMaximum(Vector2D v1, Vector2D v2) {
|
|
|
|
return new Vector2D(
|
|
|
|
Math.max(v1.x, v2.x),
|
|
|
|
Math.max(v1.z, v2.z)
|
|
|
|
);
|
|
|
|
}
|
2010-10-20 09:12:16 +00:00
|
|
|
}
|