Record Class Point2D

java.lang.Object
java.lang.Record
nl.colorize.multimedialib.math.Point2D

public record Point2D(float x, float y) extends Record
Describes a point with X and Y coordinates within a two-dimensional space. Point coordinates have float precision, and point instances are immutable.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Point2D
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Point2D(float x, float y)
    Creates an instance of a Point2D record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    float
    Returns the angle in degrees from this point towards the specified other point.
    float
    Returns the distance between this point and the specified other point.
    final boolean
    Indicates whether some other object is "equal to" this one.
    Returns a new point that is positioned in the center between this point and the specified other point.
    final int
    Returns a hash code value for this object.
    interpolate(Point2D other, float delta)
    Returns a new point with a position that uses linear interpolation between this point and the specified other point.
    interpolate(Point2D other, float delta, nl.colorize.util.animation.Interpolation method)
    Returns a new point with a position that is interpolated between this point and the specified other point.
    boolean
     
    move(float deltaX, float deltaY)
    Returns a new point that starts from this point and then adds the specified offset.
    move(Point2D other)
    Returns a new point that starts from this point and then adds the specified offset.
    Returns a string representation of this record class.
    float
    x()
    Returns the value of the x record component.
    float
    y()
    Returns the value of the y record component.

    Methods inherited from class java.lang.Object

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

    • ORIGIN

      public static final Point2D ORIGIN
  • Constructor Details

    • Point2D

      public Point2D(float x, float y)
      Creates an instance of a Point2D record class.
      Parameters:
      x - the value for the x record component
      y - the value for the y record component
  • Method Details

    • isOrigin

      public boolean isOrigin()
    • distanceTo

      public float distanceTo(Point2D other)
      Returns the distance between this point and the specified other point.
    • angleTo

      public float angleTo(Point2D other)
      Returns the angle in degrees from this point towards the specified other point. If the points are identical this will return an angle of 0.
    • findCenter

      public Point2D findCenter(Point2D other)
      Returns a new point that is positioned in the center between this point and the specified other point.
    • interpolate

      public Point2D interpolate(Point2D other, float delta, nl.colorize.util.animation.Interpolation method)
      Returns a new point with a position that is interpolated between this point and the specified other point. The delta is represented by a number between 0.0 (position of this point) and 1.0 (position of the other point).
    • interpolate

      public Point2D interpolate(Point2D other, float delta)
      Returns a new point with a position that uses linear interpolation between this point and the specified other point. The delta is represented by a number between 0.0 (position of this point) and 1.0 (position of the other point).
    • move

      public Point2D move(float deltaX, float deltaY)
      Returns a new point that starts from this point and then adds the specified offset.
    • move

      public Point2D move(Point2D other)
      Returns a new point that starts from this point and then adds the specified offset.
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • x

      public float x()
      Returns the value of the x record component.
      Returns:
      the value of the x record component
    • y

      public float y()
      Returns the value of the y record component.
      Returns:
      the value of the y record component