mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-14 08:18:34 +00:00
Code clean up, add preconditions, and correct Javadocs.
This commit is contained in:
@ -28,9 +28,7 @@ import com.sk89q.worldedit.world.storage.ChunkStore;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class AbstractRegion implements Region {
|
||||
/**
|
||||
* Stores the world.
|
||||
*/
|
||||
|
||||
protected World world;
|
||||
|
||||
public AbstractRegion(World world) {
|
||||
@ -158,7 +156,7 @@ public abstract class AbstractRegion implements Region {
|
||||
/**
|
||||
* Get a list of chunks.
|
||||
*
|
||||
* @return
|
||||
* @return a set of chunks
|
||||
*/
|
||||
@Override
|
||||
public Set<Vector2D> getChunks() {
|
||||
@ -210,4 +208,5 @@ public abstract class AbstractRegion implements Region {
|
||||
|
||||
return chunks;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,13 @@
|
||||
|
||||
package com.sk89q.worldedit.regions;
|
||||
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.regions.polyhedron.Edge;
|
||||
import com.sk89q.worldedit.regions.polyhedron.Triangle;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
@ -26,13 +33,10 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.regions.polyhedron.Edge;
|
||||
import com.sk89q.worldedit.regions.polyhedron.Triangle;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class ConvexPolyhedralRegion extends AbstractRegion {
|
||||
|
||||
/**
|
||||
* Vertices that are contained in the convex hull.
|
||||
*/
|
||||
@ -71,12 +75,15 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
|
||||
/**
|
||||
* Constructs an empty mesh, containing no vertices or triangles.
|
||||
*
|
||||
* @param world
|
||||
* @param world the world
|
||||
*/
|
||||
public ConvexPolyhedralRegion(World world) {
|
||||
public ConvexPolyhedralRegion(@Nullable World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated cast {@code world} to {@link World}
|
||||
*/
|
||||
@Deprecated
|
||||
public ConvexPolyhedralRegion(LocalWorld world) {
|
||||
super(world);
|
||||
@ -116,10 +123,12 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
|
||||
/**
|
||||
* Add a vertex to the region.
|
||||
*
|
||||
* @param vertex
|
||||
* @param vertex the vertex
|
||||
* @return true, if something changed.
|
||||
*/
|
||||
public boolean addVertex(Vector vertex) {
|
||||
checkNotNull(vertex);
|
||||
|
||||
lastTriangle = null; // Probably not necessary
|
||||
|
||||
if (vertices.contains(vertex)) {
|
||||
|
@ -48,6 +48,9 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
|
||||
this(null, pos1, pos2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated cast {@code world} to {@link World}
|
||||
*/
|
||||
@Deprecated
|
||||
public CuboidRegion(LocalWorld world, Vector pos1, Vector pos2) {
|
||||
this((World) world, pos1, pos2);
|
||||
|
@ -54,6 +54,9 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
this((World) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated cast {@code world} to {@link World}
|
||||
*/
|
||||
@Deprecated
|
||||
public CylinderRegion(LocalWorld world) {
|
||||
this((World) world);
|
||||
@ -61,7 +64,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
/**
|
||||
* Construct the region.
|
||||
*
|
||||
* @param world
|
||||
* @param world the world
|
||||
*/
|
||||
public CylinderRegion(World world) {
|
||||
this(world, new Vector(), new Vector2D(), 0, 0);
|
||||
@ -76,11 +79,11 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
/**
|
||||
* Construct the region.
|
||||
*
|
||||
* @param world
|
||||
* @param center
|
||||
* @param radius
|
||||
* @param minY
|
||||
* @param maxY
|
||||
* @param world the world
|
||||
* @param center the center position
|
||||
* @param radius the radius along the X and Z axes
|
||||
* @param minY the minimum Y, inclusive
|
||||
* @param maxY the maximum Y, inclusive
|
||||
*/
|
||||
public CylinderRegion(World world, Vector center, Vector2D radius, int minY, int maxY) {
|
||||
super(world);
|
||||
@ -113,11 +116,6 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
hasY = region.hasY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the main center point of the cylinder
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Vector getCenter() {
|
||||
return center.toVector((maxY + minY) / 2);
|
||||
@ -136,7 +134,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
/**
|
||||
* Sets the main center point of the region
|
||||
*
|
||||
* @param center
|
||||
* @param center the center point
|
||||
*/
|
||||
public void setCenter(Vector2D center) {
|
||||
this.center = center;
|
||||
@ -145,7 +143,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
/**
|
||||
* Returns the radius of the cylinder
|
||||
*
|
||||
* @return
|
||||
* @return the radius along the X and Z axes
|
||||
*/
|
||||
public Vector2D getRadius() {
|
||||
return radius.subtract(0.5, 0.5);
|
||||
@ -154,7 +152,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
/**
|
||||
* Sets the radius of the cylinder
|
||||
*
|
||||
* @param radius
|
||||
* @param radius the radius along the X and Z axes
|
||||
*/
|
||||
public void setRadius(Vector2D radius) {
|
||||
this.radius = radius.add(0.5, 0.5);
|
||||
@ -163,7 +161,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
/**
|
||||
* Extends the radius to be at least the given radius
|
||||
*
|
||||
* @param minRadius
|
||||
* @param minRadius the minimum radius
|
||||
*/
|
||||
public void extendRadius(Vector2D minRadius) {
|
||||
setRadius(Vector2D.getMaximum(minRadius, getRadius()));
|
||||
@ -172,7 +170,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
/**
|
||||
* Set the minimum Y.
|
||||
*
|
||||
* @param y
|
||||
* @param y the y
|
||||
*/
|
||||
public void setMinimumY(int y) {
|
||||
hasY = true;
|
||||
@ -182,79 +180,49 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
/**
|
||||
* Se the maximum Y.
|
||||
*
|
||||
* @param y
|
||||
* @param y the y
|
||||
*/
|
||||
public void setMaximumY(int y) {
|
||||
hasY = true;
|
||||
maxY = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lower point of a region.
|
||||
*
|
||||
* @return min. point
|
||||
*/
|
||||
@Override
|
||||
public Vector getMinimumPoint() {
|
||||
return center.subtract(getRadius()).toVector(minY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the upper point of a region.
|
||||
*
|
||||
* @return max. point
|
||||
*/
|
||||
@Override
|
||||
public Vector getMaximumPoint() {
|
||||
return center.add(getRadius()).toVector(maxY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum Y value
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int getMaximumY() {
|
||||
return maxY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the minimum Y value
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int getMinimumY() {
|
||||
return minY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of blocks in the region.
|
||||
*
|
||||
* @return number of blocks
|
||||
*/
|
||||
@Override
|
||||
public int getArea() {
|
||||
return (int) Math.floor(radius.getX() * radius.getZ() * Math.PI * getHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-size.
|
||||
*
|
||||
* @return width
|
||||
*/
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return (int) (2 * radius.getX());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Y-size.
|
||||
*
|
||||
* @return height
|
||||
*/
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return maxY - minY + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Z-size.
|
||||
*
|
||||
* @return length
|
||||
*/
|
||||
@Override
|
||||
public int getLength() {
|
||||
return (int) (2 * radius.getZ());
|
||||
}
|
||||
@ -288,6 +256,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
* @param changes array/arguments with multiple related changes
|
||||
* @throws RegionOperationException
|
||||
*/
|
||||
@Override
|
||||
public void expand(Vector... changes) throws RegionOperationException {
|
||||
center = center.add(calculateDiff2D(changes));
|
||||
radius = radius.add(calculateChanges2D(changes));
|
||||
@ -307,6 +276,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
* @param changes array/arguments with multiple related changes
|
||||
* @throws RegionOperationException
|
||||
*/
|
||||
@Override
|
||||
public void contract(Vector... changes) throws RegionOperationException {
|
||||
center = center.subtract(calculateDiff2D(changes));
|
||||
Vector2D newRadius = radius.subtract(calculateChanges2D(changes));
|
||||
@ -334,6 +304,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
/**
|
||||
* Checks to see if a point is inside this region.
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(Vector pt) {
|
||||
final int blockY = pt.getBlockY();
|
||||
if (blockY < minY || blockY > maxY) {
|
||||
@ -347,7 +318,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
/**
|
||||
* Sets the height of the cylinder to fit the specified Y.
|
||||
*
|
||||
* @param y
|
||||
* @param y the y value
|
||||
* @return true if the area was expanded
|
||||
*/
|
||||
public boolean setY(int y) {
|
||||
@ -393,6 +364,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
return center + " - " + radius + "(" + minY + ", " + maxY + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CylinderRegion clone() {
|
||||
return (CylinderRegion) super.clone();
|
||||
}
|
||||
|
@ -30,23 +30,25 @@ import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TomyLobo
|
||||
* Represents an ellipsoid region.
|
||||
*/
|
||||
public class EllipsoidRegion extends AbstractRegion {
|
||||
|
||||
/**
|
||||
* Stores the center.
|
||||
*/
|
||||
private Vector center;
|
||||
|
||||
/**
|
||||
* Stores the radii plus 0.5 on each axis.
|
||||
*/
|
||||
private Vector radius;
|
||||
|
||||
/**
|
||||
* Construct a new instance of this ellipsoid region.
|
||||
*
|
||||
* @param pos1
|
||||
* @param pos2
|
||||
* @param pos1 the first position
|
||||
* @param pos2 the second position
|
||||
*/
|
||||
public EllipsoidRegion(Vector pos1, Vector pos2) {
|
||||
this(null, pos1, pos2);
|
||||
@ -60,9 +62,9 @@ public class EllipsoidRegion extends AbstractRegion {
|
||||
/**
|
||||
* Construct a new instance of this ellipsoid region.
|
||||
*
|
||||
* @param world
|
||||
* @param center
|
||||
* @param radius
|
||||
* @param world the world
|
||||
* @param center the center
|
||||
* @param radius the radius
|
||||
*/
|
||||
public EllipsoidRegion(World world, Vector center, Vector radius) {
|
||||
super(world);
|
||||
@ -74,56 +76,32 @@ public class EllipsoidRegion extends AbstractRegion {
|
||||
this(ellipsoidRegion.world, ellipsoidRegion.center, ellipsoidRegion.getRadius());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lower point of the ellipsoid.
|
||||
*
|
||||
* @return min point
|
||||
*/
|
||||
@Override
|
||||
public Vector getMinimumPoint() {
|
||||
return center.subtract(getRadius());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the upper point of the ellipsoid.
|
||||
*
|
||||
* @return max point
|
||||
*/
|
||||
@Override
|
||||
public Vector getMaximumPoint() {
|
||||
return center.add(getRadius());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of blocks in the region.
|
||||
*
|
||||
* @return number of blocks
|
||||
*/
|
||||
@Override
|
||||
public int getArea() {
|
||||
return (int) Math.floor((4.0 / 3.0) * Math.PI * radius.getX() * radius.getY() * radius.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-size.
|
||||
*
|
||||
* @return width
|
||||
*/
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return (int) (2 * radius.getX());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Y-size.
|
||||
*
|
||||
* @return height
|
||||
*/
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return (int) (2 * radius.getY());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Z-size.
|
||||
*
|
||||
* @return length
|
||||
*/
|
||||
@Override
|
||||
public int getLength() {
|
||||
return (int) (2 * radius.getZ());
|
||||
}
|
||||
@ -148,23 +126,13 @@ public class EllipsoidRegion extends AbstractRegion {
|
||||
return total.divide(2).floor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand the region.
|
||||
*
|
||||
* @param changes array/arguments with multiple related changes
|
||||
* @throws RegionOperationException
|
||||
*/
|
||||
@Override
|
||||
public void expand(Vector... changes) throws RegionOperationException {
|
||||
center = center.add(calculateDiff(changes));
|
||||
radius = radius.add(calculateChanges(changes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Contract the region.
|
||||
*
|
||||
* @param changes array/arguments with multiple related changes
|
||||
* @throws RegionOperationException
|
||||
*/
|
||||
@Override
|
||||
public void contract(Vector... changes) throws RegionOperationException {
|
||||
center = center.subtract(calculateDiff(changes));
|
||||
Vector newRadius = radius.subtract(calculateChanges(changes));
|
||||
@ -189,35 +157,31 @@ public class EllipsoidRegion extends AbstractRegion {
|
||||
/**
|
||||
* Set the center.
|
||||
*
|
||||
* @param center
|
||||
* @param center the center
|
||||
*/
|
||||
public void setCenter(Vector center) {
|
||||
this.center = center;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the radiuses.
|
||||
* Get the radii.
|
||||
*
|
||||
* @return radiuses
|
||||
* @return radii
|
||||
*/
|
||||
public Vector getRadius() {
|
||||
return radius.subtract(0.5, 0.5, 0.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set radiuses.
|
||||
* Set the radii.
|
||||
*
|
||||
* @param radius
|
||||
* @param radius the radius
|
||||
*/
|
||||
public void setRadius(Vector radius) {
|
||||
this.radius = radius.add(0.5, 0.5, 0.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of chunks that this region is within.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Set<Vector2D> getChunks() {
|
||||
final Set<Vector2D> chunks = new HashSet<Vector2D>();
|
||||
|
||||
@ -241,11 +205,7 @@ public class EllipsoidRegion extends AbstractRegion {
|
||||
return chunks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true based on whether the region contains the point,
|
||||
*
|
||||
* @param pt
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(Vector pt) {
|
||||
return pt.subtract(center).divide(radius).lengthSq() <= 1;
|
||||
}
|
||||
@ -265,7 +225,9 @@ public class EllipsoidRegion extends AbstractRegion {
|
||||
setRadius(Vector.getMaximum(minRadius, getRadius()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EllipsoidRegion clone() {
|
||||
return (EllipsoidRegion) super.clone();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,16 +26,21 @@ public interface FlatRegion extends Region {
|
||||
/**
|
||||
* Gets the minimum Y value
|
||||
*
|
||||
* @return
|
||||
* @return the Y value
|
||||
*/
|
||||
public int getMinimumY();
|
||||
|
||||
/**
|
||||
* Gets the maximum Y value
|
||||
*
|
||||
* @return
|
||||
* @return the Y value
|
||||
*/
|
||||
public int getMaximumY();
|
||||
|
||||
/**
|
||||
* Get this region as an iterable flat region.
|
||||
*
|
||||
* @return a flat region iterable
|
||||
*/
|
||||
public Iterable<Vector2D> asFlatRegion();
|
||||
}
|
||||
|
@ -19,13 +19,15 @@
|
||||
|
||||
package com.sk89q.worldedit.regions.iterator;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.regions.FlatRegion;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class FlatRegion3DIterator implements Iterator<BlockVector> {
|
||||
|
||||
private Iterator<Vector2D> flatIterator;
|
||||
@ -36,6 +38,9 @@ public class FlatRegion3DIterator implements Iterator<BlockVector> {
|
||||
private int nextY;
|
||||
|
||||
public FlatRegion3DIterator(FlatRegion region, Iterator<Vector2D> flatIterator) {
|
||||
checkNotNull(region);
|
||||
checkNotNull(flatIterator);
|
||||
|
||||
this.flatIterator = flatIterator;
|
||||
this.minY = region.getMinimumY();
|
||||
this.maxY = region.getMaximumY();
|
||||
@ -80,4 +85,5 @@ public class FlatRegion3DIterator implements Iterator<BlockVector> {
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,12 +19,14 @@
|
||||
|
||||
package com.sk89q.worldedit.regions.iterator;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class FlatRegionIterator implements Iterator<Vector2D> {
|
||||
|
||||
private Region region;
|
||||
@ -36,6 +38,8 @@ public class FlatRegionIterator implements Iterator<Vector2D> {
|
||||
private int maxZ;
|
||||
|
||||
public FlatRegionIterator(Region region) {
|
||||
checkNotNull(region);
|
||||
|
||||
this.region = region;
|
||||
|
||||
Vector min = region.getMinimumPoint();
|
||||
@ -95,4 +99,5 @@ public class FlatRegionIterator implements Iterator<Vector2D> {
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,13 +19,16 @@
|
||||
|
||||
package com.sk89q.worldedit.regions.iterator;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class RegionIterator implements Iterator<BlockVector> {
|
||||
|
||||
private final Region region;
|
||||
private final int maxX;
|
||||
private final int maxY;
|
||||
@ -36,6 +39,8 @@ public class RegionIterator implements Iterator<BlockVector> {
|
||||
private int nextZ;
|
||||
|
||||
public RegionIterator(Region region) {
|
||||
checkNotNull(region);
|
||||
|
||||
this.region = region;
|
||||
|
||||
Vector max = region.getMaximumPoint();
|
||||
@ -51,6 +56,7 @@ public class RegionIterator implements Iterator<BlockVector> {
|
||||
forward();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return nextX != Integer.MIN_VALUE;
|
||||
}
|
||||
@ -61,6 +67,7 @@ public class RegionIterator implements Iterator<BlockVector> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockVector next() {
|
||||
if (!hasNext()) throw new java.util.NoSuchElementException();
|
||||
|
||||
@ -89,7 +96,9 @@ public class RegionIterator implements Iterator<BlockVector> {
|
||||
nextX = Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,11 +21,17 @@ package com.sk89q.worldedit.regions.polyhedron;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class Edge {
|
||||
|
||||
private final Vector start;
|
||||
private final Vector end;
|
||||
|
||||
public Edge(Vector start, Vector end) {
|
||||
checkNotNull(start);
|
||||
checkNotNull(end);
|
||||
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
@ -60,15 +66,25 @@ public class Edge {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a triangle from { this.start, this.end, vertex }
|
||||
*
|
||||
* @param vertex The 3rd vertex for the triangle
|
||||
* Create a triangle from { this.start, this.end, vertex }
|
||||
*
|
||||
* @param vertex the 3rd vertex for the triangle
|
||||
* @return a triangle
|
||||
*/
|
||||
public Triangle createTriangle(Vector vertex) {
|
||||
checkNotNull(vertex);
|
||||
return new Triangle(this.start, this.end, vertex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a triangle from { this.start, vertex, this.end }.
|
||||
*
|
||||
* @param vertex the second vertex
|
||||
* @return a new triangle
|
||||
*/
|
||||
public Triangle createTriangle2(Vector vertex) {
|
||||
checkNotNull(vertex);
|
||||
return new Triangle(this.start, vertex, this.end);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,11 @@ package com.sk89q.worldedit.regions.polyhedron;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class Triangle {
|
||||
|
||||
private String tag = "Triangle";
|
||||
private final Vector[] vertices;
|
||||
private final Vector normal;
|
||||
private final double b;
|
||||
@ -29,11 +33,15 @@ public class Triangle {
|
||||
/**
|
||||
* Constructs a triangle with the given vertices (counter-clockwise)
|
||||
*
|
||||
* @param v0
|
||||
* @param v1
|
||||
* @param v2
|
||||
* @param v0 first vertex
|
||||
* @param v1 second vertex
|
||||
* @param v2 third vertex
|
||||
*/
|
||||
public Triangle(Vector v0, Vector v1, Vector v2) {
|
||||
checkNotNull(v0);
|
||||
checkNotNull(v1);
|
||||
checkNotNull(v2);
|
||||
|
||||
vertices = new Vector[] { v0, v1, v2 };
|
||||
|
||||
this.normal = v1.subtract(v0).cross(v2.subtract(v0)).normalize();
|
||||
@ -66,30 +74,40 @@ public class Triangle {
|
||||
/**
|
||||
* Returns whether the given point is above the plane the triangle is in.
|
||||
*
|
||||
* @param pt
|
||||
* @return
|
||||
* @param pt the point to test
|
||||
* @return true if the point is below
|
||||
*/
|
||||
public boolean below(Vector pt) {
|
||||
checkNotNull(pt);
|
||||
return normal.dot(pt) < b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given point is above the plane the triangle is in.
|
||||
*
|
||||
* @param pt
|
||||
* @return
|
||||
* @param pt the point to test
|
||||
* @return true if the point is above
|
||||
*/
|
||||
public boolean above(Vector pt) {
|
||||
checkNotNull(pt);
|
||||
return normal.dot(pt) > b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the triangle's tag.
|
||||
*
|
||||
* @param tag the tag
|
||||
* @return this object
|
||||
*/
|
||||
public Triangle tag(String tag) {
|
||||
checkNotNull(tag);
|
||||
this.tag = tag;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return tag+"(" + this.vertices[0] + "," + this.vertices[1] + "," + this.vertices[2] + ")";
|
||||
}
|
||||
String tag = "Triangle";
|
||||
public Triangle tag(String tag) {
|
||||
this.tag = tag;
|
||||
return this;
|
||||
return tag + "(" + this.vertices[0] + "," + this.vertices[1] + "," + this.vertices[2] + ")";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,13 +19,17 @@
|
||||
|
||||
package com.sk89q.worldedit.regions.selector;
|
||||
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionPolygonEvent;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
|
||||
import com.sk89q.worldedit.regions.ConvexPolyhedralRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
@ -33,7 +37,11 @@ import com.sk89q.worldedit.regions.polyhedron.Triangle;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -46,6 +54,9 @@ public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.
|
||||
private final ConvexPolyhedralRegion region;
|
||||
private BlockVector pos1;
|
||||
|
||||
/**
|
||||
* @deprecated cast {@code world} to {@link World}
|
||||
*/
|
||||
@Deprecated
|
||||
public ConvexPolyhedralRegionSelector(@Nullable LocalWorld world, int maxVertices) {
|
||||
this((World) world, maxVertices);
|
||||
|
@ -50,6 +50,9 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
|
||||
this((World) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated cast {@code world} to {@link World}
|
||||
*/
|
||||
@Deprecated
|
||||
public CuboidRegionSelector(@Nullable LocalWorld world) {
|
||||
this((World) world);
|
||||
@ -92,6 +95,9 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
|
||||
region.setPos2(pos2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated cast {@code world} to {@link World}
|
||||
*/
|
||||
@Deprecated
|
||||
public CuboidRegionSelector(@Nullable LocalWorld world, Vector pos1, Vector pos2) {
|
||||
this((World) world, pos1, pos2);
|
||||
@ -106,7 +112,6 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
|
||||
*/
|
||||
public CuboidRegionSelector(@Nullable World world, Vector pos1, Vector pos2) {
|
||||
this(world);
|
||||
checkNotNull(world);
|
||||
checkNotNull(pos1);
|
||||
checkNotNull(pos2);
|
||||
this.pos1 = pos1.toBlockVector();
|
||||
|
@ -47,6 +47,9 @@ public class CylinderRegionSelector extends com.sk89q.worldedit.regions.Cylinder
|
||||
format.setMaximumFractionDigits(3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated cast {@code world} to {@link World}
|
||||
*/
|
||||
@Deprecated
|
||||
public CylinderRegionSelector(@Nullable LocalWorld world) {
|
||||
this((World) world);
|
||||
|
@ -50,6 +50,9 @@ public class EllipsoidRegionSelector extends com.sk89q.worldedit.regions.Ellipso
|
||||
this((World) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated cast {@code world} to {@link World}
|
||||
*/
|
||||
@Deprecated
|
||||
public EllipsoidRegionSelector(@Nullable LocalWorld world) {
|
||||
this((World) world);
|
||||
@ -76,7 +79,7 @@ public class EllipsoidRegionSelector extends com.sk89q.worldedit.regions.Ellipso
|
||||
|
||||
region = new EllipsoidRegion(ellipsoidRegionSelector.getIncompleteRegion());
|
||||
} else {
|
||||
Region oldRegion = null;
|
||||
Region oldRegion;
|
||||
try {
|
||||
oldRegion = oldSelector.getRegion();
|
||||
} catch (IncompleteRegionException e) {
|
||||
|
@ -53,6 +53,9 @@ public class Polygonal2DRegionSelector extends com.sk89q.worldedit.regions.Polyg
|
||||
this(world, 50);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated cast {@code world} to {@link World}
|
||||
*/
|
||||
@Deprecated
|
||||
public Polygonal2DRegionSelector(@Nullable LocalWorld world, int maxPoints) {
|
||||
this((World) world, maxPoints);
|
||||
@ -108,6 +111,9 @@ public class Polygonal2DRegionSelector extends com.sk89q.worldedit.regions.Polyg
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated cast {@code world} to {@link World}
|
||||
*/
|
||||
@Deprecated
|
||||
public Polygonal2DRegionSelector(@Nullable LocalWorld world, List<BlockVector2D> points, int minY, int maxY) {
|
||||
this((World) world, points, minY, maxY);
|
||||
|
@ -29,10 +29,9 @@ import com.sk89q.worldedit.world.biome.BaseBiome;
|
||||
/**
|
||||
* Generates solid and hollow shapes according to materials returned by the
|
||||
* {@link #getBiome} method.
|
||||
*
|
||||
* @author TomyLobo
|
||||
*/
|
||||
public abstract class ArbitraryBiomeShape {
|
||||
|
||||
private final FlatRegion extent;
|
||||
private int cacheOffsetX;
|
||||
private int cacheOffsetZ;
|
||||
@ -192,4 +191,5 @@ public abstract class ArbitraryBiomeShape {
|
||||
return this == o;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -30,10 +30,9 @@ import com.sk89q.worldedit.regions.Region;
|
||||
/**
|
||||
* Generates solid and hollow shapes according to materials returned by the
|
||||
* {@link #getMaterial} method.
|
||||
*
|
||||
* @author TomyLobo
|
||||
*/
|
||||
public abstract class ArbitraryShape {
|
||||
public abstract class ArbitraryShape
|
||||
{
|
||||
protected final Region extent;
|
||||
private int cacheOffsetX;
|
||||
private int cacheOffsetY;
|
||||
@ -208,4 +207,5 @@ public abstract class ArbitraryShape {
|
||||
|
||||
return affected;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,10 +26,9 @@ import com.sk89q.worldedit.regions.Region;
|
||||
/**
|
||||
* Generates solid and hollow shapes according to materials returned by the
|
||||
* {@link #getMaterial} method.
|
||||
*
|
||||
* @author TomyLobo
|
||||
*/
|
||||
public class RegionShape extends ArbitraryShape {
|
||||
|
||||
public RegionShape(Region extent) {
|
||||
super(extent);
|
||||
}
|
||||
@ -42,4 +41,5 @@ public class RegionShape extends ArbitraryShape {
|
||||
|
||||
return defaultMaterial;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.ExpressionEnvironment;
|
||||
|
||||
public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
|
||||
|
||||
private final Vector unit;
|
||||
private final Vector zero2;
|
||||
private Vector current = new Vector();
|
||||
@ -78,4 +79,5 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
|
||||
public void setCurrentBlock(Vector current) {
|
||||
this.current = current;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user