Record Class Point

java.lang.Object
java.lang.Record
com.digitizer.core.Point

public record Point(double x, double y) extends Record
Represents a single data point with x and y coordinates.

Points are modeled as an immutable record to simplify threading and ensure value semantics for equality and hashing. Use distanceTo(Point) when comparing proximity between points.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Point(double x, double y)
    Creates a new Point with the specified coordinates.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Calculates the Euclidean distance to another point.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    Returns a string representation of the point.
    double
    x()
    Returns the value of the x record component.
    double
    y()
    Returns the value of the y record component.

    Methods inherited from class java.lang.Object

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

    • Point

      public Point(double x, double y)
      Creates a new Point with the specified coordinates.
      Parameters:
      x - the x-coordinate
      y - the y-coordinate
  • Method Details

    • toString

      public String toString()
      Returns a string representation of the point.
      Specified by:
      toString in class Record
      Returns:
      formatted string "Point(x, y)"
    • distanceTo

      public double distanceTo(Point other)
      Calculates the Euclidean distance to another point.
      Parameters:
      other - the other point
      Returns:
      the distance between this point and the other point
    • 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 double x()
      Returns the value of the x record component.
      Returns:
      the value of the x record component
    • y

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