Add convenient constructors in *RegionSelector classes

This commit is contained in:
aumgn 2012-08-27 12:50:46 +02:00
parent 1fef255d77
commit 77bc49e057
5 changed files with 37 additions and 0 deletions

View File

@ -71,6 +71,14 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
region.setPos2(pos2); region.setPos2(pos2);
} }
public CuboidRegionSelector(LocalWorld world, Vector pos1, Vector pos2) {
this(world);
this.pos1 = pos1.toBlockVector();
this.pos2 = pos2.toBlockVector();
region.setPos1(pos1);
region.setPos2(pos2);
}
public boolean selectPrimary(Vector pos) { public boolean selectPrimary(Vector pos) {
if (pos.equals(pos1)) { if (pos.equals(pos1)) {
return false; return false;

View File

@ -79,6 +79,16 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
} }
} }
public CylinderRegionSelector(LocalWorld world, Vector2D center, Vector2D radius, int minY, int maxY) {
this(world);
region.setCenter(center);
region.setRadius(radius);
region.setMinimumY(Math.min(minY, maxY));
region.setMaximumY(Math.max(minY, maxY));
}
public boolean selectPrimary(Vector pos) { public boolean selectPrimary(Vector pos) {
if (!region.getCenter().equals(new Vector(0, 0, 0)) && pos.equals(region.getCenter())) { if (!region.getCenter().equals(new Vector(0, 0, 0)) && pos.equals(region.getCenter())) {
return false; return false;

View File

@ -70,6 +70,13 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
} }
} }
public EllipsoidRegionSelector(LocalWorld world, Vector center, Vector radius) {
this(world);
region.setCenter(center);
region.setRadius(radius);
}
public boolean selectPrimary(Vector pos) { public boolean selectPrimary(Vector pos) {
if (pos.equals(region.getCenter()) && region.getRadius().lengthSq() == 0) { if (pos.equals(region.getCenter()) && region.getRadius().lengthSq() == 0) {
return false; return false;

View File

@ -48,6 +48,14 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
region.setPos2(pos2); region.setPos2(pos2);
} }
public ExtendingCuboidRegionSelector(LocalWorld world, Vector pos1, Vector pos2) {
this(world);
pos1 = Vector.getMinimum(pos1, pos2);
pos2 = Vector.getMaximum(pos1, pos2);
region.setPos1(pos1);
region.setPos2(pos2);
}
@Override @Override
public boolean selectPrimary(Vector pos) { public boolean selectPrimary(Vector pos) {
if (pos.equals(pos1) && pos.equals(pos2)) { if (pos.equals(pos1) && pos.equals(pos2)) {

View File

@ -45,6 +45,10 @@ public class SphereRegionSelector extends EllipsoidRegionSelector {
region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar)); region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar));
} }
public SphereRegionSelector(LocalWorld world, Vector center, int radius) {
super(world, center, new Vector(radius, radius, radius));
}
@Override @Override
public boolean selectSecondary(Vector pos) { public boolean selectSecondary(Vector pos) {
final Vector diff = pos.subtract(region.getCenter()); final Vector diff = pos.subtract(region.getCenter());