Class Point2D

  • All Implemented Interfaces:
    java.lang.Cloneable
    Direct Known Subclasses:
    Point2D.Double, Point2D.Float

    public abstract class Point2D
    extends java.lang.Object
    implements java.lang.Cloneable
    An abstract class for a point. Subclasses implement float, double and integer coordinates.
    Author:
    Lawrie Griffiths
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Point2D.Double
      A point with double coordinates.
      static class  Point2D.Float
      A point with float coordinates.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Point2D()
      This is abstract class that cannot be instantiated.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object clone()  
      double distance​(double px, double py)
      Get the distance from this point to a given point as a double
      static double distance​(double x1, double y1, double x2, double y2)
      Get the the distance between two points
      double distance​(Point2D pt)
      Get the distance from this point to a given point asa double
      double distanceSq​(double px, double py)
      Get the square of the distance between two points
      static double distanceSq​(double x1, double y1, double x2, double y2)
      Get the square of the distance between two points
      double distanceSq​(Point2D pt)
      Get the square of the distance of this point to a given point
      boolean equals​(java.lang.Object obj)
      Test if this point is equal to a given object
      abstract double getX()
      Get the x coordinate as a double
      abstract double getY()
      Get the y coordinate as a double
      abstract void setLocation​(double x, double y)
      Set the location of this Point2D using double coordinates
      void setLocation​(Point2D p)
      Set the location of this Point2D to the same as a specified Point2D
      • Methods inherited from class java.lang.Object

        finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Point2D

        protected Point2D()
        This is abstract class that cannot be instantiated. Use one of its subclasses.
    • Method Detail

      • getX

        public abstract double getX()
        Get the x coordinate as a double
        Returns:
        the x co-ordinate (as a double)
      • getY

        public abstract double getY()
        Get the y coordinate as a double
        Returns:
        the y coordinate (as a double)
      • setLocation

        public abstract void setLocation​(double x,
                                         double y)
        Set the location of this Point2D using double coordinates
        Parameters:
        x - the new x coordinate
        y - the new y coordinate
      • setLocation

        public void setLocation​(Point2D p)
        Set the location of this Point2D to the same as a specified Point2D
        Parameters:
        p - the specified Point2D
      • distanceSq

        public static double distanceSq​(double x1,
                                        double y1,
                                        double x2,
                                        double y2)
        Get the square of the distance between two points
        Parameters:
        x1 - the x coordinate of the first point
        y1 - the y coordinate of the first point
        x2 - the x coordinate of the second point
        y2 - the y coordinate of the second point
        Returns:
        the square of the distance between the points as a double
      • distance

        public static double distance​(double x1,
                                      double y1,
                                      double x2,
                                      double y2)
        Get the the distance between two points
        Parameters:
        x1 - the x coordinate of the first point
        y1 - the y coordinate of the first point
        x2 - the x coordinate of the second point
        y2 - the y coordinate of the second point
        Returns:
        the distance between the points as a double
      • distanceSq

        public double distanceSq​(double px,
                                 double py)
        Get the square of the distance between two points
        Parameters:
        px - the first point
        py - the second point
        Returns:
        the square of the distance between the points as a double
      • distanceSq

        public double distanceSq​(Point2D pt)
        Get the square of the distance of this point to a given point
        Parameters:
        pt - the given point
        Returns:
        the square of the distance to the given point as a double
      • distance

        public double distance​(double px,
                               double py)
        Get the distance from this point to a given point as a double
        Parameters:
        px - the x coordinate of the given point
        py - the y coordinate of the given point
        Returns:
        the distance to the given point as a double
      • distance

        public double distance​(Point2D pt)
        Get the distance from this point to a given point asa double
        Parameters:
        pt - the given point
        Returns:
        the distance to the given point as a double
      • equals

        public boolean equals​(java.lang.Object obj)
        Test if this point is equal to a given object
        Overrides:
        equals in class java.lang.Object
      • clone

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