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

View File

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