From 48f781fb6e61539ba9d17efcfd9f9e38245cf6c0 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Wed, 23 May 2018 16:42:38 -0400 Subject: Refactor package structure --- CSMath/src/bezier/transforms/TDHCombination.java | 64 ----------- CSMath/src/bezier/transforms/TDHIdentity.java | 21 ---- .../src/bezier/transforms/TDHLineReflection.java | 68 ----------- .../src/bezier/transforms/TDHMatrixTransform.java | 32 ------ CSMath/src/bezier/transforms/TDHPointRotation.java | 67 ----------- CSMath/src/bezier/transforms/TDHRotation.java | 57 ---------- CSMath/src/bezier/transforms/TDHScale.java | 124 --------------------- CSMath/src/bezier/transforms/TDHShear.java | 59 ---------- CSMath/src/bezier/transforms/TDHTransform.java | 54 --------- CSMath/src/bezier/transforms/TDHTransformType.java | 42 ------- CSMath/src/bezier/transforms/TDHTranslate.java | 89 --------------- .../src/bezier/transforms/TDHXAxisReflection.java | 20 ---- .../src/bezier/transforms/TDHYAxisReflection.java | 20 ---- .../src/bezier/transforms/geom/TDHCombination.java | 64 +++++++++++ CSMath/src/bezier/transforms/geom/TDHIdentity.java | 21 ++++ .../bezier/transforms/geom/TDHLineReflection.java | 68 +++++++++++ .../bezier/transforms/geom/TDHMatrixTransform.java | 32 ++++++ .../bezier/transforms/geom/TDHPointRotation.java | 67 +++++++++++ CSMath/src/bezier/transforms/geom/TDHRotation.java | 57 ++++++++++ CSMath/src/bezier/transforms/geom/TDHScale.java | 124 +++++++++++++++++++++ CSMath/src/bezier/transforms/geom/TDHShear.java | 59 ++++++++++ .../src/bezier/transforms/geom/TDHTransform.java | 54 +++++++++ .../bezier/transforms/geom/TDHTransformType.java | 42 +++++++ .../src/bezier/transforms/geom/TDHTranslate.java | 89 +++++++++++++++ .../bezier/transforms/geom/TDHXAxisReflection.java | 20 ++++ .../bezier/transforms/geom/TDHYAxisReflection.java | 20 ++++ 26 files changed, 717 insertions(+), 717 deletions(-) delete mode 100644 CSMath/src/bezier/transforms/TDHCombination.java delete mode 100644 CSMath/src/bezier/transforms/TDHIdentity.java delete mode 100644 CSMath/src/bezier/transforms/TDHLineReflection.java delete mode 100644 CSMath/src/bezier/transforms/TDHMatrixTransform.java delete mode 100644 CSMath/src/bezier/transforms/TDHPointRotation.java delete mode 100644 CSMath/src/bezier/transforms/TDHRotation.java delete mode 100644 CSMath/src/bezier/transforms/TDHScale.java delete mode 100644 CSMath/src/bezier/transforms/TDHShear.java delete mode 100644 CSMath/src/bezier/transforms/TDHTransform.java delete mode 100644 CSMath/src/bezier/transforms/TDHTransformType.java delete mode 100644 CSMath/src/bezier/transforms/TDHTranslate.java delete mode 100644 CSMath/src/bezier/transforms/TDHXAxisReflection.java delete mode 100644 CSMath/src/bezier/transforms/TDHYAxisReflection.java create mode 100644 CSMath/src/bezier/transforms/geom/TDHCombination.java create mode 100644 CSMath/src/bezier/transforms/geom/TDHIdentity.java create mode 100644 CSMath/src/bezier/transforms/geom/TDHLineReflection.java create mode 100644 CSMath/src/bezier/transforms/geom/TDHMatrixTransform.java create mode 100644 CSMath/src/bezier/transforms/geom/TDHPointRotation.java create mode 100644 CSMath/src/bezier/transforms/geom/TDHRotation.java create mode 100644 CSMath/src/bezier/transforms/geom/TDHScale.java create mode 100644 CSMath/src/bezier/transforms/geom/TDHShear.java create mode 100644 CSMath/src/bezier/transforms/geom/TDHTransform.java create mode 100644 CSMath/src/bezier/transforms/geom/TDHTransformType.java create mode 100644 CSMath/src/bezier/transforms/geom/TDHTranslate.java create mode 100644 CSMath/src/bezier/transforms/geom/TDHXAxisReflection.java create mode 100644 CSMath/src/bezier/transforms/geom/TDHYAxisReflection.java (limited to 'CSMath/src/bezier/transforms') diff --git a/CSMath/src/bezier/transforms/TDHCombination.java b/CSMath/src/bezier/transforms/TDHCombination.java deleted file mode 100644 index 83b3858..0000000 --- a/CSMath/src/bezier/transforms/TDHCombination.java +++ /dev/null @@ -1,64 +0,0 @@ -package bezier.transforms; - -import java.util.ArrayList; -import java.util.List; - -import bezier.geom.TDHPoint; - -public class TDHCombination implements TDHTransform { - public final List forms; - - @Override - public TDHTransformType type() { - return TDHTransformType.COMBINATION; - } - - public TDHCombination(TDHTransform... forms) { - this.forms = new ArrayList<>(forms.length); - - for (TDHTransform form : forms) { - this.forms.add(form); - } - } - - @Override - public TDHPoint transform(TDHPoint punkt) { - TDHPoint ret = punkt; - - for (TDHTransform form : forms) { - ret = form.transform(ret); - } - - return ret; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((forms == null) ? 0 : forms.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - TDHCombination other = (TDHCombination) obj; - if (forms == null) { - if (other.forms != null) - return false; - } else if (!forms.equals(other.forms)) - return false; - return true; - } - - @Override - public String toString() { - return "TDHCombination [forms=" + forms + "]"; - } -} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/TDHIdentity.java b/CSMath/src/bezier/transforms/TDHIdentity.java deleted file mode 100644 index d1b55d0..0000000 --- a/CSMath/src/bezier/transforms/TDHIdentity.java +++ /dev/null @@ -1,21 +0,0 @@ -package bezier.transforms; - -import bezier.geom.TDHPoint; - -/** - * A transform that does nothing. - * - * @author bjculkin - * - */ -public class TDHIdentity implements TDHTransform { - @Override - public TDHPoint transform(TDHPoint punkt) { - return punkt; - } - - @Override - public String toString() { - return "TDHIdentity []"; - } -} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/TDHLineReflection.java b/CSMath/src/bezier/transforms/TDHLineReflection.java deleted file mode 100644 index db50fd5..0000000 --- a/CSMath/src/bezier/transforms/TDHLineReflection.java +++ /dev/null @@ -1,68 +0,0 @@ -package bezier.transforms; - -import bezier.geom.TDHPoint; - -public class TDHLineReflection implements TDHTransform { - public final double a; - public final double b; - public final double c; - - public TDHLineReflection(double a, double b, double c) { - this.a = a; - this.b = b; - this.c = c; - } - - @Override - public TDHTransformType type() { - return TDHTransformType.REFLECTION; - } - - @Override - public TDHPoint transform(TDHPoint punkt) { - double com = (a * a - b * b); - - double x = (punkt.x * com) - (2 * a * b * punkt.y) - (2 * a * c * punkt.z); - double y = (-2 * a * b * punkt.x) + (punkt.y * com) - (2 * b * c * punkt.z); - double z = (punkt.z * com); - - return new TDHPoint(x, y, z); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - long temp; - temp = Double.doubleToLongBits(a); - result = prime * result + (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(b); - result = prime * result + (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(c); - 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; - TDHLineReflection other = (TDHLineReflection) obj; - if (Double.doubleToLongBits(a) != Double.doubleToLongBits(other.a)) - return false; - if (Double.doubleToLongBits(b) != Double.doubleToLongBits(other.b)) - return false; - if (Double.doubleToLongBits(c) != Double.doubleToLongBits(other.c)) - return false; - return true; - } - - @Override - public String toString() { - return "TDHLineReflection [a=" + a + ", b=" + b + ", c=" + c + "]"; - } -} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/TDHMatrixTransform.java b/CSMath/src/bezier/transforms/TDHMatrixTransform.java deleted file mode 100644 index 6cfc3cc..0000000 --- a/CSMath/src/bezier/transforms/TDHMatrixTransform.java +++ /dev/null @@ -1,32 +0,0 @@ -package bezier.transforms; - -import bezier.geom.Matrix; -import bezier.geom.TDHPoint; - -public class TDHMatrixTransform implements TDHTransform { - public final Matrix mat; - - public TDHMatrixTransform(Matrix mat) { - this.mat = mat; - } - - public TDHMatrixTransform(double[][] mat) { - this.mat = new Matrix(mat); - } - - @Override - public TDHTransformType type() { - return TDHTransformType.MATRIX; - } - - @Override - public TDHPoint transform(TDHPoint punkt) { - double[] mult = mat.scalarMultiply(new double[] { punkt.x, punkt.y, punkt.z }); - - return new TDHPoint(mult[0], mult[1], mult[2]); - } - - public TDHTransform then(TDHMatrixTransform trans) { - return new TDHMatrixTransform(mat.multiply(trans.mat)); - } -} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/TDHPointRotation.java b/CSMath/src/bezier/transforms/TDHPointRotation.java deleted file mode 100644 index 5b8736c..0000000 --- a/CSMath/src/bezier/transforms/TDHPointRotation.java +++ /dev/null @@ -1,67 +0,0 @@ -package bezier.transforms; - -import bezier.geom.TDHPoint; - -public class TDHPointRotation extends TDHRotation { - public final double x0; - public final double y0; - - public TDHPointRotation(double theta, double x0, double y0) { - super(theta); - - this.x0 = x0; - this.y0 = y0; - } - - @Override - public TDHTransformType type() { - return TDHTransformType.ROTATION; - } - - @Override - public TDHPoint transform(TDHPoint punkt) { - double x1 = (punkt.x * Math.cos(theta)) - (punkt.y * Math.sin(theta)); - double y1 = (punkt.x * Math.sin(theta)) - (punkt.y * Math.cos(theta)); - - double x2 = (-x0 * Math.cos(theta)) + (y0 * Math.sin(theta)) + x0; - double y2 = (-x0 * Math.sin(theta)) - (y0 * Math.cos(theta)) + y0; - - double x = x1 + (punkt.z * x2); - double y = y1 + (punkt.z * y2); - - return new TDHPoint(x, y, punkt.z); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - long temp; - temp = Double.doubleToLongBits(x0); - result = prime * result + (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(y0); - result = prime * result + (int) (temp ^ (temp >>> 32)); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (!super.equals(obj)) - return false; - if (getClass() != obj.getClass()) - return false; - TDHPointRotation other = (TDHPointRotation) obj; - if (Double.doubleToLongBits(x0) != Double.doubleToLongBits(other.x0)) - return false; - if (Double.doubleToLongBits(y0) != Double.doubleToLongBits(other.y0)) - return false; - return true; - } - - @Override - public String toString() { - return "TDHPointRotation [x0=" + x0 + ", y0=" + y0 + "]"; - } -} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/TDHRotation.java b/CSMath/src/bezier/transforms/TDHRotation.java deleted file mode 100644 index 64a6c2c..0000000 --- a/CSMath/src/bezier/transforms/TDHRotation.java +++ /dev/null @@ -1,57 +0,0 @@ -package bezier.transforms; - -import bezier.geom.TDHPoint; - -public class TDHRotation implements TDHTransform { - public final double theta; - - public TDHRotation(double theta) { - this.theta = theta; - } - - @Override - public TDHPoint transform(TDHPoint punkt) { - double x = (punkt.x * Math.cos(theta)) - (punkt.y * Math.sin(theta)); - double y = (punkt.x * Math.sin(theta)) - (punkt.y * Math.cos(theta)); - - return new TDHPoint(x, y, punkt.z); - } - - public double[][] matrix() { - return new double[][] { new double[] { Math.cos(theta), Math.sin(theta), 0 }, - new double[] { -Math.sin(theta), Math.cos(theta), 0 }, new double[] { 0, 0, 1 } }; - } - - public TDHTransform invert() { - return new TDHRotation(-theta); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - long temp; - temp = Double.doubleToLongBits(theta); - 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; - TDHRotation other = (TDHRotation) obj; - if (Double.doubleToLongBits(theta) != Double.doubleToLongBits(other.theta)) - return false; - return true; - } - - @Override - public String toString() { - return "TDHRotation [theta=" + theta + "]"; - } -} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/TDHScale.java b/CSMath/src/bezier/transforms/TDHScale.java deleted file mode 100644 index 5cfd300..0000000 --- a/CSMath/src/bezier/transforms/TDHScale.java +++ /dev/null @@ -1,124 +0,0 @@ -package bezier.transforms; - -import bezier.geom.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 diff --git a/CSMath/src/bezier/transforms/TDHShear.java b/CSMath/src/bezier/transforms/TDHShear.java deleted file mode 100644 index 7dbb4c5..0000000 --- a/CSMath/src/bezier/transforms/TDHShear.java +++ /dev/null @@ -1,59 +0,0 @@ -package bezier.transforms; - -import bezier.geom.TDHPoint; - -public class TDHShear implements TDHTransform { - public final double shx; - public final double shy; - - @Override - public TDHTransformType type() { - return TDHTransformType.SHEAR; - } - - public TDHShear(double shx, double shy) { - this.shx = shx; - this.shy = shy; - } - - @Override - public TDHPoint transform(TDHPoint punkt) { - double x = punkt.x + (punkt.y * shx); - double y = punkt.y + (punkt.x * shy); - - return new TDHPoint(x, y, punkt.z); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - long temp; - temp = Double.doubleToLongBits(shx); - result = prime * result + (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(shy); - 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; - TDHShear other = (TDHShear) obj; - if (Double.doubleToLongBits(shx) != Double.doubleToLongBits(other.shx)) - return false; - if (Double.doubleToLongBits(shy) != Double.doubleToLongBits(other.shy)) - return false; - return true; - } - - @Override - public String toString() { - return "TDHShear [shx=" + shx + ", shy=" + shy + "]"; - } -} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/TDHTransform.java b/CSMath/src/bezier/transforms/TDHTransform.java deleted file mode 100644 index 3b8c52e..0000000 --- a/CSMath/src/bezier/transforms/TDHTransform.java +++ /dev/null @@ -1,54 +0,0 @@ -package bezier.transforms; - -import bezier.geom.TDHPoint; - -/** - * Transformation applicable to TDHPoints. - * - * @author bjculkin - * - */ -@FunctionalInterface -public interface TDHTransform { - /** - * Get the type of this transform. - * - * Unknown transformations are assumed to be identity transforms. - * - * @return The type of this transform. - */ - default TDHTransformType type() { - return TDHTransformType.IDENTITY; - } - - /** - * Get the matrix representation of the transform. - * - * Unknown transformations are assumed to be identity transforms. - * - * @return The matrix representation of the transform. - */ - default double[][] matrix() { - return new double[][] { new double[] { 1, 0, 0 }, new double[] { 0, 1, 0 }, new double[] { 0, 0, 1 } }; - } - - /** - * Get the inverse of the transform. - * - * Unknown transformations are assumed to be identity transforms. - * - * @return The inverse the transform. - */ - default TDHTransform invert() { - return new TDHIdentity(); - } - - /** - * Apply the transform to a point. - * - * @param punkt - * The point to transform. - * @return A transformed version of the point. - */ - TDHPoint transform(TDHPoint punkt); -} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/TDHTransformType.java b/CSMath/src/bezier/transforms/TDHTransformType.java deleted file mode 100644 index e64c13d..0000000 --- a/CSMath/src/bezier/transforms/TDHTransformType.java +++ /dev/null @@ -1,42 +0,0 @@ -package bezier.transforms; - -/** - * Types of transform to apply to TDHPoints. - * - * @author bjculkin - * - */ -public enum TDHTransformType { - /** - * Coordinate translation. - */ - TRANSLATE, - /** - * Do nothing transform. - */ - IDENTITY, - /** - * Coordinate scaling. - */ - SCALE, - /** - * Coordinate rotation. - */ - ROTATION, - /** - * Coordinate reflection. - */ - REFLECTION, - /** - * Coordinate shearing. - */ - SHEAR, - /** - * Multiple transformations. - */ - COMBINATION, - /** - * Arbitrary matrix transformation. - */ - MATRIX -} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/TDHTranslate.java b/CSMath/src/bezier/transforms/TDHTranslate.java deleted file mode 100644 index 3d2afe9..0000000 --- a/CSMath/src/bezier/transforms/TDHTranslate.java +++ /dev/null @@ -1,89 +0,0 @@ -package bezier.transforms; - -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 diff --git a/CSMath/src/bezier/transforms/TDHXAxisReflection.java b/CSMath/src/bezier/transforms/TDHXAxisReflection.java deleted file mode 100644 index 1969b9c..0000000 --- a/CSMath/src/bezier/transforms/TDHXAxisReflection.java +++ /dev/null @@ -1,20 +0,0 @@ -package bezier.transforms; - -import bezier.geom.TDHPoint; - -public class TDHXAxisReflection implements TDHTransform { - @Override - public TDHTransformType type() { - return TDHTransformType.REFLECTION; - } - - @Override - public TDHPoint transform(TDHPoint punkt) { - return new TDHPoint(punkt.x, -punkt.y, punkt.z); - } - - @Override - public String toString() { - return "TDHXAxisReflection []"; - } -} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/TDHYAxisReflection.java b/CSMath/src/bezier/transforms/TDHYAxisReflection.java deleted file mode 100644 index eb462ba..0000000 --- a/CSMath/src/bezier/transforms/TDHYAxisReflection.java +++ /dev/null @@ -1,20 +0,0 @@ -package bezier.transforms; - -import bezier.geom.TDHPoint; - -public class TDHYAxisReflection implements TDHTransform { - @Override - public TDHTransformType type() { - return TDHTransformType.REFLECTION; - } - - @Override - public TDHPoint transform(TDHPoint punkt) { - return new TDHPoint(-punkt.x, punkt.y, punkt.z); - } - - @Override - public String toString() { - return "TDHYAxisReflection []"; - } -} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHCombination.java b/CSMath/src/bezier/transforms/geom/TDHCombination.java new file mode 100644 index 0000000..22a0b40 --- /dev/null +++ b/CSMath/src/bezier/transforms/geom/TDHCombination.java @@ -0,0 +1,64 @@ +package bezier.transforms.geom; + +import java.util.ArrayList; +import java.util.List; + +import bezier.geom.TDHPoint; + +public class TDHCombination implements TDHTransform { + public final List forms; + + @Override + public TDHTransformType type() { + return TDHTransformType.COMBINATION; + } + + public TDHCombination(TDHTransform... forms) { + this.forms = new ArrayList<>(forms.length); + + for (TDHTransform form : forms) { + this.forms.add(form); + } + } + + @Override + public TDHPoint transform(TDHPoint punkt) { + TDHPoint ret = punkt; + + for (TDHTransform form : forms) { + ret = form.transform(ret); + } + + return ret; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((forms == null) ? 0 : forms.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TDHCombination other = (TDHCombination) obj; + if (forms == null) { + if (other.forms != null) + return false; + } else if (!forms.equals(other.forms)) + return false; + return true; + } + + @Override + public String toString() { + return "TDHCombination [forms=" + forms + "]"; + } +} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHIdentity.java b/CSMath/src/bezier/transforms/geom/TDHIdentity.java new file mode 100644 index 0000000..f24d1c9 --- /dev/null +++ b/CSMath/src/bezier/transforms/geom/TDHIdentity.java @@ -0,0 +1,21 @@ +package bezier.transforms.geom; + +import bezier.geom.TDHPoint; + +/** + * A transform that does nothing. + * + * @author bjculkin + * + */ +public class TDHIdentity implements TDHTransform { + @Override + public TDHPoint transform(TDHPoint punkt) { + return punkt; + } + + @Override + public String toString() { + return "TDHIdentity []"; + } +} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHLineReflection.java b/CSMath/src/bezier/transforms/geom/TDHLineReflection.java new file mode 100644 index 0000000..cf1e8c2 --- /dev/null +++ b/CSMath/src/bezier/transforms/geom/TDHLineReflection.java @@ -0,0 +1,68 @@ +package bezier.transforms.geom; + +import bezier.geom.TDHPoint; + +public class TDHLineReflection implements TDHTransform { + public final double a; + public final double b; + public final double c; + + public TDHLineReflection(double a, double b, double c) { + this.a = a; + this.b = b; + this.c = c; + } + + @Override + public TDHTransformType type() { + return TDHTransformType.REFLECTION; + } + + @Override + public TDHPoint transform(TDHPoint punkt) { + double com = (a * a - b * b); + + double x = (punkt.x * com) - (2 * a * b * punkt.y) - (2 * a * c * punkt.z); + double y = (-2 * a * b * punkt.x) + (punkt.y * com) - (2 * b * c * punkt.z); + double z = (punkt.z * com); + + return new TDHPoint(x, y, z); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + long temp; + temp = Double.doubleToLongBits(a); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(b); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(c); + 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; + TDHLineReflection other = (TDHLineReflection) obj; + if (Double.doubleToLongBits(a) != Double.doubleToLongBits(other.a)) + return false; + if (Double.doubleToLongBits(b) != Double.doubleToLongBits(other.b)) + return false; + if (Double.doubleToLongBits(c) != Double.doubleToLongBits(other.c)) + return false; + return true; + } + + @Override + public String toString() { + return "TDHLineReflection [a=" + a + ", b=" + b + ", c=" + c + "]"; + } +} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHMatrixTransform.java b/CSMath/src/bezier/transforms/geom/TDHMatrixTransform.java new file mode 100644 index 0000000..ace590d --- /dev/null +++ b/CSMath/src/bezier/transforms/geom/TDHMatrixTransform.java @@ -0,0 +1,32 @@ +package bezier.transforms.geom; + +import bezier.geom.Matrix; +import bezier.geom.TDHPoint; + +public class TDHMatrixTransform implements TDHTransform { + public final Matrix mat; + + public TDHMatrixTransform(Matrix mat) { + this.mat = mat; + } + + public TDHMatrixTransform(double[][] mat) { + this.mat = new Matrix(mat); + } + + @Override + public TDHTransformType type() { + return TDHTransformType.MATRIX; + } + + @Override + public TDHPoint transform(TDHPoint punkt) { + double[] mult = mat.scalarMultiply(new double[] { punkt.x, punkt.y, punkt.z }); + + return new TDHPoint(mult[0], mult[1], mult[2]); + } + + public TDHTransform then(TDHMatrixTransform trans) { + return new TDHMatrixTransform(mat.multiply(trans.mat)); + } +} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHPointRotation.java b/CSMath/src/bezier/transforms/geom/TDHPointRotation.java new file mode 100644 index 0000000..bc3c716 --- /dev/null +++ b/CSMath/src/bezier/transforms/geom/TDHPointRotation.java @@ -0,0 +1,67 @@ +package bezier.transforms.geom; + +import bezier.geom.TDHPoint; + +public class TDHPointRotation extends TDHRotation { + public final double x0; + public final double y0; + + public TDHPointRotation(double theta, double x0, double y0) { + super(theta); + + this.x0 = x0; + this.y0 = y0; + } + + @Override + public TDHTransformType type() { + return TDHTransformType.ROTATION; + } + + @Override + public TDHPoint transform(TDHPoint punkt) { + double x1 = (punkt.x * Math.cos(theta)) - (punkt.y * Math.sin(theta)); + double y1 = (punkt.x * Math.sin(theta)) - (punkt.y * Math.cos(theta)); + + double x2 = (-x0 * Math.cos(theta)) + (y0 * Math.sin(theta)) + x0; + double y2 = (-x0 * Math.sin(theta)) - (y0 * Math.cos(theta)) + y0; + + double x = x1 + (punkt.z * x2); + double y = y1 + (punkt.z * y2); + + return new TDHPoint(x, y, punkt.z); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + long temp; + temp = Double.doubleToLongBits(x0); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(y0); + result = prime * result + (int) (temp ^ (temp >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + TDHPointRotation other = (TDHPointRotation) obj; + if (Double.doubleToLongBits(x0) != Double.doubleToLongBits(other.x0)) + return false; + if (Double.doubleToLongBits(y0) != Double.doubleToLongBits(other.y0)) + return false; + return true; + } + + @Override + public String toString() { + return "TDHPointRotation [x0=" + x0 + ", y0=" + y0 + "]"; + } +} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHRotation.java b/CSMath/src/bezier/transforms/geom/TDHRotation.java new file mode 100644 index 0000000..8870b53 --- /dev/null +++ b/CSMath/src/bezier/transforms/geom/TDHRotation.java @@ -0,0 +1,57 @@ +package bezier.transforms.geom; + +import bezier.geom.TDHPoint; + +public class TDHRotation implements TDHTransform { + public final double theta; + + public TDHRotation(double theta) { + this.theta = theta; + } + + @Override + public TDHPoint transform(TDHPoint punkt) { + double x = (punkt.x * Math.cos(theta)) - (punkt.y * Math.sin(theta)); + double y = (punkt.x * Math.sin(theta)) - (punkt.y * Math.cos(theta)); + + return new TDHPoint(x, y, punkt.z); + } + + public double[][] matrix() { + return new double[][] { new double[] { Math.cos(theta), Math.sin(theta), 0 }, + new double[] { -Math.sin(theta), Math.cos(theta), 0 }, new double[] { 0, 0, 1 } }; + } + + public TDHTransform invert() { + return new TDHRotation(-theta); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + long temp; + temp = Double.doubleToLongBits(theta); + 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; + TDHRotation other = (TDHRotation) obj; + if (Double.doubleToLongBits(theta) != Double.doubleToLongBits(other.theta)) + return false; + return true; + } + + @Override + public String toString() { + return "TDHRotation [theta=" + theta + "]"; + } +} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHScale.java b/CSMath/src/bezier/transforms/geom/TDHScale.java new file mode 100644 index 0000000..a6db9a9 --- /dev/null +++ b/CSMath/src/bezier/transforms/geom/TDHScale.java @@ -0,0 +1,124 @@ +package bezier.transforms.geom; + +import bezier.geom.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 diff --git a/CSMath/src/bezier/transforms/geom/TDHShear.java b/CSMath/src/bezier/transforms/geom/TDHShear.java new file mode 100644 index 0000000..c0c72ca --- /dev/null +++ b/CSMath/src/bezier/transforms/geom/TDHShear.java @@ -0,0 +1,59 @@ +package bezier.transforms.geom; + +import bezier.geom.TDHPoint; + +public class TDHShear implements TDHTransform { + public final double shx; + public final double shy; + + @Override + public TDHTransformType type() { + return TDHTransformType.SHEAR; + } + + public TDHShear(double shx, double shy) { + this.shx = shx; + this.shy = shy; + } + + @Override + public TDHPoint transform(TDHPoint punkt) { + double x = punkt.x + (punkt.y * shx); + double y = punkt.y + (punkt.x * shy); + + return new TDHPoint(x, y, punkt.z); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + long temp; + temp = Double.doubleToLongBits(shx); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(shy); + 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; + TDHShear other = (TDHShear) obj; + if (Double.doubleToLongBits(shx) != Double.doubleToLongBits(other.shx)) + return false; + if (Double.doubleToLongBits(shy) != Double.doubleToLongBits(other.shy)) + return false; + return true; + } + + @Override + public String toString() { + return "TDHShear [shx=" + shx + ", shy=" + shy + "]"; + } +} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHTransform.java b/CSMath/src/bezier/transforms/geom/TDHTransform.java new file mode 100644 index 0000000..20afc53 --- /dev/null +++ b/CSMath/src/bezier/transforms/geom/TDHTransform.java @@ -0,0 +1,54 @@ +package bezier.transforms.geom; + +import bezier.geom.TDHPoint; + +/** + * Transformation applicable to TDHPoints. + * + * @author bjculkin + * + */ +@FunctionalInterface +public interface TDHTransform { + /** + * Get the type of this transform. + * + * Unknown transformations are assumed to be identity transforms. + * + * @return The type of this transform. + */ + default TDHTransformType type() { + return TDHTransformType.IDENTITY; + } + + /** + * Get the matrix representation of the transform. + * + * Unknown transformations are assumed to be identity transforms. + * + * @return The matrix representation of the transform. + */ + default double[][] matrix() { + return new double[][] { new double[] { 1, 0, 0 }, new double[] { 0, 1, 0 }, new double[] { 0, 0, 1 } }; + } + + /** + * Get the inverse of the transform. + * + * Unknown transformations are assumed to be identity transforms. + * + * @return The inverse the transform. + */ + default TDHTransform invert() { + return new TDHIdentity(); + } + + /** + * Apply the transform to a point. + * + * @param punkt + * The point to transform. + * @return A transformed version of the point. + */ + TDHPoint transform(TDHPoint punkt); +} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHTransformType.java b/CSMath/src/bezier/transforms/geom/TDHTransformType.java new file mode 100644 index 0000000..909afdc --- /dev/null +++ b/CSMath/src/bezier/transforms/geom/TDHTransformType.java @@ -0,0 +1,42 @@ +package bezier.transforms.geom; + +/** + * Types of transform to apply to TDHPoints. + * + * @author bjculkin + * + */ +public enum TDHTransformType { + /** + * Coordinate translation. + */ + TRANSLATE, + /** + * Do nothing transform. + */ + IDENTITY, + /** + * Coordinate scaling. + */ + SCALE, + /** + * Coordinate rotation. + */ + ROTATION, + /** + * Coordinate reflection. + */ + REFLECTION, + /** + * Coordinate shearing. + */ + SHEAR, + /** + * Multiple transformations. + */ + COMBINATION, + /** + * Arbitrary matrix transformation. + */ + MATRIX +} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHTranslate.java b/CSMath/src/bezier/transforms/geom/TDHTranslate.java new file mode 100644 index 0000000..905711f --- /dev/null +++ b/CSMath/src/bezier/transforms/geom/TDHTranslate.java @@ -0,0 +1,89 @@ +package bezier.transforms.geom; + +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 diff --git a/CSMath/src/bezier/transforms/geom/TDHXAxisReflection.java b/CSMath/src/bezier/transforms/geom/TDHXAxisReflection.java new file mode 100644 index 0000000..4b4bffe --- /dev/null +++ b/CSMath/src/bezier/transforms/geom/TDHXAxisReflection.java @@ -0,0 +1,20 @@ +package bezier.transforms.geom; + +import bezier.geom.TDHPoint; + +public class TDHXAxisReflection implements TDHTransform { + @Override + public TDHTransformType type() { + return TDHTransformType.REFLECTION; + } + + @Override + public TDHPoint transform(TDHPoint punkt) { + return new TDHPoint(punkt.x, -punkt.y, punkt.z); + } + + @Override + public String toString() { + return "TDHXAxisReflection []"; + } +} \ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHYAxisReflection.java b/CSMath/src/bezier/transforms/geom/TDHYAxisReflection.java new file mode 100644 index 0000000..39e9f18 --- /dev/null +++ b/CSMath/src/bezier/transforms/geom/TDHYAxisReflection.java @@ -0,0 +1,20 @@ +package bezier.transforms.geom; + +import bezier.geom.TDHPoint; + +public class TDHYAxisReflection implements TDHTransform { + @Override + public TDHTransformType type() { + return TDHTransformType.REFLECTION; + } + + @Override + public TDHPoint transform(TDHPoint punkt) { + return new TDHPoint(-punkt.x, punkt.y, punkt.z); + } + + @Override + public String toString() { + return "TDHYAxisReflection []"; + } +} \ No newline at end of file -- cgit v1.2.3