Class Point

java.lang.Object
edu.macalester.graphics.Point

public final class Point extends Object
A point in two-dimensional space.

This class is immutable. All methods return a new Point.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Point
    A point at (∞,∞).
    static final Point
    A point at (-∞,-∞).
    static final Point
    The point (1,1).
    static final Point
    The point (0,0).
    static final Point
    The point (1,0).
    static final Point
    The point (0,1).
  • Constructor Summary

    Constructors
    Constructor
    Description
    Point(double x, double y)
    Creates a point with the given horizontal and vertical components.
    Point(Point2D point)
    Converts a Java AWT Point2D to a kilt-graphics Point.
  • Method Summary

    Modifier and Type
    Method
    Description
    Treats the given point like a displacement vector and adds it to the current point.
    double
    Returns the angle in radians counterclockwise (or clockwise if you view y as up) from the x-axis to this point.
    static Point
    atAngle(double theta)
    Returns the unit vector at the given angle in radians.
    double
    Returns the distance between this point and another point.
    boolean
    Two points are equal if they have the same coordinates.
    double
    The vertical position of this point.
    double
    The horizontal position of this point.
    int
     
    static Point
    interpolate(Point p0, Point p1, double alpha)
    Linearly interpolates by alpha between the two points.
    double
    Returns the distance from this point to the origin.
    static Point
    max(Point p0, Point p1)
    Returns a point whose x is the maximum of the two given points' x coordinates, and whose y is the maximum of the two given points' y coordinates.
    static Point
    min(Point p0, Point p1)
    Returns a point whose x is the minimum of the two given points' x coordinates, and whose y is the minimum of the two given points' y coordinates.
    rotate(double angle)
    Returns the point rotated around the origin by the given angle in radians.
    rotate(double angle, Point center)
    Returns the point rotated around a given axis point by the given angle in radians.
    scale(double s)
    Multiplies this point's coordinates by a scalar.
    scale(double sx, double sy)
    Multiplies x by sx and y by sy.
    Treats p like a displacement vector and subtracts it from the current point
    Converts this point to the Java AWT Point2D.
     
    withX(double x)
    Returns a point with the same y as this one, but a different x.
    withY(double y)
    Returns a point with the same x as this one, but a different y.
    wrapAround(Point maxBounds)
    Makes the coordinates of the input point “wrap around” as if moving in a toroidal space extending from 0 to maxBounds.x, and from 0 to maxBounds.y: coordinates that go off one edge move to the other edge.
    wrapAround(Point minBounds, Point maxBounds)
    Makes the coordinates of the input point “wrap around” as if moving in a toroidal space: coordinates that go off one side move to the other side.

    Methods inherited from class java.lang.Object

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

    • ORIGIN

      public static final Point ORIGIN
      The point (0,0).
    • UNIT_X

      public static final Point UNIT_X
      The point (1,0).
    • UNIT_Y

      public static final Point UNIT_Y
      The point (0,1).
    • ONE_ONE

      public static final Point ONE_ONE
      The point (1,1).
    • MIN

      public static final Point MIN
      A point at (-∞,-∞).
    • MAX

      public static final Point MAX
      A point at (∞,∞).
  • Constructor Details

    • Point

      public Point(double x, double y)
      Creates a point with the given horizontal and vertical components.
    • Point

      public Point(Point2D point)
      Converts a Java AWT Point2D to a kilt-graphics Point.
  • Method Details

    • atAngle

      public static Point atAngle(double theta)
      Returns the unit vector at the given angle in radians.
    • getX

      public double getX()
      The vertical position of this point.
    • getY

      public double getY()
      The horizontal position of this point.
    • withX

      public Point withX(double x)
      Returns a point with the same y as this one, but a different x.
    • withY

      public Point withY(double y)
      Returns a point with the same x as this one, but a different y.
    • angle

      public double angle()
      Returns the angle in radians counterclockwise (or clockwise if you view y as up) from the x-axis to this point.
    • magnitude

      public double magnitude()
      Returns the distance from this point to the origin.
    • distance

      public double distance(Point p)
      Returns the distance between this point and another point.
    • add

      public Point add(Point p)
      Treats the given point like a displacement vector and adds it to the current point.
    • subtract

      public Point subtract(Point p)
      Treats p like a displacement vector and subtracts it from the current point
    • scale

      public Point scale(double s)
      Multiplies this point's coordinates by a scalar.
    • scale

      public Point scale(double sx, double sy)
      Multiplies x by sx and y by sy.
    • min

      public static Point min(Point p0, Point p1)
      Returns a point whose x is the minimum of the two given points' x coordinates, and whose y is the minimum of the two given points' y coordinates.
    • max

      public static Point max(Point p0, Point p1)
      Returns a point whose x is the maximum of the two given points' x coordinates, and whose y is the maximum of the two given points' y coordinates.
    • wrapAround

      public Point wrapAround(Point maxBounds)
      Makes the coordinates of the input point “wrap around” as if moving in a toroidal space extending from 0 to maxBounds.x, and from 0 to maxBounds.y: coordinates that go off one edge move to the other edge. Unlike Java’s raw modular arithmetic, this method handles negative values as expected.
      Parameters:
      maxBounds - The maximum x and y coordinates
      Returns:
      A new Point whose coordinates are each greater than or equal to zero, and less than the coordinates of maxBounds
    • wrapAround

      public Point wrapAround(Point minBounds, Point maxBounds)
      Makes the coordinates of the input point “wrap around” as if moving in a toroidal space: coordinates that go off one side move to the other side. Unlike Java’s raw modular arithmetic, this method handles negative values as expected.
      Parameters:
      minBounds - The minimum x and y coordinates
      maxBounds - The maximum x and y coordinates
      Returns:
      A new Point whose coordinates are each greater than or equal to the coordinates of minBounds, and less than the coordinates of maxBounds
    • rotate

      public Point rotate(double angle)
      Returns the point rotated around the origin by the given angle in radians.
    • rotate

      public Point rotate(double angle, Point center)
      Returns the point rotated around a given axis point by the given angle in radians.
    • interpolate

      public static Point interpolate(Point p0, Point p1, double alpha)
      Linearly interpolates by alpha between the two points.
      Parameters:
      p0 - The point for alpha = 0
      p1 - The point for alpha = 1
      alpha - The continuum from p0 to p1
    • equals

      public boolean equals(Object o)
      Two points are equal if they have the same coordinates.
      Overrides:
      equals in class Object
    • hashCode

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

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

      public Point2D.Double toPoint2D()
      Converts this point to the Java AWT Point2D.