diff options
| author | bjculkin <bjculkin@BECK-DZ9BJB2.wvu-ad.wvu.edu> | 2018-04-11 15:29:25 -0400 |
|---|---|---|
| committer | bjculkin <bjculkin@BECK-DZ9BJB2.wvu-ad.wvu.edu> | 2018-04-11 15:29:25 -0400 |
| commit | dcb6c2159446135a142cad41eec185bb24c45bfb (patch) | |
| tree | 965dcc07fc0256a9a8254d5f968e316a1e928617 /CSMath/src/bezier/TDPoint.java | |
| parent | 8ecf52b6c5821e5c3de8a0f5c9e7ed3e357cb282 (diff) | |
Split #9 into one class/file
Diffstat (limited to 'CSMath/src/bezier/TDPoint.java')
| -rw-r--r-- | CSMath/src/bezier/TDPoint.java | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/CSMath/src/bezier/TDPoint.java b/CSMath/src/bezier/TDPoint.java new file mode 100644 index 0000000..79f95df --- /dev/null +++ b/CSMath/src/bezier/TDPoint.java @@ -0,0 +1,111 @@ +package bezier;
+
+/**
+ * Represents a two-dimensional point.
+ *
+ * @author bjculkin
+ *
+ */
+public class TDPoint {
+ /**
+ * The x coordinate.
+ */
+ public final double x;
+
+ /**
+ * The y coordinate.
+ */
+ public final double y;
+
+ /**
+ * Create a new two-dimensional point.
+ *
+ * @param x
+ * The x coordinate.
+ * @param y
+ * The y coordinate.
+ */
+ public TDPoint(double x, double y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ /**
+ * Create a new two-dimensional point.
+ *
+ * @param x
+ * The x coordinate.
+ * @param y
+ * The y coordinate.
+ * @return A point with those coordinates.
+ */
+ public static TDPoint p2(double x, double y) {
+ return new TDPoint(x, y);
+ }
+
+ /**
+ * Return a new scaled point.
+ *
+ * @param s
+ * The amount to scale by.
+ * @return A point scaled by the specified amount.
+ */
+ public TDPoint multiply(double s) {
+ return p2(x * s, y * s);
+ }
+
+ /**
+ * Add two points together.
+ *
+ * @param p1
+ * The first point to add.
+ * @param p2
+ * The second point to add.
+ * @return The sum of the points.
+ */
+ public static TDPoint add(TDPoint p1, TDPoint p2) {
+ return p2(p1.x + p2.x, p1.y + p2.y);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ long temp;
+ temp = Double.doubleToLongBits(x);
+ result = prime * result + (int) (temp ^ (temp >>> 32));
+ temp = Double.doubleToLongBits(y);
+ 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;
+ TDPoint other = (TDPoint) obj;
+ if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x))
+ return false;
+ if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "TDPoint [x=" + x + ", y=" + y + "]";
+ }
+
+ /**
+ * Convert this point to a two-dimensional homogeneous point.
+ *
+ * @return A homogeneous version of this point.
+ */
+ public TDHPoint toTDHPoint() {
+ return new TDHPoint(x, y);
+ }
+}
\ No newline at end of file |
