Add Transform.isIdentity().

This commit is contained in:
sk89q 2014-07-09 21:44:44 -07:00
parent 47ad03a013
commit 932513d8a1
4 changed files with 26 additions and 0 deletions

View File

@ -109,6 +109,7 @@ public class AffineTransform implements Transform {
// ===================================================================
// accessors
@Override
public boolean isIdentity() {
if (m00 != 1)
return false;

View File

@ -54,6 +54,17 @@ public class CombinedTransform implements Transform {
this(transforms.toArray(new Transform[checkNotNull(transforms).size()]));
}
@Override
public boolean isIdentity() {
for (Transform transform : transforms) {
if (!transform.isIdentity()) {
return false;
}
}
return true;
}
@Override
public Vector apply(Vector vector) {
for (Transform transform : transforms) {

View File

@ -26,6 +26,11 @@ import com.sk89q.worldedit.Vector;
*/
public class Identity implements Transform {
@Override
public boolean isIdentity() {
return true;
}
@Override
public Vector apply(Vector vector) {
return vector;

View File

@ -26,6 +26,15 @@ import com.sk89q.worldedit.Vector;
*/
public interface Transform {
/**
* Return whether this transform is an identity.
*
* <p>If it is not known, then {@code false} must be returned.</p>
*
* @return true if identity
*/
boolean isIdentity();
/**
* Returns the result of applying the function to the input.
*