From 63411b427a76664ccb2ddea418c1add848beadff Mon Sep 17 00:00:00 2001 From: sk89q Date: Tue, 1 Jul 2014 12:41:11 -0700 Subject: [PATCH] Added Transform.inverse() as a standard operation. --- .../worldedit/math/transform/CombinedTransform.java | 11 +++++++++++ .../com/sk89q/worldedit/math/transform/Identity.java | 5 +++++ .../com/sk89q/worldedit/math/transform/Transform.java | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/src/main/java/com/sk89q/worldedit/math/transform/CombinedTransform.java b/src/main/java/com/sk89q/worldedit/math/transform/CombinedTransform.java index 86990f49c..84b1a474b 100644 --- a/src/main/java/com/sk89q/worldedit/math/transform/CombinedTransform.java +++ b/src/main/java/com/sk89q/worldedit/math/transform/CombinedTransform.java @@ -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 list = new ArrayList(); + 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); diff --git a/src/main/java/com/sk89q/worldedit/math/transform/Identity.java b/src/main/java/com/sk89q/worldedit/math/transform/Identity.java index 3cad43c2c..6e7622ec5 100644 --- a/src/main/java/com/sk89q/worldedit/math/transform/Identity.java +++ b/src/main/java/com/sk89q/worldedit/math/transform/Identity.java @@ -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) { diff --git a/src/main/java/com/sk89q/worldedit/math/transform/Transform.java b/src/main/java/com/sk89q/worldedit/math/transform/Transform.java index 53f0d44ca..05a7d5196 100644 --- a/src/main/java/com/sk89q/worldedit/math/transform/Transform.java +++ b/src/main/java/com/sk89q/worldedit/math/transform/Transform.java @@ -27,6 +27,13 @@ import com.sk89q.worldedit.Vector; */ public interface Transform extends Function { + /** + * Create a new inverse transform. + * + * @return a new inverse transform + */ + Transform inverse(); + /** * Create a new {@link Transform} that combines this transform with another. *