mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-16 03:34:03 +00:00
Refactor vector system to be cleaner
- Move Vector, etc. into `.math` package - Drop many methods that will be auto-promoted anyways, eg. with `divide(int)` and `divide(double)` the first is now gone. - Take Block vectors into their own class hierarchy - Make it clear throughout the API what takes blockvectors - many more improvements
This commit is contained in:
@@ -19,10 +19,9 @@
|
||||
|
||||
package com.sk89q.worldedit.regions;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.regions.iterator.RegionIterator;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.storage.ChunkStore;
|
||||
@@ -42,8 +41,8 @@ public abstract class AbstractRegion implements Region {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getCenter() {
|
||||
return getMinimumPoint().add(getMaximumPoint()).divide(2);
|
||||
public Vector3 getCenter() {
|
||||
return getMinimumPoint().add(getMaximumPoint()).toVector3().divide(2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,7 +51,7 @@ public abstract class AbstractRegion implements Region {
|
||||
* @return iterator of points inside the region
|
||||
*/
|
||||
@Override
|
||||
public Iterator<BlockVector> iterator() {
|
||||
public Iterator<BlockVector3> iterator() {
|
||||
return new RegionIterator(this);
|
||||
}
|
||||
|
||||
@@ -67,7 +66,7 @@ public abstract class AbstractRegion implements Region {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shift(Vector change) throws RegionOperationException {
|
||||
public void shift(BlockVector3 change) throws RegionOperationException {
|
||||
expand(change);
|
||||
contract(change);
|
||||
}
|
||||
@@ -82,20 +81,20 @@ public abstract class AbstractRegion implements Region {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockVector2D> polygonize(int maxPoints) {
|
||||
public List<BlockVector2> polygonize(int maxPoints) {
|
||||
if (maxPoints >= 0 && maxPoints < 4) {
|
||||
throw new IllegalArgumentException("Cannot polygonize an AbstractRegion with no overridden polygonize method into less than 4 points.");
|
||||
}
|
||||
|
||||
final BlockVector min = getMinimumPoint().toBlockVector();
|
||||
final BlockVector max = getMaximumPoint().toBlockVector();
|
||||
final BlockVector3 min = getMinimumPoint();
|
||||
final BlockVector3 max = getMaximumPoint();
|
||||
|
||||
final List<BlockVector2D> points = new ArrayList<>(4);
|
||||
final List<BlockVector2> points = new ArrayList<>(4);
|
||||
|
||||
points.add(new BlockVector2D(min.getX(), min.getZ()));
|
||||
points.add(new BlockVector2D(min.getX(), max.getZ()));
|
||||
points.add(new BlockVector2D(max.getX(), max.getZ()));
|
||||
points.add(new BlockVector2D(max.getX(), min.getZ()));
|
||||
points.add(new BlockVector2(min.getX(), min.getZ()));
|
||||
points.add(new BlockVector2(min.getX(), max.getZ()));
|
||||
points.add(new BlockVector2(max.getX(), max.getZ()));
|
||||
points.add(new BlockVector2(max.getX(), min.getZ()));
|
||||
|
||||
return points;
|
||||
}
|
||||
@@ -107,12 +106,12 @@ public abstract class AbstractRegion implements Region {
|
||||
*/
|
||||
@Override
|
||||
public int getArea() {
|
||||
Vector min = getMinimumPoint();
|
||||
Vector max = getMaximumPoint();
|
||||
BlockVector3 min = getMinimumPoint();
|
||||
BlockVector3 max = getMaximumPoint();
|
||||
|
||||
return (int)((max.getX() - min.getX() + 1) *
|
||||
(max.getY() - min.getY() + 1) *
|
||||
(max.getZ() - min.getZ() + 1));
|
||||
return (max.getX() - min.getX() + 1) *
|
||||
(max.getY() - min.getY() + 1) *
|
||||
(max.getZ() - min.getZ() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,10 +121,10 @@ public abstract class AbstractRegion implements Region {
|
||||
*/
|
||||
@Override
|
||||
public int getWidth() {
|
||||
Vector min = getMinimumPoint();
|
||||
Vector max = getMaximumPoint();
|
||||
BlockVector3 min = getMinimumPoint();
|
||||
BlockVector3 max = getMaximumPoint();
|
||||
|
||||
return (int) (max.getX() - min.getX() + 1);
|
||||
return max.getX() - min.getX() + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,10 +134,10 @@ public abstract class AbstractRegion implements Region {
|
||||
*/
|
||||
@Override
|
||||
public int getHeight() {
|
||||
Vector min = getMinimumPoint();
|
||||
Vector max = getMaximumPoint();
|
||||
BlockVector3 min = getMinimumPoint();
|
||||
BlockVector3 max = getMaximumPoint();
|
||||
|
||||
return (int) (max.getY() - min.getY() + 1);
|
||||
return max.getY() - min.getY() + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,10 +147,10 @@ public abstract class AbstractRegion implements Region {
|
||||
*/
|
||||
@Override
|
||||
public int getLength() {
|
||||
Vector min = getMinimumPoint();
|
||||
Vector max = getMaximumPoint();
|
||||
BlockVector3 min = getMinimumPoint();
|
||||
BlockVector3 max = getMaximumPoint();
|
||||
|
||||
return (int) (max.getZ() - min.getZ() + 1);
|
||||
return max.getZ() - min.getZ() + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,21 +159,21 @@ public abstract class AbstractRegion implements Region {
|
||||
* @return a set of chunks
|
||||
*/
|
||||
@Override
|
||||
public Set<Vector2D> getChunks() {
|
||||
final Set<Vector2D> chunks = new HashSet<>();
|
||||
public Set<BlockVector2> getChunks() {
|
||||
final Set<BlockVector2> chunks = new HashSet<>();
|
||||
|
||||
final Vector min = getMinimumPoint();
|
||||
final Vector max = getMaximumPoint();
|
||||
final BlockVector3 min = getMinimumPoint();
|
||||
final BlockVector3 max = getMaximumPoint();
|
||||
|
||||
final int minY = min.getBlockY();
|
||||
|
||||
for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
|
||||
for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
|
||||
if (!contains(new Vector(x, minY, z))) {
|
||||
if (!contains(new BlockVector3(x, minY, z))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
chunks.add(new BlockVector2D(
|
||||
chunks.add(new BlockVector2(
|
||||
x >> ChunkStore.CHUNK_SHIFTS,
|
||||
z >> ChunkStore.CHUNK_SHIFTS
|
||||
));
|
||||
@@ -185,20 +184,20 @@ public abstract class AbstractRegion implements Region {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Vector> getChunkCubes() {
|
||||
final Set<Vector> chunks = new HashSet<>();
|
||||
public Set<BlockVector3> getChunkCubes() {
|
||||
final Set<BlockVector3> chunks = new HashSet<>();
|
||||
|
||||
final Vector min = getMinimumPoint();
|
||||
final Vector max = getMaximumPoint();
|
||||
final BlockVector3 min = getMinimumPoint();
|
||||
final BlockVector3 max = getMaximumPoint();
|
||||
|
||||
for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
|
||||
for (int y = min.getBlockY(); y <= max.getBlockY(); ++y) {
|
||||
for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
|
||||
if (!contains(new Vector(x, y, z))) {
|
||||
if (!contains(new BlockVector3(x, y, z))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
chunks.add(new BlockVector(
|
||||
chunks.add(new BlockVector3(
|
||||
x >> ChunkStore.CHUNK_SHIFTS,
|
||||
y >> ChunkStore.CHUNK_SHIFTS,
|
||||
z >> ChunkStore.CHUNK_SHIFTS
|
||||
|
Reference in New Issue
Block a user