Implement contract/expand(Vector...) for Cylinder & Ellipsoid

This commit is contained in:
aumgn
2012-03-13 11:00:40 +01:00
committed by TomyLobo
parent 0346228310
commit 1359a7fada
2 changed files with 80 additions and 0 deletions

View File

@ -120,6 +120,22 @@ public class EllipsoidRegion extends AbstractRegion {
return (int) (2 * radius.getZ());
}
private Vector getTotalChanges(Vector... changes) throws RegionOperationException {
Vector diff = new Vector();
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.
*
@ -128,6 +144,16 @@ public class EllipsoidRegion extends AbstractRegion {
public void expand(Vector change) {
}
/**
* Expand the region.
*
* @param changes array/arguments with multiple related changes
* @throws RegionOperationException
*/
public void expand(Vector... changes) throws RegionOperationException {
radius = radius.add(getTotalChanges(changes));
}
/**
* Contracts the ellipsoid in a direction.
*
@ -136,6 +162,17 @@ public class EllipsoidRegion extends AbstractRegion {
public void contract(Vector change) {
}
/**
* Contract the region.
*
* @param changes array/arguments with multiple related changes
* @throws RegionOperationException
*/
public void contract(Vector... changes) throws RegionOperationException {
Vector newRadius = radius.subtract(getTotalChanges(changes));
radius = Vector.getMaximum(new Vector(1.5, 1.5, 1.5), newRadius);
}
@Override
public void shift(Vector change) throws RegionOperationException {
center = center.add(change);