Add support for expand with reverse dir for Cylinder & Ellipsoid
This commit is contained in:
@@ -213,39 +213,28 @@ public class CylinderRegion extends AbstractRegion {
|
||||
return (int) (2 * radius.getZ());
|
||||
}
|
||||
|
||||
private Vector2D getTotalXZChanges(Vector... changes) throws RegionOperationException {
|
||||
private Vector2D calculateDiff2D(Vector... changes) throws RegionOperationException {
|
||||
Vector2D diff = new Vector2D();
|
||||
Vector2D total = new Vector2D();
|
||||
for (Vector change : changes) {
|
||||
diff = diff.add(change.toVector2D());
|
||||
}
|
||||
|
||||
if ((diff.getBlockX() & 1) + (diff.getBlockZ() & 1) != 0) {
|
||||
throw new RegionOperationException("Cylinders changes must be even for each horizontal dimensions.");
|
||||
}
|
||||
|
||||
return diff.divide(2).floor();
|
||||
}
|
||||
|
||||
private Vector2D calculateChanges2D(Vector... changes) {
|
||||
Vector2D total = new Vector2D();
|
||||
for (Vector change : changes) {
|
||||
total = total.add(change.toVector2D().positive());
|
||||
}
|
||||
|
||||
if (diff.getBlockX() != 0 || diff.getBlockZ() != 0) {
|
||||
throw new RegionOperationException("Cylinders changes must be equal for both directions of each horizontal dimensions.");
|
||||
}
|
||||
|
||||
return total.divide(2).floor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand the region.
|
||||
*
|
||||
* @param change
|
||||
*/
|
||||
public void expand(Vector change) throws RegionOperationException {
|
||||
if (change.getBlockX() != 0 || change.getBlockZ() != 0) {
|
||||
throw new RegionOperationException("Cylinders can only be expanded vertically.");
|
||||
}
|
||||
|
||||
int changeY = change.getBlockY();
|
||||
if (changeY > 0) {
|
||||
maxY += changeY;
|
||||
} else {
|
||||
minY += changeY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand the region.
|
||||
* Expand the region.
|
||||
@@ -254,27 +243,15 @@ public class CylinderRegion extends AbstractRegion {
|
||||
* @throws RegionOperationException
|
||||
*/
|
||||
public void expand(Vector... changes) throws RegionOperationException {
|
||||
radius = radius.add(getTotalXZChanges(changes));
|
||||
setCenter(getCenter().add(calculateDiff2D(changes).toVector()));
|
||||
radius = radius.add(calculateChanges2D(changes));
|
||||
for (Vector change : changes) {
|
||||
expand(new Vector(0, change.getBlockY(), 0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Contract the region.
|
||||
*
|
||||
* @param change
|
||||
*/
|
||||
public void contract(Vector change) throws RegionOperationException {
|
||||
if (change.getBlockX() != 0 || change.getBlockZ() != 0) {
|
||||
throw new RegionOperationException("Cylinders can only be expanded vertically.");
|
||||
}
|
||||
|
||||
int changeY = change.getBlockY();
|
||||
if (changeY > 0) {
|
||||
minY += changeY;
|
||||
} else {
|
||||
maxY += changeY;
|
||||
int changeY = change.getBlockY();
|
||||
if (changeY > 0) {
|
||||
maxY += changeY;
|
||||
} else {
|
||||
minY += changeY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,10 +262,16 @@ public class CylinderRegion extends AbstractRegion {
|
||||
* @throws RegionOperationException
|
||||
*/
|
||||
public void contract(Vector... changes) throws RegionOperationException {
|
||||
Vector2D newRadius = radius.subtract(getTotalXZChanges(changes));
|
||||
setCenter(getCenter().subtract(calculateDiff2D(changes).toVector()));
|
||||
Vector2D newRadius = radius.subtract(calculateChanges2D(changes));
|
||||
radius = Vector2D.getMaximum(new Vector2D(1.5, 1.5), newRadius);
|
||||
for (Vector change : changes) {
|
||||
contract(new Vector(0, change.getBlockY(), 0));
|
||||
int changeY = change.getBlockY();
|
||||
if (changeY > 0) {
|
||||
minY += changeY;
|
||||
} else {
|
||||
maxY += changeY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -120,30 +120,26 @@ public class EllipsoidRegion extends AbstractRegion {
|
||||
return (int) (2 * radius.getZ());
|
||||
}
|
||||
|
||||
private Vector getTotalChanges(Vector... changes) throws RegionOperationException {
|
||||
Vector diff = new Vector();
|
||||
private Vector calculateDiff(Vector... changes) throws RegionOperationException {
|
||||
Vector diff = new Vector().add(changes);
|
||||
|
||||
if ((diff.getBlockX() & 1) + (diff.getBlockY() & 1) + (diff.getBlockZ() & 1) != 0) {
|
||||
throw new RegionOperationException(
|
||||
"Ellipsoid changes must be even for each dimensions.");
|
||||
}
|
||||
|
||||
return diff.divide(2).floor();
|
||||
}
|
||||
|
||||
private Vector calculateChanges(Vector... changes) {
|
||||
Vector total = new Vector();
|
||||
for (Vector change : changes) {
|
||||
diff = diff.add(change);
|
||||
total = total.add(change.positive());
|
||||
}
|
||||
|
||||
if (diff.getBlockX() != 0 || diff.getBlockY() != 0 || diff.getBlockZ() != 0) {
|
||||
throw new RegionOperationException(
|
||||
"Ellipsoid changes must be equal for both directions of each dimensions.");
|
||||
}
|
||||
|
||||
return total.divide(2).floor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Expands the ellipsoid in a direction.
|
||||
*
|
||||
* @param change
|
||||
*/
|
||||
public void expand(Vector change) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand the region.
|
||||
*
|
||||
@@ -151,15 +147,8 @@ public class EllipsoidRegion extends AbstractRegion {
|
||||
* @throws RegionOperationException
|
||||
*/
|
||||
public void expand(Vector... changes) throws RegionOperationException {
|
||||
radius = radius.add(getTotalChanges(changes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Contracts the ellipsoid in a direction.
|
||||
*
|
||||
* @param change
|
||||
*/
|
||||
public void contract(Vector change) {
|
||||
center = center.add(calculateDiff(changes));
|
||||
radius = radius.add(calculateChanges(changes));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,7 +158,8 @@ public class EllipsoidRegion extends AbstractRegion {
|
||||
* @throws RegionOperationException
|
||||
*/
|
||||
public void contract(Vector... changes) throws RegionOperationException {
|
||||
Vector newRadius = radius.subtract(getTotalChanges(changes));
|
||||
center = center.subtract(calculateDiff(changes));
|
||||
Vector newRadius = radius.subtract(calculateChanges(changes));
|
||||
radius = Vector.getMaximum(new Vector(1.5, 1.5, 1.5), newRadius);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user