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());
}
Aggregations