From 77bc49e057a6806b310fb589b73a30201fc98a96 Mon Sep 17 00:00:00 2001 From: aumgn Date: Mon, 27 Aug 2012 12:50:46 +0200 Subject: [PATCH] Add convenient constructors in *RegionSelector classes --- .../sk89q/worldedit/regions/CuboidRegionSelector.java | 8 ++++++++ .../worldedit/regions/CylinderRegionSelector.java | 10 ++++++++++ .../worldedit/regions/EllipsoidRegionSelector.java | 7 +++++++ .../regions/ExtendingCuboidRegionSelector.java | 8 ++++++++ .../sk89q/worldedit/regions/SphereRegionSelector.java | 4 ++++ 5 files changed, 37 insertions(+) diff --git a/src/main/java/com/sk89q/worldedit/regions/CuboidRegionSelector.java b/src/main/java/com/sk89q/worldedit/regions/CuboidRegionSelector.java index a40c89e01..c61813daa 100644 --- a/src/main/java/com/sk89q/worldedit/regions/CuboidRegionSelector.java +++ b/src/main/java/com/sk89q/worldedit/regions/CuboidRegionSelector.java @@ -71,6 +71,14 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { 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) { if (pos.equals(pos1)) { return false; diff --git a/src/main/java/com/sk89q/worldedit/regions/CylinderRegionSelector.java b/src/main/java/com/sk89q/worldedit/regions/CylinderRegionSelector.java index 3a6de1371..44e64fbde 100644 --- a/src/main/java/com/sk89q/worldedit/regions/CylinderRegionSelector.java +++ b/src/main/java/com/sk89q/worldedit/regions/CylinderRegionSelector.java @@ -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) { if (!region.getCenter().equals(new Vector(0, 0, 0)) && pos.equals(region.getCenter())) { return false; diff --git a/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegionSelector.java b/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegionSelector.java index d91d29c91..8a84ac8e7 100644 --- a/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegionSelector.java +++ b/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegionSelector.java @@ -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) { if (pos.equals(region.getCenter()) && region.getRadius().lengthSq() == 0) { return false; diff --git a/src/main/java/com/sk89q/worldedit/regions/ExtendingCuboidRegionSelector.java b/src/main/java/com/sk89q/worldedit/regions/ExtendingCuboidRegionSelector.java index 3b223308b..2242379ff 100644 --- a/src/main/java/com/sk89q/worldedit/regions/ExtendingCuboidRegionSelector.java +++ b/src/main/java/com/sk89q/worldedit/regions/ExtendingCuboidRegionSelector.java @@ -48,6 +48,14 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector { 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 public boolean selectPrimary(Vector pos) { if (pos.equals(pos1) && pos.equals(pos2)) { diff --git a/src/main/java/com/sk89q/worldedit/regions/SphereRegionSelector.java b/src/main/java/com/sk89q/worldedit/regions/SphereRegionSelector.java index 17ac97e7b..90a63b049 100644 --- a/src/main/java/com/sk89q/worldedit/regions/SphereRegionSelector.java +++ b/src/main/java/com/sk89q/worldedit/regions/SphereRegionSelector.java @@ -45,6 +45,10 @@ public class SphereRegionSelector extends EllipsoidRegionSelector { region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar)); } + public SphereRegionSelector(LocalWorld world, Vector center, int radius) { + super(world, center, new Vector(radius, radius, radius)); + } + @Override public boolean selectSecondary(Vector pos) { final Vector diff = pos.subtract(region.getCenter());