Major cleanup and refactoring. Non-cuboid regions now technically supported; players now abstracted through WorldEditPlayer; use of Point across the board; command cleanup.

This commit is contained in:
sk89q
2010-10-11 01:22:47 -07:00
parent ce4b2810ff
commit 204cfc1452
9 changed files with 1233 additions and 728 deletions

View File

@@ -20,50 +20,289 @@
package com.sk89q.worldedit;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.EqualsBuilder;
/**
*
* @author Albert
*/
public final class Point<T> {
private final T x, y, z;
public final class Point {
private final double x, y, z;
/**
* Construct the Point object.
*
*
* @param x
* @param y
* @param z
*/
public Point(T x, T y, T z) {
public Point(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
/**
* Construct the Point object.
*
* @param x
* @param y
* @param z
*/
public Point(int x, int y, int z) {
this.x = (double)x;
this.y = (double)y;
this.z = (double)z;
}
/**
* Construct the Point object.
*
* @param x
* @param y
* @param z
*/
public Point(float x, float y, float z) {
this.x = (double)x;
this.y = (double)y;
this.z = (double)z;
}
/**
* Construct the Point object.
*/
public Point() {
this.x = 0;
this.y = 0;
this.z = 0;
}
/**
* @return the x
*/
public T getX() {
public double getX() {
return x;
}
/**
* @return the x
*/
public int getBlockX() {
return (int)x;
}
/**
* @return the y
*/
public T getY() {
public double getY() {
return y;
}
/**
* @return the y
*/
public int getBlockY() {
return (int)y;
}
/**
* @return the z
*/
public T getZ() {
public double getZ() {
return z;
}
/**
* @return the z
*/
public int getBlockZ() {
return (int)z;
}
/**
* Adds two points.
*
* @param other
* @return New point
*/
public Point add(Point other) {
return new Point(x + other.x, y + other.y, z + other.z);
}
/**
* Adds two points.
*
* @param other
* @return New point
*/
public Point add(double x, double y, double z) {
return new Point(this.x + x, this.y + y, this.z + z);
}
/**
* Adds two points.
*
* @param other
* @return New point
*/
public Point add(int x, int y, int z) {
return new Point(this.x + x, this.y + y, this.z + z);
}
/**
* Adds points.
*
* @param other
* @return New point
*/
public Point add(Point ... others) {
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;
}
return new Point(newX, newY, newZ);
}
/**
* Subtracts two points.
*
* @param other
* @return New point
*/
public Point subtract(Point other) {
return new Point(x - other.x, y - other.y, z - other.z);
}
/**
* Subtract two points.
*
* @param other
* @return New point
*/
public Point subtract(double x, double y, double z) {
return new Point(this.x - x, this.y - y, this.z - z);
}
/**
* Subtract two points.
*
* @param other
* @return New point
*/
public Point subtract(int x, int y, int z) {
return new Point(this.x - x, this.y - y, this.z - z);
}
/**
* Subtract points.
*
* @param other
* @return New point
*/
public Point subtract(Point ... others) {
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;
}
return new Point(newX, newY, newZ);
}
/**
* Multiplies two points.
*
* @param other
* @return New point
*/
public Point multiply(Point other) {
return new Point(x * other.x, y * other.y, z * other.z);
}
/**
* Multiply two points.
*
* @param other
* @return New point
*/
public Point multiply(double x, double y, double z) {
return new Point(this.x * x, this.y * y, this.z * z);
}
/**
* Multiply two points.
*
* @param other
* @return New point
*/
public Point multiply(int x, int y, int z) {
return new Point(this.x * x, this.y * y, this.z * z);
}
/**
* Multiply points.
*
* @param other
* @return New point
*/
public Point multiply(Point ... others) {
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;
}
return new Point(newX, newY, newZ);
}
/**
* Divide two points.
*
* @param other
* @return New point
*/
public Point divide(Point other) {
return new Point(x / other.x, y / other.y, z / other.z);
}
/**
* Divide two points.
*
* @param other
* @return New point
*/
public Point divide(double x, double y, double z) {
return new Point(this.x / x, this.y / y, this.z / z);
}
/**
* Divide two points.
*
* @param other
* @return New point
*/
public Point divide(int x, int y, int z) {
return new Point(this.x / x, this.y / y, this.z / z);
}
/**
* Get a block point from a point.
*
* @param x
* @param y
* @param z
* @return
*/
public static Point toBlockPoint(double x, double y, double z) {
return new Point((int)Math.floor(x),
(int)Math.floor(y),
(int)Math.floor(z));
}
/**
* Checks if another object is equivalent.
*
@@ -76,11 +315,7 @@ public final class Point<T> {
return false;
}
Point other = (Point)obj;
return new EqualsBuilder()
.append(x, other.x)
.append(y, other.y)
.append(z, other.z)
.isEquals();
return other.x == this.x && other.y == this.y && other.z == this.z;
}
@@ -97,5 +332,4 @@ public final class Point<T> {
append(z).
toHashCode();
}
}