From 66a51636a3f816ef7ccc464a564a23f0805f13ef Mon Sep 17 00:00:00 2001 From: sk89q Date: Thu, 10 Jul 2014 00:47:36 -0700 Subject: [PATCH] Ellipsoid-based region selectors no longer starts primary at (0, 0, 0). Fixes WORLDEDIT-2968. --- .../regions/selector/EllipsoidRegionSelector.java | 9 ++++++++- .../worldedit/regions/selector/SphereRegionSelector.java | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java b/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java index 3aed786a1..21a2eee6e 100644 --- a/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java +++ b/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java @@ -41,6 +41,7 @@ import static com.google.common.base.Preconditions.checkNotNull; public class EllipsoidRegionSelector extends com.sk89q.worldedit.regions.EllipsoidRegionSelector implements RegionSelector, CUIRegion { protected EllipsoidRegion region; + protected boolean started = false; /** * Create a new selector. @@ -113,11 +114,17 @@ public class EllipsoidRegionSelector extends com.sk89q.worldedit.regions.Ellipso region.setCenter(pos.toBlockVector()); region.setRadius(new Vector()); + started = true; + return true; } @Override public boolean selectSecondary(Vector pos) { + if (!started) { + return false; + } + final Vector diff = pos.subtract(region.getCenter()); final Vector minRadius = Vector.getMaximum(diff, diff.multiply(-1.0)); region.extendRadius(minRadius); @@ -153,7 +160,7 @@ public class EllipsoidRegionSelector extends com.sk89q.worldedit.regions.Ellipso @Override public boolean isDefined() { - return region.getRadius().lengthSq() > 0; + return started && region.getRadius().lengthSq() > 0; } @Override diff --git a/src/main/java/com/sk89q/worldedit/regions/selector/SphereRegionSelector.java b/src/main/java/com/sk89q/worldedit/regions/selector/SphereRegionSelector.java index f6f043778..002ba7577 100644 --- a/src/main/java/com/sk89q/worldedit/regions/selector/SphereRegionSelector.java +++ b/src/main/java/com/sk89q/worldedit/regions/selector/SphereRegionSelector.java @@ -80,6 +80,10 @@ public class SphereRegionSelector extends EllipsoidRegionSelector { @Override public boolean selectSecondary(Vector pos) { + if (!started) { + return false; + } + final double radiusScalar = Math.ceil(pos.distance(region.getCenter())); region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar));