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

Dieser Commit ist enthalten in:
aumgn 2012-03-13 11:00:40 +01:00 committet von TomyLobo
Ursprung 0346228310
Commit 1359a7fada
2 geänderte Dateien mit 80 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -213,6 +213,21 @@ public class CylinderRegion extends AbstractRegion {
return (int) (2 * radius.getZ());
}
private Vector2D getTotalXZChanges(Vector... changes) throws RegionOperationException {
Vector2D diff = new Vector2D();
Vector2D total = new Vector2D();
for (Vector change : changes) {
diff = diff.add(change.toVector2D());
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.
*
@ -231,6 +246,20 @@ public class CylinderRegion extends AbstractRegion {
}
}
/**
* Expand the region.
* Expand the region.
*
* @param changes array/arguments with multiple related changes
* @throws RegionOperationException
*/
public void expand(Vector... changes) throws RegionOperationException {
radius = radius.add(getTotalXZChanges(changes));
for (Vector change : changes) {
expand(new Vector(0, change.getBlockY(), 0));
}
}
/**
* Contract the region.
*
@ -249,6 +278,20 @@ public class CylinderRegion extends AbstractRegion {
}
}
/**
* Contract the region.
*
* @param changes array/arguments with multiple related changes
* @throws RegionOperationException
*/
public void contract(Vector... changes) throws RegionOperationException {
Vector2D newRadius = radius.subtract(getTotalXZChanges(changes));
radius = Vector2D.getMaximum(new Vector2D(1.5, 1.5), newRadius);
for (Vector change : changes) {
contract(new Vector(0, change.getBlockY(), 0));
}
}
@Override
public void shift(Vector change) throws RegionOperationException {
setCenter(getCenter().add(change));

Datei anzeigen

@ -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);