From 5fdb8554aa59432924c6cf2cf4e8c178c5856deb Mon Sep 17 00:00:00 2001 From: student Date: Wed, 11 Apr 2018 17:06:20 -0400 Subject: Update --- CSMath/src/bezier/geom/TDPoint.java | 111 ++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 CSMath/src/bezier/geom/TDPoint.java (limited to 'CSMath/src/bezier/geom/TDPoint.java') 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 -- cgit v1.2.3