Class Grid2D

    • Field Detail

      • DEFAULT_NAME

        public static final java.lang.String DEFAULT_NAME
        The default ID for this space.
      • NEIGHBORHOOD_MOORE

        public static final java.lang.String NEIGHBORHOOD_MOORE
        The moore neighborhood.
        See Also:
        Constant Field Values
      • NEIGHBORHOOD_VON_NEUMANN

        public static final java.lang.String NEIGHBORHOOD_VON_NEUMANN
        The von neumann neighborhood.
        See Also:
        Constant Field Values
      • PROPERTY_NEIGHBORHOOD

        public static final java.lang.String PROPERTY_NEIGHBORHOOD
        The neighborhood property.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Grid2D

        public Grid2D()
        Creates a new ContinuousSpace2D with the default name.
        Parameters:
        clockService - the clock service
        timeCoefficient - the time coefficient for time differences.
        areaSize - the size of the 2D area
      • Grid2D

        public Grid2D​(IVector2 areasize)
        Creates a new ContinuousSpace2D with the default name.
        Parameters:
        actionexecutor - executor for component actions
        areasize - the size of the 2D area
      • Grid2D

        public Grid2D​(java.lang.Object name,
                      IVector2 areasize)
        Creates a new ContinuousSpace2D with a special ID.
        Parameters:
        name - the name of this space
        areasize - the size of the 2D area
        actionexecutor - executor for component actions
    • Method Detail

      • setAreaSize

        public void setAreaSize​(IVector2 areasize)
        Set the area size.
        Overrides:
        setAreaSize in class Space2D
        Parameters:
        areasize - The area size.
      • getNeighborhood

        public java.lang.String getNeighborhood()
        Get the neighborhood.
        Returns:
        Set the neighborhood.
      • getSpaceObjectsByGridPosition

        public java.util.Collection<ISpaceObject> getSpaceObjectsByGridPosition​(IVector2 position,
                                                                                java.lang.Object type)
        Get all SimObjects from a specific type at a specific grid position
      • getEmptyGridPosition

        public IVector2 getEmptyGridPosition()
        Get an empty position in the grid.
        Returns:
        Empty IVector2 position.
      • getRandomGridPosition

        public IVector2 getRandomGridPosition​(IVector2 distance)
        Retrieves a random position within the simulation area with a minimum distance from the edge.
        Parameters:
        distance - minimum distance from the edge, null or zero for no distance
      • setPosition

        public void setPosition​(java.lang.Object id,
                                IVector2 pos)
        Set the position of an object.
        Overrides:
        setPosition in class Space2D
        Parameters:
        id - The object id.
        pos - The object position.
      • destroyAndVerifySpaceObject

        public boolean destroyAndVerifySpaceObject​(java.lang.Object id)
        Destroys an object in this space.
        Parameters:
        objectId - the object's ID
      • getNearGridObjects

        public java.util.Set<ISpaceObject> getNearGridObjects​(IVector2 position,
                                                              int range,
                                                              java.lang.String[] types)
      • getNearObjects

        public java.util.Set<ISpaceObject> getNearObjects​(IVector2 position,
                                                          IVector1 distance,
                                                          java.lang.String type)
        Retrieve all objects in the distance for a position. Uses position->object mapping, for fast operation.
        Overrides:
        getNearObjects in class Space2D
        Parameters:
        position - The position.
        distance - The distance.
        type - The type (or null for all objects).
        Returns:
        The near objects.
      • calculateDistance

        public IVector1 calculateDistance​(IVector1 dx,
                                          IVector1 dy)
        Calculate the distance in the space.
        Overrides:
        calculateDistance in class Space2D
        Parameters:
        dx - The distance in x.
        dy - The distance in y.
        Returns:
        The distance according to the distance metrics of the space.
      • getShortestDirection

        public IVector1 getShortestDirection​(IVector1 pos1,
                                             IVector1 pos2,
                                             boolean isx)
        Get the shortest (direct) direction between two coordinates.
        Parameters:
        pos1 - The first position.
        pos2 - The second position.
        isx - The flag indicating if x or y).
        Returns:
        -1: left/down, +1: right/up, 0: no move