Package dsa

Class Point2D

    • Constructor Summary

      Constructors 
      Constructor Description
      Point2D​(double x, double y)
      Constructs a point (x, y).
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Comparator<Point2D> atan2Order()
      Returns a comparator for comparing two points by the atan2 angle (-pi to pi) they make with this point.
      int compareTo​(Point2D other)
      Returns a comparison of this point with other, by their x- and y-coordinates.
      double distanceSquaredTo​(Point2D other)
      Returns the squared Euclidean distance between this point and other.
      double distanceTo​(Point2D other)
      Returns the Euclidean distance between this point and other.
      Comparator<Point2D> distanceToOrder()
      Returns a comparator for comparing two points by their distance to this point.
      void draw()
      Draws this point using standard draw.
      void drawTo​(Point2D other)
      Draws a line between this point and other using standard draw.
      boolean equals​(Object other)
      Returns true if this point and other have the same x- and y-coordinates, and false otherwise.
      int hashCode()
      Returns a hash code for this point.
      static void main​(String[] args)
      Unit tests the data type.
      Comparator<Point2D> polarOrder()
      Returns a comparator for comparing two points by the polar angle (0 to 2pi) they make with this point.
      double r()
      Returns the polar radius of this point.
      static Comparator<Point2D> rOrder()
      Returns a comparator for comparing two points by their polar radius.
      double theta()
      Returns the polar angle (-pi to pi) of this point.
      String toString()
      Returns a string representation of this point.
      double x()
      Returns the x-coordinate of this point.
      static Comparator<Point2D> xOrder()
      Returns a comparator for comparing two points by their x-coordinate.
      double y()
      Returns the y-coordinate of this point.
      static Comparator<Point2D> yOrder()
      Returns a comparator for comparing two points by their y-coordinate.
    • Constructor Detail

      • Point2D

        public Point2D​(double x,
                       double y)
        Constructs a point (x, y).
        Parameters:
        x - the x-coordinate.
        y - the y-coordinate.
    • Method Detail

      • x

        public double x()
        Returns the x-coordinate of this point.
        Returns:
        the x-coordinate of this point.
      • y

        public double y()
        Returns the y-coordinate of this point.
        Returns:
        the y-coordinate of this point.
      • r

        public double r()
        Returns the polar radius of this point.
        Returns:
        the polar radius of this point.
      • theta

        public double theta()
        Returns the polar angle (-pi to pi) of this point.
        Returns:
        the polar angle (-pi to pi) of this point.
      • distanceTo

        public double distanceTo​(Point2D other)
        Returns the Euclidean distance between this point and other.
        Parameters:
        other - the other point.
        Returns:
        the Euclidean distance between this point and other.
      • distanceSquaredTo

        public double distanceSquaredTo​(Point2D other)
        Returns the squared Euclidean distance between this point and other.
        Parameters:
        other - the other point.
        Returns:
        the squared Euclidean distance between this point and other.
      • equals

        public boolean equals​(Object other)
        Returns true if this point and other have the same x- and y-coordinates, and false otherwise.
        Overrides:
        equals in class Object
        Parameters:
        other - the other point.
        Returns:
        true if this point and other have the same x- and y-coordinates, and false otherwise.
      • hashCode

        public int hashCode()
        Returns a hash code for this point.
        Overrides:
        hashCode in class Object
        Returns:
        a hash code for this point.
      • toString

        public String toString()
        Returns a string representation of this point.
        Overrides:
        toString in class Object
        Returns:
        a string representation of this point.
      • draw

        public void draw()
        Draws this point using standard draw.
      • drawTo

        public void drawTo​(Point2D other)
        Draws a line between this point and other using standard draw.
        Parameters:
        other - the other point
      • compareTo

        public int compareTo​(Point2D other)
        Returns a comparison of this point with other, by their x- and y-coordinates.
        Specified by:
        compareTo in interface Comparable<Point2D>
        Parameters:
        other - the other point.
        Returns:
        a comparison of this point with other, by their x- and y-coordinates.
      • atan2Order

        public Comparator<Point2D> atan2Order()
        Returns a comparator for comparing two points by the atan2 angle (-pi to pi) they make with this point.
        Returns:
        a comparator for comparing two points by the atan2 angle (-pi to pi) they make with this point.
      • polarOrder

        public Comparator<Point2D> polarOrder()
        Returns a comparator for comparing two points by the polar angle (0 to 2pi) they make with this point.
        Returns:
        a comparator for comparing two points by the polar angle (0 to 2pi) they make with this point.
      • distanceToOrder

        public Comparator<Point2D> distanceToOrder()
        Returns a comparator for comparing two points by their distance to this point.
        Returns:
        a comparator for comparing two points by their distance to this point.
      • xOrder

        public static Comparator<Point2D> xOrder()
        Returns a comparator for comparing two points by their x-coordinate.
        Returns:
        a comparator for comparing two points by their x-coordinate.
      • yOrder

        public static Comparator<Point2D> yOrder()
        Returns a comparator for comparing two points by their y-coordinate.
        Returns:
        a comparator for comparing two points by their y-coordinate.
      • rOrder

        public static Comparator<Point2D> rOrder()
        Returns a comparator for comparing two points by their polar radius.
        Returns:
        a comparator for comparing two points by their polar radius.
      • main

        public static void main​(String[] args)
        Unit tests the data type.
        Parameters:
        args - the command-line arguments.