public class

Region

extends Object
java.lang.Object
   ↳ sun.java2d.pipe.Region

Class Overview

This class encapsulates a definition of a two dimensional region which consists of a number of Y ranges each containing multiple X bands.

A rectangular Region is allowed to have a null band list in which case the rectangular shape is defined by the bounding box parameters (lox, loy, hix, hiy).

The band list, if present, consists of a list of rows in ascending Y order, ending at endIndex which is the index beyond the end of the last row. Each row consists of at least 3 + 2n entries (n >= 1) where the first 3 entries specify the Y range as start, end, and the number of X ranges in that Y range. These 3 entries are followed by pairs of X coordinates in ascending order:

 bands[rowstart+0] = Y0;        // starting Y coordinate
 bands[rowstart+1] = Y1;        // ending Y coordinate - endY > startY
 bands[rowstart+2] = N;         // number of X bands - N >= 1

 bands[rowstart+3] = X10;       // starting X coordinate of first band
 bands[rowstart+4] = X11;       // ending X coordinate of first band
 bands[rowstart+5] = X20;       // starting X coordinate of second band
 bands[rowstart+6] = X21;       // ending X coordinate of second band
 ...
 bands[rowstart+3+N*2-2] = XN0; // starting X coord of last band
 bands[rowstart+3+N*2-1] = XN1; // ending X coord of last band

 bands[rowstart+3+N*2] = ...    // start of next Y row
 

Summary

