Record Class CubeCoords

java.lang.Object
java.lang.Record
megamek.common.board.CubeCoords
All Implemented Interfaces:
Serializable

public record CubeCoords(double q, double r, double s) extends Record implements Serializable
Represents a set of cube coordinates in a hex grid. Cube Coordinate allows for more precise manipulation of distances, movements, and other operations.
See Also:
  • Field Details

  • Constructor Details

    • CubeCoords

      public CubeCoords(double q, double r, double s)
      Creates a new CubeCoords object with the given cube coordinates.
      Parameters:
      q - the q coordinate
      r - the r coordinate
      s - the s coordinate
  • Method Details

    • toOffset

      public Coords toOffset()
      Converts cube coordinates to offset coordinates.
      Returns:
      a new Coords object with the offset coordinates
    • add

      public CubeCoords add(CubeCoords other)
      Adds another CubeCoords to this one and returns a new CubeCoords object.
      Parameters:
      other - the CubeCoords to add
      Returns:
      a new CubeCoords object with the sum of the coordinates
    • subtract

      public CubeCoords subtract(CubeCoords other)
      Subtracts another CubeCoords from this one and returns a new CubeCoords object.
      Parameters:
      other - the CubeCoords to subtract
      Returns:
      a new CubeCoords object with the difference of the coordinates
    • neighbor

      public CubeCoords neighbor(CardinalDirection direction)
      Gets the cube coordinate of a neighbor hex around this hex.
      Parameters:
      direction - the direction to get the neighbor from
      Returns:
      a CubeCoords representing the neighbor
    • neighbors

      public Set<CubeCoords> neighbors()
      Gets the cube coordinates of the neighbor hexes around this hex.
      Returns:
      an unordered set of CubeCoords representing the neighbors
    • mean

      public static Optional<CubeCoords> mean(Collection<CubeCoords> positions)
      Averages a collection of CubeCoords and returns the average as a new CubeCoords object.
      Parameters:
      positions - the collection of CubeCoords to average
      Returns:
      an Optional containing the average CubeCoords, or empty if the collection is empty
    • roundToNearestHex

      public CubeCoords roundToNearestHex()
      Rounds the cube coordinates to the nearest hex.
      Returns:
      a new CubeCoords object with the rounded coordinates
    • distanceBetween

      public static int distanceBetween(CubeCoords a, CubeCoords b)
      Gets the distance between two cube coordinates.
      Parameters:
      a - the first cube coordinate
      b - the second cube coordinate
      Returns:
      the distance between the two coordinates
    • distanceTo

      public int distanceTo(CubeCoords other)
      Gets the distance between this cube coordinate and another.
      Parameters:
      other - the other cube coordinate
      Returns:
      the distance between the two coordinates
    • dot

      public double dot(CubeCoords other)
      Gets the dot product of this cube coordinate and another.
      Parameters:
      other - the other cube coordinate
      Returns:
      the dot product of the two coordinates
    • getCrossMagnitude

      @Deprecated(since="0.51.0", forRemoval=true) public double getCrossMagnitude(CubeCoords vector)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Gets the cross product of this cube coordinate and another.
      Parameters:
      vector - the other cube coordinate
      Returns:
      the cross product of the two coordinates
    • intervening

      public List<CubeCoords> intervening(CubeCoords other)
      Gets the cube coordinates of a line between two cube coordinates.
      Parameters:
      other - the other cube coordinate
      Returns:
      a list of CubeCoords representing the line
    • lerp

      public static CubeCoords lerp(CubeCoords a, CubeCoords b, double t)
      Linearly interpolates between two cube coordinates.
      Parameters:
      a - the start cube coordinate
      b - the end cube coordinate
      t - the interpolation parameter, where 0 <= t <= 1
      Returns:
      a new CubeCoords representing the interpolated coordinate
    • toString

      @Nonnull 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.
    • q

      public double q()
      Returns the value of the q record component.
      Returns:
      the value of the q record component
    • r

      public double r()
      Returns the value of the r record component.
      Returns:
      the value of the r record component
    • s

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