Package common
Class Point
java.lang.Object
common.Point
- All Implemented Interfaces:
Comparable<Point>
Initializes a new point.
Provides a representation of a Point at location (x,y)
- Author:
- Krish Pillai
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintCompares two points by y-coordinate, breaking ties by x-coordinate.floatReturns the Euclidean distance from this point to that point.intgetX()intgetY()Compares two points by the slope they make with this point.doubleReturns the slope between this point and the specified point.toString()Returns a string representation of this point.
-
Constructor Details
-
Point
public Point(int x, int y) Initializes a new point.- Parameters:
x- the x-coordinate of the pointy- the y-coordinate of the point
-
Point
Initializes a new point as copy of the argument.- Parameters:
that- the point that is to be cloned
-
-
Method Details
-
getX
public int getX()- Returns:
- the x-coordinate of the point
-
getY
public int getY()- Returns:
- the y-coordinate of the point
-
slopeTo
Returns the slope between this point and the specified point. Formally, if the two points are (x0, y0) and (x1, y1), then the slope is (y1 - y0) / (x1 - x0). For completeness, the slope is defined to be +0.0 if the line segment connecting the two points is horizontal; Double.POSITIVE_INFINITY if the line segment is vertical; and Double.NEGATIVE_INFINITY if (x0, y0) and (x1, y1) are equal.- Parameters:
that- the other point- Returns:
- the slope between this point and the specified point
-
compareTo
Compares two points by y-coordinate, breaking ties by x-coordinate. Formally, the invoking point (x0, y0) is less than the argument point (x1, y1) if and only if either y0 < y1 or if y0 = y1 and x0 < x1.- Specified by:
compareToin interfaceComparable<Point>- Parameters:
that- the other point- Returns:
- the value 0 if this point is equal to the argument point (x0 = x1 and y0 = y1); a negative integer if this point is less than the argument point; and a positive integer if this point is greater than the argument point
-
slopeOrder
Compares two points by the slope they make with this point. The slope is defined as in the slopeTo() method.- Returns:
- the Comparator that defines this ordering on points
-
distance
Returns the Euclidean distance from this point to that point.- Parameters:
that- the distance point- Returns:
- the Euclidean distance as a float.
-
toString
Returns a string representation of this point. This method is provided for debugging.
-