Added cylinder->polygon conversion.

This commit is contained in:
TomyLobo 2013-06-22 05:55:13 +02:00 committed by wizjany
parent 610fa40e2a
commit d7837f6121

View File

@ -29,6 +29,7 @@ import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.cui.CUIRegion;
import com.sk89q.worldedit.cui.SelectionMinMaxEvent;
import com.sk89q.worldedit.cui.SelectionPoint2DEvent;
@ -66,6 +67,35 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
pos1 = polygonal2DRegionSelector.pos1;
region = new Polygonal2DRegion(polygonal2DRegionSelector.region);
} else if (oldSelector instanceof CylinderRegionSelector) {
final CylinderRegionSelector cylinderRegionSelector = (CylinderRegionSelector) oldSelector;
final CylinderRegion oldRegion = cylinderRegionSelector.region;
final Vector2D radius = oldRegion.getRadius();
final Vector2D center = oldRegion.getCenter().toVector2D();
int nPoints = (int) Math.ceil(Math.PI*radius.length());
// These strange semantics for maxPoints are copied from the selectSecondary method.
if (maxPoints > -1 && nPoints >= maxPoints) {
nPoints = maxPoints - 1;
}
final List<BlockVector2D> points = new ArrayList<BlockVector2D>(nPoints);
for (int i = 0; i < nPoints; ++i) {
double angle = i * (2.0 * Math.PI) / nPoints;
System.out.println(angle);
final Vector2D pos = new Vector2D(Math.cos(angle), Math.sin(angle));
final BlockVector2D blockVector2D = pos.multiply(radius).add(center).toBlockVector2D();
System.out.println(blockVector2D);
points.add(blockVector2D);
}
final int minY = oldRegion.getMinimumY();
pos1 = points.get(0).toVector(minY).toBlockVector();
region = new Polygonal2DRegion(oldRegion.getWorld(), points, minY, oldRegion.getMaximumY());
} else {
final Region oldRegion;
try {