Search in sources :

Example 1 with CombinedTransform

use of com.sk89q.worldedit.math.transform.CombinedTransform in project FastAsyncWorldEdit by IntellectualSites.

the class FlattenedClipboardTransform method getTransformedRegion.

/**
 * Get the transformed region.
 *
 * @return the transformed region
 */
public Region getTransformedRegion() {
    Region region = original.getRegion();
    Vector3 minimum = region.getMinimumPoint().toVector3();
    Vector3 maximum = region.getMaximumPoint().toVector3();
    Transform transformAround = new CombinedTransform(new AffineTransform().translate(original.getOrigin().multiply(-1)), transform, new AffineTransform().translate(original.getOrigin()));
    Vector3[] corners = new Vector3[] { minimum, maximum, minimum.withX(maximum.getX()), minimum.withY(maximum.getY()), minimum.withZ(maximum.getZ()), maximum.withX(minimum.getX()), maximum.withY(minimum.getY()), maximum.withZ(minimum.getZ()) };
    for (int i = 0; i < corners.length; i++) {
        corners[i] = transformAround.apply(corners[i]);
    }
    Vector3 newMinimum = corners[0];
    Vector3 newMaximum = corners[0];
    for (int i = 1; i < corners.length; i++) {
        newMinimum = newMinimum.getMinimum(corners[i]);
        newMaximum = newMaximum.getMaximum(corners[i]);
    }
    // After transformation, the points may not really sit on a block,
    // so we should expand the region for edge cases
    newMinimum = newMinimum.floor();
    newMaximum = newMaximum.ceil();
    return new CuboidRegion(newMinimum.toBlockPoint(), newMaximum.toBlockPoint());
}
Also used : CombinedTransform(com.sk89q.worldedit.math.transform.CombinedTransform) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform) Vector3(com.sk89q.worldedit.math.Vector3) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Transform(com.sk89q.worldedit.math.transform.Transform) CombinedTransform(com.sk89q.worldedit.math.transform.CombinedTransform) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform)

Aggregations

Vector3 (com.sk89q.worldedit.math.Vector3)1 AffineTransform (com.sk89q.worldedit.math.transform.AffineTransform)1 CombinedTransform (com.sk89q.worldedit.math.transform.CombinedTransform)1 Transform (com.sk89q.worldedit.math.transform.Transform)1 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)1 Region (com.sk89q.worldedit.regions.Region)1