Record Class AxialPosition

java.lang.Object
java.lang.Record
spinhex.model.AxialPosition
Record Components:
q - The row coordinate
s - The top-left to bottom-right diagonal coordinate

public record AxialPosition(int q, int s) extends Record
Represents a position in an axial coordinate system for a hexagonal grid.

In axial coordinates, the position is described by two values, q and s, where q represents the row and s represents the top-left to bottom-right diagonal.

To learn more about axial coordinates, refer to: Red Blob Games - Axial Coordinates
  • Constructor Summary

    Constructors
    Constructor
    Description
    AxialPosition(int q, int s)
    Creates an instance of a AxialPosition record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Adds another axial position to this one.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    int
    q()
    Returns the value of the q record component.
    int
    s()
    Returns the value of the s record component.
    Subtracts another axial position from this one.
    Returns a string representation of this position in the format "(q,s)".

    Methods inherited from class java.lang.Object

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

    • AxialPosition

      public AxialPosition(int q, int s)
      Creates an instance of a AxialPosition record class.
      Parameters:
      q - the value for the q record component
      s - the value for the s record component
  • Method Details

    • toString

      public String toString()
      Returns a string representation of this position in the format "(q,s)".
      Specified by:
      toString in class Record
      Returns:
      A string representation of this position
    • add

      public AxialPosition add(AxialPosition other)
      Adds another axial position to this one.
      Parameters:
      other - The axial position to add
      Returns:
      A new axial position representing the sum
    • subtract

      public AxialPosition subtract(AxialPosition other)
      Subtracts another axial position from this one.
      Parameters:
      other - The axial position to subtract
      Returns:
      A new axial position representing the difference
    • 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 the compare method from their corresponding wrapper classes.
      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.
    • q

      public int q()
      Returns the value of the q record component.
      Returns:
      the value of the q record component
    • s

      public int s()
      Returns the value of the s record component.
      Returns:
      the value of the s record component