Class Point

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class Point
    extends java.lang.Object
    implements java.lang.Cloneable
    Class that represent point object with x and y coordinates.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private double x  
      private double y  
    • Constructor Summary

      Constructors 
      Constructor Description
      Point()
      Instantiates a new Point instance with 0 x and y.
      Point​(double x, double y)
      Instantiates a new Point instance based on passed x and y.
      Point​(Point other)
      Instantiates a new Point instance based on other Point instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object clone()  
      double distance​(double px, double py)
      The distance between this point and the second point which is defined by passed x and y coordinates.
      double distance​(Point p)
      The distance between this point and the second point.
      private static double distanceSq​(double x1, double y1, double x2, double y2)  
      boolean equals​(java.lang.Object obj)  
      Point getLocation()
      Gets location of point by creating a new copy.
      double getX()
      Gets x coordinate of the point.
      double getY()
      Gets y coordinate of the point.
      int hashCode()  
      void move​(double dx, double dy)
      Moves the point by the specified offset.
      void setLocation​(double x, double y)
      Sets x and y double coordinates of the point.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • x

        private double x
      • y

        private double y
    • Constructor Detail

      • Point

        public Point()
        Instantiates a new Point instance with 0 x and y.
      • Point

        public Point​(double x,
                     double y)
        Instantiates a new Point instance based on passed x and y.
        Parameters:
        x - the x coordinates of the point
        y - the y coordinates of the point
      • Point

        public Point​(Point other)
        Instantiates a new Point instance based on other Point instance.
        Parameters:
        other - other Point instance from which coordinates will be copied
    • Method Detail

      • getX

        public double getX()
        Gets x coordinate of the point.
        Returns:
        the x coordinate
      • getY

        public double getY()
        Gets y coordinate of the point.
        Returns:
        the y coordinate
      • getLocation

        public Point getLocation()
        Gets location of point by creating a new copy.
        Returns:
        the copy of this point
      • setLocation

        public void setLocation​(double x,
                                double y)
        Sets x and y double coordinates of the point.
        Parameters:
        x - the x coordinate
        y - the y coordinate
      • move

        public void move​(double dx,
                         double dy)
        Moves the point by the specified offset.
        Parameters:
        dx - the x-axis offset
        dy - the y-axis offset
      • distance

        public double distance​(double px,
                               double py)
        The distance between this point and the second point which is defined by passed x and y coordinates.
        Parameters:
        px - the x coordinate of the second point
        py - the y coordinate of the second point
        Returns:
        the distance between points
      • distance

        public double distance​(Point p)
        The distance between this point and the second point.
        Parameters:
        p - the second point to calculate distance
        Returns:
        the distance between points
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • clone

        public java.lang.Object clone()
        Overrides:
        clone in class java.lang.Object
      • distanceSq

        private static double distanceSq​(double x1,
                                         double y1,
                                         double x2,
                                         double y2)