Package common

Class Point

java.lang.Object
common.Point
All Implemented Interfaces:
Comparable<Point>

public class Point extends Object implements Comparable<Point>
Initializes a new point. Provides a representation of a Point at location (x,y)
Author:
Krish Pillai
  • Constructor Summary

    Constructors
    Constructor
    Description
    Point(int x, int y)
    Initializes a new point.
    Point(Point that)
    Initializes a new point as copy of the argument.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Compares two points by y-coordinate, breaking ties by x-coordinate.
    float
    Returns the Euclidean distance from this point to that point.
    int
     
    int
     
    Compares two points by the slope they make with this point.
    double
    slopeTo(Point that)
    Returns the slope between this point and the specified point.
    Returns a string representation of this point.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Point

      public Point(int x, int y)
      Initializes a new point.
      Parameters:
      x - the x-coordinate of the point
      y - the y-coordinate of the point
    • Point

      public Point(Point that)
      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

      public double slopeTo(Point that)
      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

      public int compareTo(Point that)
      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:
      compareTo in interface Comparable<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

      public Comparator<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

      public float distance(Point that)
      Returns the Euclidean distance from this point to that point.
      Parameters:
      that - the distance point
      Returns:
      the Euclidean distance as a float.
    • toString

      public String toString()
      Returns a string representation of this point. This method is provided for debugging.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this point