Package megamek.common.board
Record Class CubeCoords
java.lang.Object
java.lang.Record
megamek.common.board.CubeCoords
- All Implemented Interfaces:
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCubeCoords(double q, double r, double s) Creates a new CubeCoords object with the given cube coordinates. -
Method Summary
Modifier and TypeMethodDescriptionadd(CubeCoords other) Adds another CubeCoords to this one and returns a new CubeCoords object.static intGets the distance between two cube coordinates.intdistanceTo(CubeCoords other) Gets the distance between this cube coordinate and another.doubledot(CubeCoords other) Gets the dot product of this cube coordinate and another.final booleanIndicates whether some other object is "equal to" this one.doublegetCrossMagnitude(CubeCoords vector) Deprecated, for removal: This API element is subject to removal in a future version.final inthashCode()Returns a hash code value for this object.intervening(CubeCoords other) Gets the cube coordinates of a line between two cube coordinates.static CubeCoordslerp(CubeCoords a, CubeCoords b, double t) Linearly interpolates between two cube coordinates.static Optional<CubeCoords> mean(Collection<CubeCoords> positions) Averages a collection of CubeCoords and returns the average as a new CubeCoords object.neighbor(CardinalDirection direction) Gets the cube coordinate of a neighbor hex around this hex.Gets the cube coordinates of the neighbor hexes around this hex.doubleq()Returns the value of theqrecord component.doubler()Returns the value of therrecord component.Rounds the cube coordinates to the nearest hex.doubles()Returns the value of thesrecord component.subtract(CubeCoords other) Subtracts another CubeCoords from this one and returns a new CubeCoords object.toOffset()Converts cube coordinates to offset coordinates.toString()Returns a string representation of this record class.
-
Field Details
-
ZERO
-
-
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 coordinater- the r coordinates- the s coordinate
-
-
Method Details
-
toOffset
Converts cube coordinates to offset coordinates.- Returns:
- a new Coords object with the offset coordinates
-
add
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
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
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
Gets the cube coordinates of the neighbor hexes around this hex.- Returns:
- an unordered set of CubeCoords representing the neighbors
-
mean
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
Rounds the cube coordinates to the nearest hex.- Returns:
- a new CubeCoords object with the rounded coordinates
-
distanceBetween
Gets the distance between two cube coordinates.- Parameters:
a- the first cube coordinateb- the second cube coordinate- Returns:
- the distance between the two coordinates
-
distanceTo
Gets the distance between this cube coordinate and another.- Parameters:
other- the other cube coordinate- Returns:
- the distance between the two coordinates
-
dot
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, 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
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
Linearly interpolates between two cube coordinates.- Parameters:
a- the start cube coordinateb- the end cube coordinatet- the interpolation parameter, where0 <= t <= 1- Returns:
- a new CubeCoords representing the interpolated coordinate
-
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. -
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. -
equals
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 '=='. -
q
public double q()Returns the value of theqrecord component.- Returns:
- the value of the
qrecord component
-
r
public double r()Returns the value of therrecord component.- Returns:
- the value of the
rrecord component
-
s
public double s()Returns the value of thesrecord component.- Returns:
- the value of the
srecord component
-