Class CubeCoordinate
- java.lang.Object
-
- page.codeberg.terratactician_expandoria.world.CubeCoordinate
-
public class CubeCoordinate extends java.lang.ObjectCubeCoordinate/CubeVector: This class can be used to compute Coordinates or Vectors in a hexagon world. This Coordinate consists of 3 components: q, r, s. This components represent three vector in cartesian, rotated by 180° each. To get a unique Vector all components MUST full fill this condition: q+r+s = 0.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classCubeCoordinate.AreaIteratorAn AreaIterator iterates over all tiles in a filled hexagon with a center and radius.classCubeCoordinate.RingIteratorThe RingIterator is a Iterator and Iterable over CubeCoordinate's.
-
Field Summary
Fields Modifier and Type Field Description static doubleEDGE_LENGTHEdge length of a tile in cartesian coordinates = 1 / SQRT(3)intqq component of this coordinate/vector (note: q+r+s = 0)static Vec2Q_VECcartesian vector of the q component of a vector, with q=1intrr component of this coordinate/vector (note: q+r+s = 0)static Vec2R_VECcartesian vector of the r component of a vector, with r=1intss component of this coordinate/vector (note: q+r+s = 0)static Vec2S_VECcartesian vector of the s component of a vector, with s=1static doubleSQRT_3square root of 3static doubleTILE_SIZEDistance between tow tiles centers, connecting on there edges.
-
Constructor Summary
Constructors Constructor Description CubeCoordinate()Creates a 0 CubeCoordinate or a 0 CubeVector.CubeCoordinate(int q, int r, int s)Creates a CubeCoordinate/CubeVector with coordinates.CubeCoordinate(CubeCoordinate current)Copy/clone a CubeCoordinate/CubeVector.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CubeCoordinateadd(CubeCoordinate other)Add CubeVector, to this CubeCoordinate/CubeVector.CubeCoordinateclone()Creates a clone of this Coordinate.static CubeCoordinatedeserialize(org.json.JSONObject data)deserializes a CubeCoordinate from jsonintdistance(CubeCoordinate coord)Returns the hex len between two coordinates.CubeCoordinatediv(int scale)Divide this CubeVector be scalar value.booleanequals(java.lang.Object obj)CubeCoordinate.AreaIteratorgetArea(int radius)Creates Iterator iterating all coordinates in a given radius.CubeCoordinate.RingIteratorgetRing(int radius)Creates Iterator iterating all coordinates on the outline of an hexagon.inthashCode()inthexLen()Returns the size that a hexagon area, centered around (0,0,0), would have to be, to contain the Coordinate.CubeCoordinatemul(int scale)Multiply CubeVector by a scalar value.CubeCoordinatenegate()Create a negated CubeVector.org.json.JSONObjectserialize()serializes a CubeCoordinate to jsonCubeCoordinatesub(CubeCoordinate other)Subtract CubeVector, to this CubeCoordinate/CubeVector.java.lang.StringtoString()Vec2toVec()Converts this CubeCoordinate/CubeVector to cartesian coordinates.static CubeCoordinateunitFromDirection(int dir)Create a unit CubeCoordinate Vector from direction index.
-
-
-
Field Detail
-
SQRT_3
public static double SQRT_3
square root of 3
-
EDGE_LENGTH
public static double EDGE_LENGTH
Edge length of a tile in cartesian coordinates = 1 / SQRT(3)
-
TILE_SIZE
public static double TILE_SIZE
Distance between tow tiles centers, connecting on there edges.
-
Q_VEC
public static Vec2 Q_VEC
cartesian vector of the q component of a vector, with q=1
-
R_VEC
public static Vec2 R_VEC
cartesian vector of the r component of a vector, with r=1
-
S_VEC
public static Vec2 S_VEC
cartesian vector of the s component of a vector, with s=1
-
q
public int q
q component of this coordinate/vector (note: q+r+s = 0)
-
r
public int r
r component of this coordinate/vector (note: q+r+s = 0)
-
s
public int s
s component of this coordinate/vector (note: q+r+s = 0)
-
-
Constructor Detail
-
CubeCoordinate
public CubeCoordinate()
Creates a 0 CubeCoordinate or a 0 CubeVector. (can be used as both)
-
CubeCoordinate
public CubeCoordinate(int q, int r, int s)Creates a CubeCoordinate/CubeVector with coordinates. The following condition MUST be true: q+r+s = 0. (will be checked in debug mode)- Parameters:
q- q componentr- r components- s component
-
CubeCoordinate
public CubeCoordinate(CubeCoordinate current)
Copy/clone a CubeCoordinate/CubeVector.- Parameters:
current- coordinate to copy
-
-
Method Detail
-
hexLen
public int hexLen()
Returns the size that a hexagon area, centered around (0,0,0), would have to be, to contain the Coordinate.- Returns:
- size
-
distance
public int distance(CubeCoordinate coord)
Returns the hex len between two coordinates. SeehexLen.- Parameters:
coord- coordinate to compare to- Returns:
- distance between the coords
-
getRing
public CubeCoordinate.RingIterator getRing(int radius)
Creates Iterator iterating all coordinates on the outline of an hexagon. The radius does define the size of a hexagon.- Parameters:
radius- size of the hexagon, min 0- Returns:
- ring iterator
-
getArea
public CubeCoordinate.AreaIterator getArea(int radius)
Creates Iterator iterating all coordinates in a given radius. The radius does define the size of a hexagon.- Parameters:
radius- size of the hexagon, min 1- Returns:
- area iterator
-
toVec
public Vec2 toVec()
Converts this CubeCoordinate/CubeVector to cartesian coordinates.- Returns:
- cartesian vector
-
unitFromDirection
public static CubeCoordinate unitFromDirection(int dir)
Create a unit CubeCoordinate Vector from direction index.- Parameters:
dir- value between 0 and 5- Returns:
- requested unit vector.
-
add
public CubeCoordinate add(CubeCoordinate other)
Add CubeVector, to this CubeCoordinate/CubeVector. (this nor other will not be modified)- Parameters:
other- other CubeCoordinate/CubeVector- Returns:
- added copy
-
sub
public CubeCoordinate sub(CubeCoordinate other)
Subtract CubeVector, to this CubeCoordinate/CubeVector. (this nor other will not be modified)- Parameters:
other- other CubeCoordinate/CubeVector- Returns:
- subtracted copy
-
mul
public CubeCoordinate mul(int scale)
Multiply CubeVector by a scalar value. (this will not be modified)- Parameters:
scale- value to multiply ba- Returns:
- multiplied copy
-
negate
public CubeCoordinate negate()
Create a negated CubeVector. (this will not be modified)- Returns:
- negated copy
-
div
public CubeCoordinate div(int scale)
Divide this CubeVector be scalar value. (this will not be modified)- Parameters:
scale- value to divide by.- Returns:
- divided copy
-
clone
public CubeCoordinate clone()
Creates a clone of this Coordinate.- Overrides:
clonein classjava.lang.Object- Returns:
- the new CubeCoordinate
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
deserialize
public static CubeCoordinate deserialize(org.json.JSONObject data)
deserializes a CubeCoordinate from json- Parameters:
data- json data- Returns:
- deserialized CubeCoordinate
-
serialize
public org.json.JSONObject serialize()
serializes a CubeCoordinate to json- Returns:
- json object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-