Added Transform.inverse() as a standard operation.

This commit is contained in:
sk89q 2014-07-01 12:41:11 -07:00
parent a74bab7f98
commit 63411b427a
3 changed files with 23 additions and 0 deletions

View File

@ -21,8 +21,10 @@ package com.sk89q.worldedit.math.transform;
import com.sk89q.worldedit.Vector;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
@ -60,6 +62,15 @@ public class CombinedTransform implements Transform {
return vector;
}
@Override
public Transform inverse() {
List<Transform> list = new ArrayList<Transform>();
for (int i = transforms.length - 1; i >= 0; i--) {
list.add(transforms[i].inverse());
}
return new CombinedTransform(list);
}
@Override
public Transform combine(Transform other) {
checkNotNull(other);

View File

@ -31,6 +31,11 @@ public class Identity implements Transform {
return vector;
}
@Override
public Transform inverse() {
return this;
}
@Override
public Transform combine(Transform other) {
if (other instanceof Identity) {

View File

@ -27,6 +27,13 @@ import com.sk89q.worldedit.Vector;
*/
public interface Transform extends Function<Vector, Vector> {
/**
* Create a new inverse transform.
*
* @return a new inverse transform
*/
Transform inverse();
/**
* Create a new {@link Transform} that combines this transform with another.
*