Public Methods
void appendSpans(SpanIterator si)
Appends the list of spans returned from the indicated SpanIterator.
static int clipAdd(int v, int dv)
Adds the delta dv to the value v with appropriate clipping to the bounds of Integer resolution.
void clipBoxToBounds(int[] bbox)
Clips the indicated bbox array to the bounds of this Region.
boolean contains(int x, int y)
Returns true iff this Region contains the specified coordinate.
static int dimAdd(int start, int dim)
Adds the dimension dim to the coordinate start with appropriate clipping.
boolean encompasses(Region r)
Quickly checks if this Region surrounds the specified Region object.
boolean encompassesXYWH(int x, int y, int w, int h)
Quickly checks if this Region surrounds the specified rectangular area specified in x, y, width, height format.
boolean encompassesXYXY(int lox, int loy, int hix, int hiy)
Quickly checks if this Region surrounds the specified rectangular area specified in lox, loy, hix, hiy format.
boolean equals(Object o)
Indicates whether some other object is "equal to" this one.
SpanIterator filter(SpanIterator si)
Returns a SpanIterator that is the argument iterator filtered by this region.
void getBounds(int[] pathbox)
Gets the bbox of the available spans, clipped to the OutputArea.
Region getBoundsIntersection(Rectangle r)
Returns a Region object that represents the bounds of the intersection of this object with the bounds of the specified Region object.
Region getBoundsIntersection(Region r)
Returns a Region object that represents the intersection of this object with the bounds of the specified Region object.
Region getBoundsIntersectionXYWH(int x, int y, int w, int h)
Returns a Region object that represents the bounds of the intersection of this object with the bounds of the specified rectangular area in x, y, width, height format.
Region getBoundsIntersectionXYXY(int lox, int loy, int hix, int hiy)
Returns a Region object that represents the bounds of the intersection of this object with the bounds of the specified rectangular area in lox, loy, hix, hiy format.
Region getDifference(Region r)
Returns a Region object that represents the difference of the specified Region object subtracted from this object.
Region getExclusiveOr(Region r)
Returns a Region object that represents the exclusive or of this object with the specified Region object.
final int getHeight()
Returns the height of this Region clipped to the range (0 - MAX_INT).
final int getHiX()
Returns the highest X coordinate in the Region.
final int getHiY()
Returns the highest Y coordinate in the Region.
static Region getInstance(Shape s, AffineTransform at)
Returns a Region object covering the pixels which would be touched by a fill or clip operation on a Graphics implementation on the specified Shape object under the optionally specified AffineTransform object.
static Region getInstance(Region devBounds, boolean normalize, Shape s, AffineTransform at)
Returns a Region object covering the pixels which would be touched by a fill or clip operation on a Graphics implementation on the specified Shape object under the optionally specified AffineTransform object further restricted by the specified device bounds.
static Region getInstance(Rectangle r)
Returns a Region object with a rectangle of interest specified by the indicated Rectangle object.
static Region getInstance(int[] box)
Returns a Region object with a rectangle of interest specified by the indicated span array.
static Region getInstance(Region devBounds, Shape s, AffineTransform at)
Returns a Region object covering the pixels which would be touched by a fill or clip operation on a Graphics implementation on the specified Shape object under the optionally specified AffineTransform object further restricted by the specified device bounds.
static Region getInstanceXYWH(int x, int y, int w, int h)
Returns a Region object with a rectangle of interest specified by the indicated rectangular area in x, y, width, height format.
static Region getInstanceXYXY(int lox, int loy, int hix, int hiy)
Returns a Region object with a rectangle of interest specified by the indicated rectangular area in lox, loy, hix, hiy format.
Region getIntersection(Region r)
Returns a Region object that represents the intersection of this object with the specified Region object.
Region getIntersection(Rectangle r)
Returns a Region object that represents the intersection of this object with the specified Rectangle.
Region getIntersectionXYWH(int x, int y, int w, int h)
Returns a Region object that represents the intersection of this object with the specified rectangular area.
Region getIntersectionXYXY(int lox, int loy, int hix, int hiy)
Returns a Region object that represents the intersection of this object with the specified rectangular area.
RegionIterator getIterator()
Gets an iterator object to iterate over the spans in this region.
final int getLoX()
Returns the lowest X coordinate in the Region.
final int getLoY()
Returns the lowest Y coordinate in the Region.
SpanIterator getSpanIterator()
Gets a span iterator object that iterates over the spans in this region
SpanIterator getSpanIterator(int[] bbox)
Gets a span iterator object that iterates over the spans in this region but clipped to the bounds given in the argument (xlo, ylo, xhi, yhi).
Region getTranslatedRegion(int dx, int dy)
Returns a Region object that represents the same list of rectangles as the current Region object, translated by the specified dx, dy translation factors.
Region getUnion(Region r)
Returns a Region object that represents the union of this object with the specified Region object.
final int getWidth()
Returns the width of this Region clipped to the range (0 - MAX_INT).
int hashCode()
Returns a hash code value for the object.
boolean intersectsQuickCheck(Region r)
Quickly checks if this Region intersects the specified Region object.
boolean intersectsQuickCheckXYXY(int lox, int loy, int hix, int hiy)
Quickly checks if this Region intersects the specified rectangular area specified in lox, loy, hix, hiy format.
boolean isEmpty()
Returns true iff this Region encloses no area.
boolean isInsideQuickCheck(Region r)
Quickly checks if this Region lies inside the specified Region object.
boolean isInsideXYWH(int x, int y, int w, int h)
Returns true iff this Region lies inside the indicated rectangular area specified in x, y, width, height format with appropriate clipping performed as per the dimAdd method.
boolean isInsideXYXY(int lox, int loy, int hix, int hiy)
Returns true iff this Region lies inside the indicated rectangular area specified in lox, loy, hix, hiy format.
boolean isRectangular()
Returns true iff this Region represents a single simple rectangular area.
void setOutputArea(int[] box)
Sets the rectangle of interest for storing and returning region bands.
void setOutputArea(Rectangle r)
Sets the rectangle of interest for storing and returning region bands.
void setOutputAreaXYWH(int x, int y, int w, int h)
Sets the rectangle of interest for storing and returning region bands.
void setOutputAreaXYXY(int lox, int loy, int hix, int hiy)
Sets the rectangle of interest for storing and returning region bands.
String toString()
Returns a string representation of the object.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public void appendSpans (SpanIterator si)

Appends the list of spans returned from the indicated SpanIterator. Each span must be at a higher starting Y coordinate than the previous data or it must have a Y range equal to the highest Y band in the region and a higher X coordinate than any of the spans in that band.

public static int clipAdd (int v, int dv)

Adds the delta dv to the value v with appropriate clipping to the bounds of Integer resolution. If the answer would be greater than Integer.MAX_VALUE then Integer.MAX_VALUE is returned. If the answer would be less than Integer.MIN_VALUE then Integer.MIN_VALUE is returned. Otherwise the sum is returned.

public void clipBoxToBounds (int[] bbox)

Clips the indicated bbox array to the bounds of this Region.

public boolean contains (int x, int y)

Returns true iff this Region contains the specified coordinate.

public static int dimAdd (int start, int dim)

Adds the dimension dim to the coordinate start with appropriate clipping. If dim is non-positive then the method returns the start coordinate. If the sum overflows an integer data type then the method returns Integer.MAX_VALUE.

public boolean encompasses (Region r)

Quickly checks if this Region surrounds the specified Region object.

This method will return false if this Region object is not a simple rectangle.

public boolean encompassesXYWH (int x, int y, int w, int h)

Quickly checks if this Region surrounds the specified rectangular area specified in x, y, width, height format.

This method will return false if this Region object is not a simple rectangle.

