summaryrefslogtreecommitdiff
path: root/CSMath/src/bezier/geom/TDPoint.java
diff options
context:
space:
mode:
authorstudent <student@localhost>2018-04-11 17:06:20 -0400
committerstudent <student@localhost>2018-04-11 17:06:20 -0400
commit5fdb8554aa59432924c6cf2cf4e8c178c5856deb (patch)
tree9fb86d7ed82887c883ba0bd9c462619a6f96499e /CSMath/src/bezier/geom/TDPoint.java
parentdcb6c2159446135a142cad41eec185bb24c45bfb (diff)
Update
Diffstat (limited to 'CSMath/src/bezier/geom/TDPoint.java')
-rw-r--r--CSMath/src/bezier/geom/TDPoint.java111
1 files changed, 111 insertions, 0 deletions
diff --git a/CSMath/src/bezier/geom/TDPoint.java b/CSMath/src/bezier/geom/TDPoint.java
new file mode 100644
index 0000000..8074461
--- /dev/null
+++ b/CSMath/src/bezier/geom/TDPoint.java
@@ -0,0 +1,111 @@
+package bezier.geom;
+
+/**
+ * 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