summaryrefslogtreecommitdiff
path: root/CSMath/src/bezier/transforms/TDHScale.java
diff options
context:
space:
mode:
authorbjculkin <bjculkin@BECK-DZ9BJB2.wvu-ad.wvu.edu>2018-04-11 15:29:25 -0400
committerbjculkin <bjculkin@BECK-DZ9BJB2.wvu-ad.wvu.edu>2018-04-11 15:29:25 -0400
commitdcb6c2159446135a142cad41eec185bb24c45bfb (patch)
tree965dcc07fc0256a9a8254d5f968e316a1e928617 /CSMath/src/bezier/transforms/TDHScale.java
parent8ecf52b6c5821e5c3de8a0f5c9e7ed3e357cb282 (diff)
Split #9 into one class/file
Diffstat (limited to 'CSMath/src/bezier/transforms/TDHScale.java')
-rw-r--r--CSMath/src/bezier/transforms/TDHScale.java124
1 files changed, 124 insertions, 0 deletions
diff --git a/CSMath/src/bezier/transforms/TDHScale.java b/CSMath/src/bezier/transforms/TDHScale.java
new file mode 100644
index 0000000..09ab237
--- /dev/null
+++ b/CSMath/src/bezier/transforms/TDHScale.java
@@ -0,0 +1,124 @@
+package bezier.transforms;
+
+import bezier.TDHPoint;
+
+/**
+ * Transform that does coordinate scaling.
+ *
+ * @author bjculkin
+ *
+ */
+public class TDHScale implements TDHTransform {
+ /**
+ * Amount to scale x by.
+ */
+ public final double sx;
+ /**
+ * Amount to scale y by.
+ */
+ public final double sy;
+ /**
+ * Amount to scale the homogeneous coordinate by.
+ */
+ public final double sz;
+
+ /**
+ * Create a new scaling that scales each coordinate by an equal amount
+ *
+ * @param factor
+ * The amount to scale the coordinates by.
+ */
+ public TDHScale(double factor) {
+ this(factor, factor);
+ }
+
+ /**
+ * Create a new scaling that scales each coordinate separately.
+ *
+ * @param sx
+ * The amount to scale x by.
+ * @param sy
+ * The amount to scale y by.
+ */
+ public TDHScale(double sx, double sy) {
+ this(sx, sy, 1);
+ }
+
+ /**
+ * Create a new scaling that scales each coordinate separately.
+ *
+ * Includes the homogeneous coordinate.
+ *
+ * @param sx
+ * The amount to scale x by.
+ * @param sy
+ * The amount to scale y by.
+ * @param sz
+ * The amount to scale the homogeneous coordinate by.
+ */
+ public TDHScale(double sx, double sy, double sz) {
+ this.sx = sx;
+ this.sy = sy;
+ this.sz = sz;
+ }
+
+ @Override
+ public TDHTransformType type() {
+ return TDHTransformType.SCALE;
+ }
+
+ @Override
+ public TDHPoint transform(TDHPoint punkt) {
+ double x = punkt.x * sx;
+ double y = punkt.y * sy;
+ double z = punkt.z * sz;
+
+ return new TDHPoint(x, y, z);
+ }
+
+ @Override
+ public double[][] matrix() {
+ return new double[][] { new double[] { sx, 0, 0 }, new double[] { 0, sy, 0 }, new double[] { 0, 0, sz } };
+ }
+
+ public TDHTransform invert() {
+ return new TDHScale(1 / sx, 1 / sy, 1 / sy);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ long temp;
+ temp = Double.doubleToLongBits(sx);
+ result = prime * result + (int) (temp ^ (temp >>> 32));
+ temp = Double.doubleToLongBits(sy);
+ result = prime * result + (int) (temp ^ (temp >>> 32));
+ temp = Double.doubleToLongBits(sz);
+ 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;
+ TDHScale other = (TDHScale) obj;
+ if (Double.doubleToLongBits(sx) != Double.doubleToLongBits(other.sx))
+ return false;
+ if (Double.doubleToLongBits(sy) != Double.doubleToLongBits(other.sy))
+ return false;
+ if (Double.doubleToLongBits(sz) != Double.doubleToLongBits(other.sz))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "TDHScale [sx=" + sx + ", sy=" + sy + ", sz=" + sz + "]";
+ }
+} \ No newline at end of file