Class GridPosition
- java.lang.Object
-
- de.gsi.chart.renderer.spi.hexagon.GridPosition
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
public class GridPosition extends java.lang.Object implements java.lang.Cloneable, java.io.SerializableStores coordinates and has functions for grid calculations, e.g. getLine, ring and distance. These calculations do not depend on how you have placed the Hexagons on the HexagonMap. The axial coordinate system is used.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description GridPosition(int q, int r)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected GridPositionclone()booleanequals(java.lang.Object obj)Two positions are equal if they have the same q and rHexagonMap.DirectiongetDirectionTo(GridPosition otherPosition)intgetDistance(GridPosition target)static intgetDistance(GridPosition a, GridPosition b)Calculates the grid distance between two positionsGridPositiongetNeighborPosition(HexagonMap.Direction direction)Finds the adjacent position in the specified direction from this positionjava.util.List<GridPosition>getPositionsInCircleArea(int radius)java.util.List<GridPosition>getPositionsOnCircleEdge(int radius)Finds all positions that are on the edge of a circle in which this position is the centre.intgetQ()intgetR()inthashCode()static GridPositionhexRound(double q, double r)Finds the position that best matches given non-integer coordinatesbooleanisAdjacent(GridPosition otherPosition)java.util.List<GridPosition>line(GridPosition destination)Finds all GridPositions that are on a getLine between this and the given position (the array includes this and the destination positions)java.lang.StringtoString()
-
-
-
Method Detail
-
getQ
public int getQ()
-
getR
public int getR()
-
getNeighborPosition
public GridPosition getNeighborPosition(HexagonMap.Direction direction)
Finds the adjacent position in the specified direction from this position- Parameters:
direction- in which to search- Returns:
- the adjacent position
-
getPositionsOnCircleEdge
public java.util.List<GridPosition> getPositionsOnCircleEdge(int radius)
Finds all positions that are on the edge of a circle in which this position is the centre. If radius is 0, an array with only this GridPosition will be returned.- Parameters:
radius- circle radius- Returns:
- positions that are on the edge of a circle
-
getPositionsInCircleArea
public java.util.List<GridPosition> getPositionsInCircleArea(int radius)
-
hexRound
public static GridPosition hexRound(double q, double r)
Finds the position that best matches given non-integer coordinates- Parameters:
q- coordinater- coordinate- Returns:
- position that best matches given non-integer coordinates
-
clone
protected GridPosition clone()
- Overrides:
clonein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
Two positions are equal if they have the same q and r- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- object to compare to- Returns:
- positions are equal if they have the same q and r
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
isAdjacent
public boolean isAdjacent(GridPosition otherPosition)
- Parameters:
otherPosition- other hex grid position- Returns:
- true if the positions are adjacent
-
getDirectionTo
public HexagonMap.Direction getDirectionTo(GridPosition otherPosition)
- Parameters:
otherPosition- reference grid position- Returns:
- the direction
-
line
public java.util.List<GridPosition> line(GridPosition destination)
Finds all GridPositions that are on a getLine between this and the given position (the array includes this and the destination positions)- Parameters:
destination- destination grid position- Returns:
- an array positions
-
getDistance
public static int getDistance(GridPosition a, GridPosition b)
Calculates the grid distance between two positions- Parameters:
a- the start positionb- the destination position- Returns:
- the distance (number of hexagons)
-
getDistance
public int getDistance(GridPosition target)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-