Some region selection fixes

- CuboidSelection no longer deals with IncompleteRegionExceptions
- Fixed Polygonal2DSelection not passing its region to the selector
- Fixed Polygonal2DRegion not cloning the list it receives in its constructor
- Gave PolygonalRegionSelector a new constructor where it takes a list of points
This commit is contained in:
TomyLobo 2012-01-01 14:08:22 +01:00
parent 3b87953da0
commit f2e26b07ec
4 changed files with 22 additions and 11 deletions

View File

@ -21,7 +21,6 @@ package com.sk89q.worldedit.bukkit.selections;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitUtil; import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.regions.*; import com.sk89q.worldedit.regions.*;
@ -37,6 +36,7 @@ public class CuboidSelection extends RegionSelection {
public CuboidSelection(World world, Vector pt1, Vector pt2) { public CuboidSelection(World world, Vector pt1, Vector pt2) {
super(world); super(world);
// Validate input
if (pt1 == null) { if (pt1 == null) {
throw new IllegalArgumentException("Null point 1 not permitted"); throw new IllegalArgumentException("Null point 1 not permitted");
} }
@ -45,16 +45,17 @@ public class CuboidSelection extends RegionSelection {
throw new IllegalArgumentException("Null point 2 not permitted"); throw new IllegalArgumentException("Null point 2 not permitted");
} }
// Create new selector
CuboidRegionSelector sel = new CuboidRegionSelector(BukkitUtil.getLocalWorld(world)); CuboidRegionSelector sel = new CuboidRegionSelector(BukkitUtil.getLocalWorld(world));
// set up selector
sel.selectPrimary(pt1); sel.selectPrimary(pt1);
sel.selectSecondary(pt2); sel.selectSecondary(pt2);
try { // set up CuboidSelection
cuboid = sel.getRegion(); cuboid = sel.getIncompleteRegion();
} catch (IncompleteRegionException e) {
throw new RuntimeException("IncompleteRegionException unexpectedly thrown");
}
// set up RegionSelection
setRegionSelector(sel); setRegionSelector(sel);
setRegion(cuboid); setRegion(cuboid);
} }

View File

@ -41,13 +41,17 @@ public class Polygonal2DSelection extends RegionSelection {
super(world); super(world);
LocalWorld lWorld = BukkitUtil.getLocalWorld(world); LocalWorld lWorld = BukkitUtil.getLocalWorld(world);
// Validate input
minY = Math.min(Math.max(0, minY), world.getMaxHeight()); minY = Math.min(Math.max(0, minY), world.getMaxHeight());
maxY = Math.min(Math.max(0, maxY), world.getMaxHeight()); maxY = Math.min(Math.max(0, maxY), world.getMaxHeight());
Polygonal2DRegionSelector sel = new Polygonal2DRegionSelector(BukkitUtil.getLocalWorld(world)); // Create and set up new selector
poly2d = new Polygonal2DRegion(lWorld, points, minY, maxY); Polygonal2DRegionSelector sel = new Polygonal2DRegionSelector(lWorld, points, minY, maxY);
sel.learnChanges();
// set up CuboidSelection
poly2d = sel.getIncompleteRegion();
// set up RegionSelection
setRegionSelector(sel); setRegionSelector(sel);
setRegion(poly2d); setRegion(poly2d);
} }

View File

@ -76,7 +76,7 @@ public class Polygonal2DRegion implements Region {
* @param maxY * @param maxY
*/ */
public Polygonal2DRegion(LocalWorld world, List<BlockVector2D> points, int minY, int maxY) { public Polygonal2DRegion(LocalWorld world, List<BlockVector2D> points, int minY, int maxY) {
this.points = points; this.points = new ArrayList<BlockVector2D>(points);
this.minY = minY; this.minY = minY;
this.maxY = maxY; this.maxY = maxY;
hasY = true; hasY = true;

View File

@ -80,6 +80,12 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
} }
} }
public Polygonal2DRegionSelector(LocalWorld world, List<BlockVector2D> points, int minY, int maxY) {
final BlockVector2D pos2D = points.get(0);
pos1 = new BlockVector(pos2D.getX(), minY, pos2D.getZ());
region = new Polygonal2DRegion(world, points, minY, maxY);
}
public boolean selectPrimary(Vector pos) { public boolean selectPrimary(Vector pos) {
if (pos.equals(pos1)) { if (pos.equals(pos1)) {
return false; return false;