Class Region

  • All Implemented Interfaces:
    IRegion

    public class Region
    extends Object
    implements IRegion
    Represents a region.
    • Field Detail

      • EMPTY

        public static final Region EMPTY
        The constant EMPTY.
    • Constructor Detail

      • Region

        public Region​(int left,
                      int top,
                      int width,
                      int height)
        Instantiates a new Region.
        Parameters:
        left - the left
        top - the top
        width - the width
        height - the height
      • Region

        public Region​(int left,
                      int top,
                      int width,
                      int height,
                      CoordinatesType coordinatesType)
        Instantiates a new Region.
        Parameters:
        left - the left
        top - the top
        width - the width
        height - the height
        coordinatesType - the coordinates type
      • Region

        public Region​(Rectangle rectangle)
      • Region

        public Region​(Location location,
                      RectangleSize size)
        Instantiates a new Region.
        Parameters:
        location - the location
        size - the size
      • Region

        public Region​(Location location,
                      RectangleSize size,
                      CoordinatesType coordinatesType)
        Instantiates a new Region.
        Parameters:
        location - the location
        size - the size
        coordinatesType - the coordinates type
      • Region

        public Region​(IRegion other)
        Instantiates a new Region.
        Parameters:
        other - the other
    • Method Detail

      • makeEmpty

        protected void makeEmpty()
        Make empty.
      • isEmpty

        public boolean isEmpty()
        Is empty boolean.
        Returns:
        true if the region is empty, false otherwise.
      • isSizeEmpty

        public boolean isSizeEmpty()
        Is size empty boolean.
        Returns:
        true if the region's size is 0, false otherwise.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getLocation

        public Location getLocation()
        Gets location.
        Specified by:
        getLocation in interface IRegion
        Returns:
        The (left, top) position of the current region.
      • getNegativeLocation

        public Location getNegativeLocation()
        Gets negative location.
        Returns:
        The (-left, -top) position of the current region.
      • offset

        public Region offset​(int dx,
                             int dy)
        Get an offset region.
        Specified by:
        offset in interface IRegion
        Parameters:
        dx - The X axis offset.
        dy - The Y axis offset.
        Returns:
        A region with an offset location.
      • offset

        public Region offset​(Location location)
        Get an offset region.
        Parameters:
        location - the amount by which to offset.
        Returns:
        A region with an offset location.
      • scale

        public Region scale​(double scaleRatio)
        Get a region which is a scaled version of the current region. IMPORTANT: This also scales the LOCATION(!!) of the region (not just its size).
        Parameters:
        scaleRatio - The ratio by which to scale the region.
        Returns:
        A new region which is a scaled version of the current region.
      • setCoordinatesType

        public void setCoordinatesType​(CoordinatesType value)
        Sets coordinates type.
        Parameters:
        value - the value
      • setSize

        public void setSize​(RectangleSize size)
        Sets size.
        Parameters:
        size - The updated size of the region.
      • setLocation

        public void setLocation​(Location location)
        Set the (top,left) position of the current region
        Parameters:
        location - The (top,left) position to set.
      • getSubRegions

        public Iterable<Region> getSubRegions​(RectangleSize subRegionSize,
                                              boolean isFixedSize)
        Returns a list of sub-regions which compose the current region.
        Parameters:
        subRegionSize - The default sub-region size to use.
        isFixedSize - If false, then sub-regions might have a size which is smaller then subRegionSize (thus there will be no overlap of regions). Otherwise, all sub-regions will have the same size, but sub-regions might overlap.
        Returns:
        The sub-regions composing the current region. If subRegionSize is equal or greater than the current region, only a single region is returned.
      • contains

        public boolean contains​(Region other)
        Check if a region is contained within the current region.
        Parameters:
        other - The region to check if it is contained within the current region.
        Returns:
        True if other is contained within the current region, false otherwise.
      • contains

        public boolean contains​(Location location)
        Check if a specified location is contained within this region.

        Parameters:
        location - The location to test.
        Returns:
        True if the location is contained within this region, false otherwise.
      • isIntersected

        public boolean isIntersected​(Region other)
        Check if a region is intersected with the current region.
        Parameters:
        other - The region to check intersection with.
        Returns:
        True if the regions are intersected, false otherwise.
      • intersect

        public void intersect​(Region other)
        Replaces this region with the intersection of itself and other
        Parameters:
        other - The region with which to intersect.
      • getIntersected

        public Region getIntersected​(Region other)
      • getLeft

        public int getLeft()
        Gets left.
        Specified by:
        getLeft in interface IRegion
        Returns:
        the left
      • getTop

        public int getTop()
        Gets top.
        Specified by:
        getTop in interface IRegion
        Returns:
        the top
      • getWidth

        public int getWidth()
        Gets width.
        Specified by:
        getWidth in interface IRegion
        Returns:
        the width
      • getHeight

        public int getHeight()
        Gets height.
        Specified by:
        getHeight in interface IRegion
        Returns:
        the height
      • setLeft

        public void setLeft​(int value)
        Sets left.
        Parameters:
        value - the value
      • setTop

        public void setTop​(int value)
        Sets top.
        Parameters:
        value - the value
      • getBottom

        public int getBottom()
      • getRight

        public int getRight()
      • setWidth

        public void setWidth​(int value)
        Sets width.
        Parameters:
        value - the value
      • setHeight

        public void setHeight​(int value)
        Sets height.
        Parameters:
        value - the value
      • getMiddleOffset

        public Location getMiddleOffset()
        Gets middle offset.
        Returns:
        the middle offset
      • expandToContain

        public Region expandToContain​(Region region)
        Expand to contain region.
        Parameters:
        region - the region
        Returns:
        the region
      • getArea

        public int getArea()
        Specified by:
        getArea in interface IRegion
      • setX

        public void setX​(int x)
      • setY

        public void setY​(int y)
      • getRegionId

        public String getRegionId()