summaryrefslogtreecommitdiff
path: root/CSMath/src/bezier/geom/transform/TDHTranslate.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2018-05-23 16:42:38 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2018-05-23 16:42:38 -0400
commit48f781fb6e61539ba9d17efcfd9f9e38245cf6c0 (patch)
tree97e5743678a00d09024ec040490b8fcf8ccb1c74 /CSMath/src/bezier/geom/transform/TDHTranslate.java
parent81d8191c01629d881486f1f1fe5ae16c42b46287 (diff)
Refactor package structure
Diffstat (limited to 'CSMath/src/bezier/geom/transform/TDHTranslate.java')
-rw-r--r--CSMath/src/bezier/geom/transform/TDHTranslate.java89
1 files changed, 89 insertions, 0 deletions
diff --git a/CSMath/src/bezier/geom/transform/TDHTranslate.java b/CSMath/src/bezier/geom/transform/TDHTranslate.java
new file mode 100644
index 0000000..1114c5e
--- /dev/null
+++ b/CSMath/src/bezier/geom/transform/TDHTranslate.java
@@ -0,0 +1,89 @@
+package bezier.geom.transform;
+
+import bezier.geom.TDHPoint;
+
+/**
+ * A transform that does coordinate translation.
+ *
+ * @author bjculkin
+ *
+ */
+public class TDHTranslate implements TDHTransform {
+ /**
+ * The amount to translate the x-coordinate by.
+ */
+ public final double h;
+ /**
+ * The amount to translate the y-coordinate by.
+ */
+ public final double k;
+
+ /**
+ * Create a new translation transform.
+ *
+ * @param h
+ * The amount to translate x by.
+ * @param k
+ * The amount to translate y by.
+ */
+ public TDHTranslate(double h, double k) {
+ this.h = h;
+ this.k = k;
+ }
+
+ @Override
+ public TDHTransformType type() {
+ return TDHTransformType.TRANSLATE;
+ }
+
+ @Override
+ public TDHPoint transform(TDHPoint punkt) {
+ double x = punkt.x + (punkt.z * h);
+ double y = punkt.y + (punkt.z * k);
+
+ return new TDHPoint(x, y, punkt.z);
+ }
+
+ @Override
+ public double[][] matrix() {
+ return new double[][] { new double[] { 1, 0, 0 }, new double[] { 0, 1, 0 }, new double[] { h, k, 1 } };
+ }
+
+ @Override
+ public TDHTransform invert() {
+ return new TDHTranslate(-h, -k);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ long temp;
+ temp = Double.doubleToLongBits(h);
+ result = prime * result + (int) (temp ^ (temp >>> 32));
+ temp = Double.doubleToLongBits(k);
+ result = prime * result + (int) (temp ^ (temp >>> 32));
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ TDHTranslate other = (TDHTranslate) obj;
+ if (Double.doubleToLongBits(h) != Double.doubleToLongBits(other.h))
+ return false;
+ if (Double.doubleToLongBits(k) != Double.doubleToLongBits(other.k))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "TDHTranslate [h=" + h + ", k=" + k + "]";
+ }
+} \ No newline at end of file