From 77219a8b3ee86de088be6fdff42e19cd0dfc9e9d Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sat, 24 Aug 2013 09:55:35 +0200 Subject: [PATCH] The Sphere selector can now also shrink the region. The radius is set to ceil(distanceToCenter). --- .../com/sk89q/worldedit/commands/SelectionCommands.java | 2 +- .../sk89q/worldedit/regions/SphereRegionSelector.java | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java b/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java index 16c5de53f..b268467d0 100644 --- a/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java @@ -763,7 +763,7 @@ public class SelectionCommands { player.print("Ellipsoid selector: left click=center, right click to extend"); } else if (typeName.equalsIgnoreCase("sphere")) { selector = new SphereRegionSelector(oldSelector); - player.print("Sphere selector: left click=center, right click to extend"); + player.print("Sphere selector: left click=center, right click to set radius"); } else if (typeName.equalsIgnoreCase("cyl")) { selector = new CylinderRegionSelector(oldSelector); player.print("Cylindrical selector: Left click=center, right click to extend."); diff --git a/src/main/java/com/sk89q/worldedit/regions/SphereRegionSelector.java b/src/main/java/com/sk89q/worldedit/regions/SphereRegionSelector.java index 90a63b049..6281205ca 100644 --- a/src/main/java/com/sk89q/worldedit/regions/SphereRegionSelector.java +++ b/src/main/java/com/sk89q/worldedit/regions/SphereRegionSelector.java @@ -41,7 +41,7 @@ public class SphereRegionSelector extends EllipsoidRegionSelector { public SphereRegionSelector(RegionSelector oldSelector) { super(oldSelector); final Vector radius = region.getRadius(); - double radiusScalar = Math.max(Math.max(radius.getX(), radius.getY()), radius.getZ()); + final double radiusScalar = Math.max(Math.max(radius.getX(), radius.getY()), radius.getZ()); region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar)); } @@ -51,12 +51,9 @@ public class SphereRegionSelector extends EllipsoidRegionSelector { @Override public boolean selectSecondary(Vector pos) { - final Vector diff = pos.subtract(region.getCenter()); - final Vector minRadius = Vector.getMaximum(diff, diff.multiply(-1.0)); + final double radiusScalar = Math.ceil(pos.distance(region.getCenter())); + region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar)); - double minRadiusScalar = Math.max(Math.max(minRadius.getX(), minRadius.getY()), minRadius.getZ()); - - region.extendRadius(new Vector(minRadiusScalar, minRadiusScalar, minRadiusScalar)); return true; }