Class Hexagon
- java.lang.Object
-
- javafx.scene.Node
-
- javafx.scene.shape.Shape
-
- javafx.scene.shape.Polygon
-
- de.gsi.chart.renderer.spi.hexagon.Hexagon
-
- All Implemented Interfaces:
javafx.css.Styleable,javafx.event.EventTarget
public class Hexagon extends javafx.scene.shape.PolygonA Hexagon is the building block of the grid.
-
-
Field Summary
Fields Modifier and Type Field Description HexagonaStarCameFromintaStarFscoreintaStarGscoreGridPositionposition
-
Constructor Summary
Constructors Constructor Description Hexagon(int q, int r)The position of the Hexagon is specified with axial coordinates
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddraw(javafx.scene.canvas.GraphicsContext gc)voiddrawContour(javafx.scene.canvas.GraphicsContext gc)voiddrawHexagon(javafx.scene.canvas.GraphicsContext gc)voiddrawHexagon(javafx.scene.canvas.GraphicsContext gc, HexagonMap.Direction... directions)booleanequals(java.lang.Object obj)Two Hexagons are equal if they have the same q and rHexagonMap.DirectiongetDirectionTo(Hexagon target)Finds the direction (NORTHWEST, NORTHEAST, EAST, SOUTHEAST, SOUTHWEST or WEST) If target is a neighbour, then it is quite simple.intgetDistance(Hexagon target)Calculates the distance (number of hexagons) to the target hexagonintgetGraphicsXoffset()intgetGraphicsYoffset()java.util.List<Hexagon>getHexagonsInRingArea(int radius)Returns all Hexagons that are located within a certain distance from herejava.util.List<Hexagon>getHexagonsOnRingEdge(int radius)Returns all Hexagons that are located a certain distance from herejava.util.List<Hexagon>getLine(Hexagon origin, Hexagon destination)Finds all Hexagons that are on a line between this and destinationHexagongetNeighbour(HexagonMap.Direction direction)Finds the neighbour of this Hexagonjava.util.List<Hexagon>getNeighbours()Finds all neighbours of this Hexagonjava.util.List<Hexagon>getPathTo(Hexagon destination)Finds the cheapest path from here to the destination.java.util.List<Hexagon>getPathTo(Hexagon destination, IPathInfoSupplier pathInfoSupplier)Finds the cheapest path from start to the goal.intgetQ()intgetR()java.util.List<Hexagon>getVisibleHexes(int visibleRange)Calculates all Hexagons that are visible from this Hexagon.inthashCode()voidinit()booleanisBlockingPath()This affects the pathfinding calculationsbooleanisVisualObstacle()This affects the field of view calculations.voidrenderCoordinates(javafx.scene.canvas.GraphicsContext gc)voidsetBackgroundColor(javafx.scene.paint.Color c)This method is the safe way to change the background color since it makes sure that the change is made on the JavaFX Application thread.voidsetIsBlockingPath(boolean b)This affects the pathfinding calculations.voidsetIsVisualObstacle(boolean b)This affects the field of view calculations.voidsetMap(HexagonMap map)This gives the Hexagon access a HexagonMap without actually adding it to the HexagonMap.java.lang.StringtoString()-
Methods inherited from class javafx.scene.shape.Shape
fillProperty, getClassCssMetaData, getCssMetaData, getFill, getStroke, getStrokeDashArray, getStrokeDashOffset, getStrokeLineCap, getStrokeLineJoin, getStrokeMiterLimit, getStrokeType, getStrokeWidth, intersect, isSmooth, setFill, setSmooth, setStroke, setStrokeDashOffset, setStrokeLineCap, setStrokeLineJoin, setStrokeMiterLimit, setStrokeType, setStrokeWidth, smoothProperty, strokeDashOffsetProperty, strokeLineCapProperty, strokeLineJoinProperty, strokeMiterLimitProperty, strokeProperty, strokeTypeProperty, strokeWidthProperty, subtract, union
-
Methods inherited from class javafx.scene.Node
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, executeAccessibleAction, fireEvent, focusedProperty, focusTraversableProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBaselineOffset, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInitialFocusTraversable, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isResizable, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookup, lookupAll, managedProperty, maxHeight, maxWidth, minHeight, minWidth, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, prefHeight, prefWidth, pressedProperty, pseudoClassStateChanged, queryAccessibleAttribute, relocate, removeEventFilter, removeEventHandler, requestFocus, resize, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty
-
-
-
-
Field Detail
-
position
public final GridPosition position
-
aStarGscore
public int aStarGscore
-
aStarFscore
public int aStarFscore
-
aStarCameFrom
public Hexagon aStarCameFrom
-
-
Method Detail
-
draw
public void draw(javafx.scene.canvas.GraphicsContext gc)
-
drawContour
public void drawContour(javafx.scene.canvas.GraphicsContext gc)
-
drawHexagon
public void drawHexagon(javafx.scene.canvas.GraphicsContext gc)
-
drawHexagon
public void drawHexagon(javafx.scene.canvas.GraphicsContext gc, HexagonMap.Direction... directions)
-
equals
public boolean equals(java.lang.Object obj)
Two Hexagons are equal if they have the same q and r- Overrides:
equalsin classjava.lang.Object
-
getDirectionTo
public HexagonMap.Direction getDirectionTo(Hexagon target)
Finds the direction (NORTHWEST, NORTHEAST, EAST, SOUTHEAST, SOUTHWEST or WEST) If target is a neighbour, then it is quite simple. If target is not a neighbour, this returns the direction to the first step on a line to the target.- Parameters:
target- target hexagon- Returns:
- direction towards target
-
getDistance
public int getDistance(Hexagon target)
Calculates the distance (number of hexagons) to the target hexagon- Parameters:
target- destination hex tile- Returns:
- distance in hex grid coordinates
-
getGraphicsXoffset
public int getGraphicsXoffset()
- Returns:
- where this Hexagon is when rendererd into a JavaFX Group
-
getGraphicsYoffset
public int getGraphicsYoffset()
- Returns:
- where this Hexagon is when rendererd into a JavaFX Group
-
getHexagonsInRingArea
public java.util.List<Hexagon> getHexagonsInRingArea(int radius)
Returns all Hexagons that are located within a certain distance from here- Parameters:
radius- in hex grid coordinates- Returns:
- list of all hexagon on the circle radius
-
getHexagonsOnRingEdge
public java.util.List<Hexagon> getHexagonsOnRingEdge(int radius)
Returns all Hexagons that are located a certain distance from here- Parameters:
radius- in hex grid coordinates- Returns:
- list of all hexagon within the circle
-
getLine
public java.util.List<Hexagon> getLine(Hexagon origin, Hexagon destination)
Finds all Hexagons that are on a line between this and destination- Parameters:
origin- source hex tiledestination- target hex tile- Returns:
- list of hexagon on the path
-
getNeighbour
public Hexagon getNeighbour(HexagonMap.Direction direction)
Finds the neighbour of this Hexagon- Parameters:
direction- direction from source- Returns:
- neighbour
-
getNeighbours
public java.util.List<Hexagon> getNeighbours()
Finds all neighbours of this Hexagon- Returns:
- list of all direct neighbours
-
getPathTo
public java.util.List<Hexagon> getPathTo(Hexagon destination) throws NoPathFoundException
Finds the cheapest path from here to the destination. The A* algorithm is used. This method uses the method isBlockingPath() in Hexagon and the movement cost between neighboring hexagons is always 1.- Parameters:
destination- the target Hexagon- Returns:
- an array of Hexagons, sorted so that the first step comes first.
- Throws:
NoPathFoundException- if there exists no path between start and the goal
-
getPathTo
public java.util.List<Hexagon> getPathTo(Hexagon destination, IPathInfoSupplier pathInfoSupplier) throws NoPathFoundException
Finds the cheapest path from start to the goal. The A* algorithm is used.- Parameters:
destination- the target HexagonpathInfoSupplier- a class implementing the IPathInfoSupplier interface. This can be used to add inpassable hexagons and customize the movement costs.- Returns:
- an array of Hexagons, sorted so that the first step comes first.
- Throws:
NoPathFoundException- if there exists no path between start and the goal
-
getQ
public int getQ()
- Returns:
- axial Q-value
-
getR
public int getR()
- Returns:
- axial R-value
-
getVisibleHexes
public java.util.List<Hexagon> getVisibleHexes(int visibleRange)
Calculates all Hexagons that are visible from this Hexagon. The line of sight can be blocked by Hexagons that has isVisualObstacle == true. NOTE: Accuracy is not guaranteed!- Parameters:
visibleRange- a limit of how long distance can be seen assuming there are no obstacles- Returns:
- an array of Hexagons that are visible
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
init
public void init()
-
isBlockingPath
public boolean isBlockingPath()
This affects the pathfinding calculations- Returns:
- true if this is an obstacle that blocks the path
-
isVisualObstacle
public boolean isVisualObstacle()
This affects the field of view calculations.- Returns:
- If true, the hexagons behind this hexagon cannot be seen (but this hexagon can still be seen).
-
renderCoordinates
public void renderCoordinates(javafx.scene.canvas.GraphicsContext gc)
-
setBackgroundColor
public void setBackgroundColor(javafx.scene.paint.Color c)
This method is the safe way to change the background color since it makes sure that the change is made on the JavaFX Application thread.- Parameters:
c- the color
-
setIsBlockingPath
public void setIsBlockingPath(boolean b)
This affects the pathfinding calculations. If true, the algorithm will try to find a path around this Hexagon. If you want to have more control over this, you can supply your own class implementing IPathInfoSupplier to the pathfinding method.- Parameters:
b- true: blocking hexagon
-
setIsVisualObstacle
public void setIsVisualObstacle(boolean b)
This affects the field of view calculations. If true, the hexagons behind this hexagon cannot be seen (but this hexagon can still be seen).- Parameters:
b- true: opaque hexagon
-
setMap
public void setMap(HexagonMap map)
This gives the Hexagon access a HexagonMap without actually adding it to the HexagonMap. It can be useful e.g. if you want to make some calculations before creating another Hexagon.- Parameters:
map- global map reference
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjavafx.scene.shape.Polygon
-
-