Class Space2D

    • Field Detail

      • PROPERTY_POSITION

        public static final java.lang.String PROPERTY_POSITION
        The constant for the position property.
        See Also:
        Constant Field Values
      • PROPERTY_BORDER

        public static final java.lang.String PROPERTY_BORDER
        The constant for the border property.
        See Also:
        Constant Field Values
      • BORDER_STRICT

        public static final java.lang.String BORDER_STRICT
        Border strict mode.
        See Also:
        Constant Field Values
      • BORDER_RELAXED

        public static final java.lang.String BORDER_RELAXED
        Border relaxed mode.
        See Also:
        Constant Field Values
      • BORDER_TORUS

        public static final java.lang.String BORDER_TORUS
        Border torus behavior.
        See Also:
        Constant Field Values
      • areasize

        protected IVector2 areasize
        Area size.
      • kdTrees

        protected java.util.Map<java.lang.String,​KdTree> kdTrees
        KD-Trees.
    • Constructor Detail

      • Space2D

        protected Space2D​(IVector2 areasize)
        Initializes the 2D-Space.
        Parameters:
        spaceexecutor - executor for the space
        actionexecutor - executor for component actions
        areasize - the size of the 2D area
    • Method Detail

      • getAreaSize

        public IVector2 getAreaSize()
        Returns the size of the simulated area.
        Returns:
        size of the simulated area
      • setAreaSize

        public void setAreaSize​(IVector2 areasize)
        Set the area size.
        Parameters:
        areasize - The area size.
      • getBorderMode

        public java.lang.String getBorderMode()
        Get the border mode.
        Returns:
        the border_mode
      • setPosition

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

        public IVector1 getDistance​(IVector2 pos1,
                                    IVector2 pos2)
        Get the distance between two positions.
        Parameters:
        pos1 - The first position.
        pos2 - The second position.
      • getDistance

        public IVector1 getDistance​(IVector1 pos1,
                                    IVector1 pos2,
                                    boolean isx)
        Get the distance between two coordinates (x or y).
        Parameters:
        pos1 - The first position.
        pos2 - The second position.
      • calculateDistance

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

        public IVector2 adjustPosition​(IVector2 pos)
        Calculate a position according to the space borders.
      • getRandomPosition

        public IVector2 getRandomPosition​(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
      • enableKdTree

        public void enableKdTree​(java.lang.String type)
        Enables kd-tree NN-Search optimization for a specific object type. This will increase space overhead but massively decreases restricted nearest-neighborsearches in cases of large amounts of (evenly distributed) objects.
        Parameters:
        String - type The type of object being optimized.
      • disableKdTree

        public void disableKdTree​(java.lang.String type)
        Disables kd-tree NN-Search optimization for a specific object type.
        Parameters:
        String - type The type of object for which the kd-tree is disabled.
      • getNearestObject

        public ISpaceObject getNearestObject​(IVector2 position,
                                             IVector1 maxdist,
                                             java.lang.String type)
        Returns the nearest object to the given position within a maximum distance from the position.
        Parameters:
        position - position the object should be nearest to
        maxdist - maximum distance from the position, use null for unlimited distance
        Returns:
        nearest object's ID or null if none is found
      • getNearObjects

        public java.util.Set<ISpaceObject> getNearObjects​(IVector2 position,
                                                          IVector1 maxdist)
        Retrieve all objects in the distance for a position
        Parameters:
        position -
        distance -
        Returns:
        The near objects.
      • getNearObjects

        public java.util.Set<ISpaceObject> getNearObjects​(IVector2 position,
                                                          IVector1 maxdist,
                                                          java.lang.String type)
        Retrieve all objects in the distance for a position
        Parameters:
        position -
        distance -
        Returns:
        The near objects.
      • getNearObjects

        public java.util.Set<ISpaceObject> getNearObjects​(IVector2 position,
                                                          IVector1 maxdist,
                                                          IFilter filter)
        Retrieve all objects in the distance for a position
        Parameters:
        position -
        distance -
        Returns:
        The near objects.
      • getNearObjects

        public java.util.Set<ISpaceObject> getNearObjects​(IVector2 position,
                                                          IVector1 maxdist,
                                                          java.lang.String type,
                                                          IFilter filter)
        Retrieve all objects in the distance for a position
        Parameters:
        position -
        distance -
        Returns:
        The near objects.
      • getSpaceObjects

        public java.lang.Object[] getSpaceObjects()
        Get all space objects.
        Returns:
        All space objects.