Class Point2d

Object
Point2d
All Implemented Interfaces:
Serializable

public final class Point2d extends Object implements Serializable
A two-dimensional point of double values.

We consider a point to be a tuple representing a single physical point in space.

Author:
Owen Feehan
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    Point2d(double x, double y)
    Creates a new Point2d instance.
    Creates with the same values as an existing Point2d.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(double xToAdd, double yToAdd)
    Arithmetically adds two double values, to the X- and Y- dimensions.
    void
    add(int xToAdd, int yToAdd)
    Arithmetically adds two int values, to the X- and Y- dimensions.
    void
    add(Point2d toAdd)
    Arithmetically adds a Point2d's values across each dimension.
    void
    add(Point2i toAdd)
    Arithmetically adds a Point2i's values across each dimension.
    double
    The square of the Euclidean distance between this point and another Point2d.
    double
    The square of the Euclidean distance between this point and another Point2d.
    boolean
     
    int
     
    void
    scale(double factor)
    Arithmetically multiplies each dimension's value by a factor.
     
    double
    x()
    X-axis component of point.
    double
    y()
    Y-axis component of point.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Point2d

      public Point2d(Point2d point)
      Creates with the same values as an existing Point2d.
      Parameters:
      point - to copy values from.
    • Point2d

      public Point2d(double x, double y)
      Creates a new Point2d instance.
      Parameters:
      x - X-axis component of point.
      y - Y-axis component of point.
    • Point2d

      public Point2d()
  • Method Details

    • add

      public void add(Point2i toAdd)
      Arithmetically adds a Point2i's values across each dimension.
      Parameters:
      toAdd - tuple to add to current state.
    • add

      public void add(Point2d toAdd)
      Arithmetically adds a Point2d's values across each dimension.
      Parameters:
      toAdd - tuple to add to current state.
    • add

      public void add(int xToAdd, int yToAdd)
      Arithmetically adds two int values, to the X- and Y- dimensions.
      Parameters:
      xToAdd - x-value to add to current state.
      yToAdd - y-value to add to current state.
    • add

      public void add(double xToAdd, double yToAdd)
      Arithmetically adds two double values, to the X- and Y- dimensions.
      Parameters:
      xToAdd - x-value to add to current state.
      yToAdd - y-value to add to current state.
    • scale

      public void scale(double factor)
      Arithmetically multiplies each dimension's value by a factor.
      Parameters:
      factor - the factor to multiply by.
    • distance

      public double distance(Point2d point)
      The square of the Euclidean distance between this point and another Point2d.
      Parameters:
      point - the other point to a measure a distance to.
      Returns:
      the distance squared.
    • distanceSquared

      public double distanceSquared(Point2d point)
      The square of the Euclidean distance between this point and another Point2d.
      Parameters:
      point - the other point to a measure a distance to.
      Returns:
      the distance squared.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • x

      public double x()
      X-axis component of point.
    • y

      public double y()
      Y-axis component of point.