public boolean encompassesXYXY (int lox, int loy, int hix, int hiy)

Quickly checks if this Region surrounds the specified rectangular area specified in lox, loy, hix, hiy format.

This method will return false if this Region object is not a simple rectangle.

public boolean equals (Object o)

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).

Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.

Parameters
o the reference object with which to compare.
Returns
  • true if this object is the same as the obj argument; false otherwise.

public SpanIterator filter (SpanIterator si)

Returns a SpanIterator that is the argument iterator filtered by this region.

public void getBounds (int[] pathbox)

Gets the bbox of the available spans, clipped to the OutputArea.

public Region getBoundsIntersection (Rectangle r)

Returns a Region object that represents the bounds of the intersection of this object with the bounds of the specified Region object.

The return value may be this same object if no clipping occurs and this Region is rectangular.

public Region getBoundsIntersection (Region r)

Returns a Region object that represents the intersection of this object with the bounds of the specified Region object.

The return value may be this same object or the argument Region object if no clipping occurs and the Regions are rectangular.

public Region getBoundsIntersectionXYWH (int x, int y, int w, int h)

Returns a Region object that represents the bounds of the intersection of this object with the bounds of the specified rectangular area in x, y, width, height format.

The return value may be this same object if no clipping occurs and this Region is rectangular.

public Region getBoundsIntersectionXYXY (int lox, int loy, int hix, int hiy)

Returns a Region object that represents the bounds of the intersection of this object with the bounds of the specified rectangular area in lox, loy, hix, hiy format.

The return value may be this same object if no clipping occurs and this Region is rectangular.

public Region getDifference (Region r)

Returns a Region object that represents the difference of the specified Region object subtracted from this object.

If A and B are both Region Objects and C = A.getDifference(B); then a point will be contained in C iff it is contained in A but not contained in B.

The return value may be this same object or the argument Region object if no clipping occurs.

public Region getExclusiveOr (Region r)

Returns a Region object that represents the exclusive or of this object with the specified Region object.

If A and B are both Region Objects and C = A.getExclusiveOr(B); then a point will be contained in C iff it is contained in either A or B, but not if it is contained in both.

The return value may be this same object or the argument Region object if either is empty.

public final int getHeight ()

Returns the height of this Region clipped to the range (0 - MAX_INT).

public final int getHiX ()

Returns the highest X coordinate in the Region.

public final int getHiY ()

Returns the highest Y coordinate in the Region.

public static Region getInstance (Shape s, AffineTransform at)

Returns a Region object covering the pixels which would be touched by a fill or clip operation on a Graphics implementation on the specified Shape object under the optionally specified AffineTransform object.

Parameters
s a non-null Shape object specifying the geometry enclosing the pixels of interest
at an optional AffineTransform to be applied to the coordinates as they are returned in the iteration, or null if untransformed coordinates are desired

public static Region getInstance (Region devBounds, boolean normalize, Shape s, AffineTransform at)

Returns a Region object covering the pixels which would be touched by a fill or clip operation on a Graphics implementation on the specified Shape object under the optionally specified AffineTransform object further restricted by the specified device bounds. If the normalize parameter is true then coordinate normalization is performed as per the 2D Graphics non-antialiasing implementation of the VALUE_STROKE_NORMALIZE hint.

Note that only the bounds of the specified Region are used to restrict the resulting Region. If devBounds is non-rectangular and clipping to the specific bands of devBounds is needed, then an intersection of the resulting Region with devBounds must be performed in a subsequent step.

Parameters
devBounds a non-null Region specifying some bounds to clip the geometry to
normalize a boolean indicating whether or not to apply normalization
s a non-null Shape object specifying the geometry enclosing the pixels of interest
at an optional AffineTransform to be applied to the coordinates as they are returned in the iteration, or null if untransformed coordinates are desired

public static Region getInstance (Rectangle r)

Returns a Region object with a rectangle of interest specified by the indicated Rectangle object.

This method can also be used to create a simple rectangular region.

public static Region getInstance (int[] box)

Returns a Region object with a rectangle of interest specified by the indicated span array.

This method can also be used to create a simple rectangular region.

public static Region getInstance (Region devBounds, Shape s, AffineTransform at)

Returns a Region object covering the pixels which would be touched by a fill or clip operation on a Graphics implementation on the specified Shape object under the optionally specified AffineTransform object further restricted by the specified device bounds.

Note that only the bounds of the specified Region are used to restrict the resulting Region. If devBounds is non-rectangular and clipping to the specific bands of devBounds is needed, then an intersection of the resulting Region with devBounds must be performed in a subsequent step.

