diff options
Diffstat (limited to 'CSMath/src/bezier/geom')
| -rw-r--r-- | CSMath/src/bezier/geom/Bezier.java | 32 | ||||
| -rw-r--r-- | CSMath/src/bezier/geom/BezierProperties.java | 74 | ||||
| -rw-r--r-- | CSMath/src/bezier/geom/Matrix.java | 76 | ||||
| -rw-r--r-- | CSMath/src/bezier/geom/transform/TDHCombination.java | 12 | ||||
| -rw-r--r-- | CSMath/src/bezier/geom/transform/TDHLineReflection.java | 20 | ||||
| -rw-r--r-- | CSMath/src/bezier/geom/transform/TDHMatrixTransform.java | 28 | ||||
| -rw-r--r-- | CSMath/src/bezier/geom/transform/TDHPointRotation.java | 17 | ||||
| -rw-r--r-- | CSMath/src/bezier/geom/transform/TDHRotation.java | 14 | ||||
| -rw-r--r-- | CSMath/src/bezier/geom/transform/TDHScale.java | 1 | ||||
| -rw-r--r-- | CSMath/src/bezier/geom/transform/TDHShear.java | 16 | ||||
| -rw-r--r-- | CSMath/src/bezier/geom/transform/TDHXAxisReflection.java | 5 | ||||
| -rw-r--r-- | CSMath/src/bezier/geom/transform/TDHYAxisReflection.java | 5 |
12 files changed, 241 insertions, 59 deletions
diff --git a/CSMath/src/bezier/geom/Bezier.java b/CSMath/src/bezier/geom/Bezier.java index dbc6a12..0a70db3 100644 --- a/CSMath/src/bezier/geom/Bezier.java +++ b/CSMath/src/bezier/geom/Bezier.java @@ -24,7 +24,7 @@ public class Bezier { * Create a new bezier curve from a set of control points.
*
* @param points
- * The control points to use.
+ * The control points to use.
*/
public Bezier(TDPoint... points) {
data = new BezierProperties();
@@ -40,7 +40,7 @@ public class Bezier { * Do a scaled evaluation of the curve.
*
* @param t
- * The value to evaluate at.
+ * The value to evaluate at.
* @return The point on the curve, scaled by the curves scaling factor.
*/
public TDPoint scaleEval(double t) {
@@ -51,11 +51,11 @@ public class Bezier { * Do a scaled evaluation of the curve.
*
* @param t
- * The value to evaluate at.
+ * The value to evaluate at.
+ * @return The point on the curve.
*/
public TDPoint eval(double t) {
- if (controls.isEmpty())
- return new TDPoint(0, 0);
+ if (controls.isEmpty()) return new TDPoint(0, 0);
TDPoint punkt = evalIntern(t, controls.size() - 1, 0);
@@ -95,7 +95,7 @@ public class Bezier { * Split a curve into two curves at a specific point.
*
* @param t
- * The point to split the curve at.
+ * The point to split the curve at.
* @return The two curves, split at that point.
*/
public Bezier[] decompose(double t) {
@@ -136,10 +136,11 @@ public class Bezier { }
/**
- * Get the bounding box for a transformed version of this curves control points.
+ * Get the bounding box for a transformed version of this curves control
+ * points.
*
* @param transform
- * The transform to apply to the control points.
+ * The transform to apply to the control points.
* @return The bounding box for the transformed control points.
*/
public TDPoint[] extrema(TDHTransform transform) {
@@ -197,18 +198,13 @@ public class Bezier { @Override
public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (getClass() != obj.getClass()) return false;
Bezier other = (Bezier) obj;
if (controls == null) {
- if (other.controls != null)
- return false;
- } else if (!controls.equals(other.controls))
- return false;
+ if (other.controls != null) return false;
+ } else if (!controls.equals(other.controls)) return false;
return true;
}
diff --git a/CSMath/src/bezier/geom/BezierProperties.java b/CSMath/src/bezier/geom/BezierProperties.java index 1b5443d..d73c1f1 100644 --- a/CSMath/src/bezier/geom/BezierProperties.java +++ b/CSMath/src/bezier/geom/BezierProperties.java @@ -2,6 +2,12 @@ package bezier.geom; import java.awt.Color;
+/**
+ * Properties for graphing a bezier curve.
+ *
+ * @author bjculkin
+ *
+ */
public class BezierProperties {
/**
* The number of separate points to graph from the curve.
@@ -14,15 +20,38 @@ public class BezierProperties { public double scale = 5;
/**
- * The colors for varying parts of the curve.
+ * The color for the curve itself.
*/
- public Color curveColor = Color.BLACK;
- public Color pointColor = Color.RED;
- public Color boxColor = Color.GREEN;
+ public Color curveColor = Color.BLACK;
+ /**
+ * The color for the points in the curve.
+ */
+ public Color pointColor = Color.RED;
+ /**
+ * The color for the bounding box.
+ */
+ public Color boxColor = Color.GREEN;
+ /**
+ * Create a new set of default bezier properties.
+ */
public BezierProperties() {
}
+ /**
+ * Create a new set of bezier properties, with specific values.
+ *
+ * @param parts
+ * The number of points to graph in the curve.
+ * @param scale
+ * The amount to scale the curve by.
+ * @param curveColor
+ * The color for the curve.
+ * @param pointColor
+ * The color for the points in the curve.
+ * @param boxColor
+ * The color for the bounding box of the curve.
+ */
public BezierProperties(int parts, double scale, Color curveColor, Color pointColor, Color boxColor) {
this.parts = parts;
this.scale = scale;
@@ -47,38 +76,27 @@ public class BezierProperties { @Override
public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (getClass() != obj.getClass()) return false;
BezierProperties other = (BezierProperties) obj;
if (boxColor == null) {
- if (other.boxColor != null)
- return false;
- } else if (!boxColor.equals(other.boxColor))
- return false;
+ if (other.boxColor != null) return false;
+ } else if (!boxColor.equals(other.boxColor)) return false;
if (curveColor == null) {
- if (other.curveColor != null)
- return false;
- } else if (!curveColor.equals(other.curveColor))
- return false;
- if (parts != other.parts)
- return false;
+ if (other.curveColor != null) return false;
+ } else if (!curveColor.equals(other.curveColor)) return false;
+ if (parts != other.parts) return false;
if (pointColor == null) {
- if (other.pointColor != null)
- return false;
- } else if (!pointColor.equals(other.pointColor))
- return false;
- if (Double.doubleToLongBits(scale) != Double.doubleToLongBits(other.scale))
- return false;
+ if (other.pointColor != null) return false;
+ } else if (!pointColor.equals(other.pointColor)) return false;
+ if (Double.doubleToLongBits(scale) != Double.doubleToLongBits(other.scale)) return false;
return true;
}
@Override
public String toString() {
- return "BezierProperties [parts=" + parts + ", scale=" + scale + ", curveColor=" + curveColor + ", pointColor="
- + pointColor + ", boxColor=" + boxColor + "]";
+ return "BezierProperties [parts=" + parts + ", scale=" + scale + ", curveColor=" + curveColor
+ + ", pointColor=" + pointColor + ", boxColor=" + boxColor + "]";
}
}
\ No newline at end of file diff --git a/CSMath/src/bezier/geom/Matrix.java b/CSMath/src/bezier/geom/Matrix.java index a728a02..f9395ea 100644 --- a/CSMath/src/bezier/geom/Matrix.java +++ b/CSMath/src/bezier/geom/Matrix.java @@ -1,44 +1,94 @@ package bezier.geom; +/** + * Matrix class. + * + * @author bjculkin + * + */ public class Matrix { + /** + * Matrix values. + */ public final double[][] mat; + /** + * Create a new matrix, with the specified values. + * + * @param mat + * The matrix to use. + */ public Matrix(double[][] mat) { this.mat = mat; } - + + /** + * Add two matrices together. + * + * @param m + * The matrix to add. + * @return An added matrix. + */ public Matrix add(Matrix m) { return add(m.mat); } - + + /** + * Multiply this matrix by a scalar vector. + * + * @param vec + * The vector to multiply by. + * @return The resulting vector. + */ public double[] scalarMultiply(double[] vec) { double[] ret = new double[vec.length]; - - for(int i = 0; i < mat[0].length; i++) { - for(int j = 0; j < mat.length; j++) { + + for (int i = 0; i < mat[0].length; i++) { + for (int j = 0; j < mat.length; j++) { ret[i] += mat[i][j] * vec[j]; } } - + return ret; } - + + /** + * Add a matrix to this one. + * + * @param matr + * The matrix to add. + * @return The resulting matrix. + */ public Matrix add(double[][] matr) { double[][] ret = new double[mat.length][mat[0].length]; - - for(int i = 0; i < mat.length; i++) { - for(int j = 0; j < mat[0].length; j++) { + + for (int i = 0; i < mat.length; i++) { + for (int j = 0; j < mat[0].length; j++) { ret[i][j] = mat[i][j] + matr[i][j]; } } - + return new Matrix(ret); } - + + /** + * Multiply this matrix by another. + * + * @param m + * The matrix to multiply by + * @return The multiplied matrix. + */ public Matrix multiply(Matrix m) { return multiply(m.mat); } - + + /** + * Multiply this matrix by another. + * + * @param matr + * The matrix to multiply by + * @return The multiplied matrix. + */ public Matrix multiply(double[][] matr) { double[][] ret = new double[mat.length][matr[0].length]; diff --git a/CSMath/src/bezier/geom/transform/TDHCombination.java b/CSMath/src/bezier/geom/transform/TDHCombination.java index 27d71e7..65dec7c 100644 --- a/CSMath/src/bezier/geom/transform/TDHCombination.java +++ b/CSMath/src/bezier/geom/transform/TDHCombination.java @@ -5,7 +5,15 @@ import java.util.List; import bezier.geom.TDHPoint;
+/**
+ * Combination of 2D homogenous transforms.
+ * @author bjculkin
+ *
+ */
public class TDHCombination implements TDHTransform {
+ /**
+ * The transforms that make up this transform.
+ */
public final List<TDHTransform> forms;
@Override
@@ -13,6 +21,10 @@ public class TDHCombination implements TDHTransform { return TDHTransformType.COMBINATION;
}
+ /**
+ * Create a new combined transform.
+ * @param forms The transforms to combine.
+ */
public TDHCombination(TDHTransform... forms) {
this.forms = new ArrayList<>(forms.length);
diff --git a/CSMath/src/bezier/geom/transform/TDHLineReflection.java b/CSMath/src/bezier/geom/transform/TDHLineReflection.java index 0158d60..1ebb76e 100644 --- a/CSMath/src/bezier/geom/transform/TDHLineReflection.java +++ b/CSMath/src/bezier/geom/transform/TDHLineReflection.java @@ -2,11 +2,31 @@ package bezier.geom.transform; import bezier.geom.TDHPoint;
+/**
+ * Transform to reflect across a line.
+ * @author bjculkin
+ *
+ */
public class TDHLineReflection implements TDHTransform {
+ /**
+ * 'a' value for line.
+ */
public final double a;
+ /**
+ * 'b' value for line.
+ */
public final double b;
+ /**
+ * 'c' value for line.
+ */
public final double c;
+ /**
+ * Create a new line-reflect transform.
+ * @param a 'a' value for the line.
+ * @param b 'b' value for the line.
+ * @param c 'c' value for the line.
+ */
public TDHLineReflection(double a, double b, double c) {
this.a = a;
this.b = b;
diff --git a/CSMath/src/bezier/geom/transform/TDHMatrixTransform.java b/CSMath/src/bezier/geom/transform/TDHMatrixTransform.java index 5014d1f..0952703 100644 --- a/CSMath/src/bezier/geom/transform/TDHMatrixTransform.java +++ b/CSMath/src/bezier/geom/transform/TDHMatrixTransform.java @@ -3,13 +3,34 @@ package bezier.geom.transform; import bezier.geom.Matrix;
import bezier.geom.TDHPoint;
+/**
+ * 2D homogenous transform defined by a matrix.
+ *
+ * @author bjculkin
+ *
+ */
public class TDHMatrixTransform implements TDHTransform {
+ /**
+ * The matrix for the transform.
+ */
public final Matrix mat;
+ /**
+ * Create a new matrix-based transform.
+ *
+ * @param mat
+ * The matrix that defines the transform.
+ */
public TDHMatrixTransform(Matrix mat) {
this.mat = mat;
}
+ /**
+ * Create a new matrix-based transform.
+ *
+ * @param mat
+ * The matrix that defines the transform.
+ */
public TDHMatrixTransform(double[][] mat) {
this.mat = new Matrix(mat);
}
@@ -26,6 +47,13 @@ public class TDHMatrixTransform implements TDHTransform { return new TDHPoint(mult[0], mult[1], mult[2]);
}
+ /**
+ * Chain two matrix transforms together.
+ *
+ * @param trans
+ * The next transform to use.
+ * @return A transform that represents the two transforms in serial.
+ */
public TDHTransform then(TDHMatrixTransform trans) {
return new TDHMatrixTransform(mat.multiply(trans.mat));
}
diff --git a/CSMath/src/bezier/geom/transform/TDHPointRotation.java b/CSMath/src/bezier/geom/transform/TDHPointRotation.java index a207612..c92b172 100644 --- a/CSMath/src/bezier/geom/transform/TDHPointRotation.java +++ b/CSMath/src/bezier/geom/transform/TDHPointRotation.java @@ -2,10 +2,27 @@ package bezier.geom.transform; import bezier.geom.TDHPoint;
+/**
+ * Transformation doing rotation about a point.
+ * @author bjculkin
+ *
+ */
public class TDHPointRotation extends TDHRotation {
+ /**
+ * x-coordinate of point.
+ */
public final double x0;
+ /**
+ * y-coordinate of point.
+ */
public final double y0;
+ /**
+ * Create a new point rotation.
+ * @param theta The degrees to rotate about the point.
+ * @param x0 The x-coordinate of the point.
+ * @param y0 The y-coordinate of the point.
+ */
public TDHPointRotation(double theta, double x0, double y0) {
super(theta);
diff --git a/CSMath/src/bezier/geom/transform/TDHRotation.java b/CSMath/src/bezier/geom/transform/TDHRotation.java index a8c4cd6..4cea452 100644 --- a/CSMath/src/bezier/geom/transform/TDHRotation.java +++ b/CSMath/src/bezier/geom/transform/TDHRotation.java @@ -2,9 +2,21 @@ package bezier.geom.transform; import bezier.geom.TDHPoint;
+/**
+ * Rotation transform.
+ * @author bjculkin
+ *
+ */
public class TDHRotation implements TDHTransform {
+ /**
+ * Degrees to rotate.
+ */
public final double theta;
+ /**
+ * Create a new rotation transform.
+ * @param theta The degrees to rotate.
+ */
public TDHRotation(double theta) {
this.theta = theta;
}
@@ -17,11 +29,13 @@ public class TDHRotation implements TDHTransform { return new TDHPoint(x, y, punkt.z);
}
+ @Override
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 } };
}
+ @Override
public TDHTransform invert() {
return new TDHRotation(-theta);
}
diff --git a/CSMath/src/bezier/geom/transform/TDHScale.java b/CSMath/src/bezier/geom/transform/TDHScale.java index 83c7a63..c064f1b 100644 --- a/CSMath/src/bezier/geom/transform/TDHScale.java +++ b/CSMath/src/bezier/geom/transform/TDHScale.java @@ -81,6 +81,7 @@ public class TDHScale implements TDHTransform { return new double[][] { new double[] { sx, 0, 0 }, new double[] { 0, sy, 0 }, new double[] { 0, 0, sz } };
}
+ @Override
public TDHTransform invert() {
return new TDHScale(1 / sx, 1 / sy, 1 / sy);
}
diff --git a/CSMath/src/bezier/geom/transform/TDHShear.java b/CSMath/src/bezier/geom/transform/TDHShear.java index f099e74..7e09b63 100644 --- a/CSMath/src/bezier/geom/transform/TDHShear.java +++ b/CSMath/src/bezier/geom/transform/TDHShear.java @@ -2,8 +2,19 @@ package bezier.geom.transform; import bezier.geom.TDHPoint;
+/**
+ * Shear transform.
+ * @author bjculkin
+ *
+ */
public class TDHShear implements TDHTransform {
+ /**
+ * x-value for shear.
+ */
public final double shx;
+ /**
+ * y-value for shear.
+ */
public final double shy;
@Override
@@ -11,6 +22,11 @@ public class TDHShear implements TDHTransform { return TDHTransformType.SHEAR;
}
+ /**
+ * Create a new shear transform.
+ * @param shx The x-value for shearing.
+ * @param shy The y-value for shearing.
+ */
public TDHShear(double shx, double shy) {
this.shx = shx;
this.shy = shy;
diff --git a/CSMath/src/bezier/geom/transform/TDHXAxisReflection.java b/CSMath/src/bezier/geom/transform/TDHXAxisReflection.java index 21af1a8..0324c88 100644 --- a/CSMath/src/bezier/geom/transform/TDHXAxisReflection.java +++ b/CSMath/src/bezier/geom/transform/TDHXAxisReflection.java @@ -2,6 +2,11 @@ package bezier.geom.transform; import bezier.geom.TDHPoint;
+/**
+ * Reflect about x-axis.
+ * @author bjculkin
+ *
+ */
public class TDHXAxisReflection implements TDHTransform {
@Override
public TDHTransformType type() {
diff --git a/CSMath/src/bezier/geom/transform/TDHYAxisReflection.java b/CSMath/src/bezier/geom/transform/TDHYAxisReflection.java index c4ada7f..7e8f6d9 100644 --- a/CSMath/src/bezier/geom/transform/TDHYAxisReflection.java +++ b/CSMath/src/bezier/geom/transform/TDHYAxisReflection.java @@ -2,6 +2,11 @@ package bezier.geom.transform; import bezier.geom.TDHPoint;
+/**
+ * Reflect about y-axis.
+ * @author bjculkin
+ *
+ */
public class TDHYAxisReflection implements TDHTransform {
@Override
public TDHTransformType type() {
|