Parameters
devBounds a non-null Region specifying some bounds to clip the geometry to
s a non-null Shape object specifying the geometry enclosing the pixels of interest
at an optional AffineTransform to be applied to the coordinates as they are returned in the iteration, or null if untransformed coordinates are desired

public static Region getInstanceXYWH (int x, int y, int w, int h)

Returns a Region object with a rectangle of interest specified by the indicated rectangular area in x, y, width, height format.

This method can also be used to create a simple rectangular region.

public static Region getInstanceXYXY (int lox, int loy, int hix, int hiy)

Returns a Region object with a rectangle of interest specified by the indicated rectangular area in lox, loy, hix, hiy format.

This method can also be used to create a simple rectangular region.

public Region getIntersection (Region r)

Returns a Region object that represents the intersection of this object with the specified Region object.

If A and B are both Region Objects and C = A.getIntersection(B); then a point will be contained in C iff it is contained in both A and B.

The return value may be this same object or the argument Region object if no clipping occurs.

public Region getIntersection (Rectangle r)

Returns a Region object that represents the intersection of this object with the specified Rectangle. The return value may be this same object if no clipping occurs.

public Region getIntersectionXYWH (int x, int y, int w, int h)

Returns a Region object that represents the intersection of this object with the specified rectangular area. The return value may be this same object if no clipping occurs.

public Region getIntersectionXYXY (int lox, int loy, int hix, int hiy)

Returns a Region object that represents the intersection of this object with the specified rectangular area. The return value may be this same object if no clipping occurs.

public RegionIterator getIterator ()

Gets an iterator object to iterate over the spans in this region.

public final int getLoX ()

Returns the lowest X coordinate in the Region.

public final int getLoY ()

Returns the lowest Y coordinate in the Region.

public SpanIterator getSpanIterator ()

Gets a span iterator object that iterates over the spans in this region

public SpanIterator getSpanIterator (int[] bbox)

Gets a span iterator object that iterates over the spans in this region but clipped to the bounds given in the argument (xlo, ylo, xhi, yhi).

public Region getTranslatedRegion (int dx, int dy)

Returns a Region object that represents the same list of rectangles as the current Region object, translated by the specified dx, dy translation factors.

public Region getUnion (Region r)

Returns a Region object that represents the union of this object with the specified Region object.

If A and B are both Region Objects and C = A.getUnion(B); then a point will be contained in C iff it is contained in either A or B.

The return value may be this same object or the argument Region object if no augmentation occurs.

public final int getWidth ()

Returns the width of this Region clipped to the range (0 - MAX_INT).

public int hashCode ()

Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables.

As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

Returns
  • a hash code value for this object.

public boolean intersectsQuickCheck (Region r)

Quickly checks if this Region intersects the specified Region object.

This method tests only against the bounds of this region and does not bother to test if the rectangular region actually intersects any bands.

public boolean intersectsQuickCheckXYXY (int lox, int loy, int hix, int hiy)

Quickly checks if this Region intersects the specified rectangular area specified in lox, loy, hix, hiy format.

This method tests only against the bounds of this region and does not bother to test if the rectangular region actually intersects any bands.

public boolean isEmpty ()

Returns true iff this Region encloses no area.

public boolean isInsideQuickCheck (Region r)

Quickly checks if this Region lies inside the specified Region object.

This method will return false if the specified Region object is not a simple rectangle.

public boolean isInsideXYWH (int x, int y, int w, int h)

Returns true iff this Region lies inside the indicated rectangular area specified in x, y, width, height format with appropriate clipping performed as per the dimAdd method.

public boolean isInsideXYXY (int lox, int loy, int hix, int hiy)

Returns true iff this Region lies inside the indicated rectangular area specified in lox, loy, hix, hiy format.

public boolean isRectangular ()

Returns true iff this Region represents a single simple rectangular area.

public void setOutputArea (int[] box)

Sets the rectangle of interest for storing and returning region bands. The rectangle is specified as a span array.

This method can also be used to initialize a simple rectangular region.

public void setOutputArea (Rectangle r)

Sets the rectangle of interest for storing and returning region bands.

This method can also be used to initialize a simple rectangular region.

public void setOutputAreaXYWH (int x, int y, int w, int h)

Sets the rectangle of interest for storing and returning region bands. The rectangle is specified in x, y, width, height format and appropriate clipping is performed as per the method dimAdd.

This method can also be used to initialize a simple rectangular region.

public void setOutputAreaXYXY (int lox, int loy, int hix, int hiy)

Sets the rectangle of interest for storing and returning region bands. The rectangle is specified in lox, loy, hix, hiy format.

This method can also be used to initialize a simple rectangular region.

public String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
  • a string representation of the object.