| Method from sun.java2d.pipe.Region Detail: |
public void appendSpans(SpanIterator si) {
int[] box = new int[6];
while (si.nextSpan(box)) {
appendSpan(box);
}
endRow(box);
calcBBox();
}
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) {
int newv = v + dv;
if ((newv > v) != (dv > 0)) {
newv = (dv < 0) ? Integer.MIN_VALUE : Integer.MAX_VALUE;
}
return newv;
}
Adds the delta {@code dv} to the value {@code v} with
appropriate clipping to the bounds of Integer resolution.
If the answer would be greater than {@code Integer.MAX_VALUE}
then {@code Integer.MAX_VALUE} is returned.
If the answer would be less than {@code Integer.MIN_VALUE}
then {@code Integer.MIN_VALUE} is returned.
Otherwise the sum is returned. |
public void clipBoxToBounds(int[] bbox) {
if (bbox[0] < lox) bbox[0] = lox;
if (bbox[1] < loy) bbox[1] = loy;
if (bbox[2] > hix) bbox[2] = hix;
if (bbox[3] > hiy) bbox[3] = hiy;
}
Clips the indicated bbox array to the bounds of this Region. |
public boolean contains(int x,
int y) {
if (x < lox || x >= hix || y < loy || y >= hiy) return false;
if (bands == null) return true;
int i = 0;
while (i < endIndex) {
if (y < bands[i++]) {
return false;
}
if (y >= bands[i++]) {
int numspans = bands[i++];
i += numspans * 2;
} else {
int end = bands[i++];
end = i + end * 2;
while (i < end) {
if (x < bands[i++]) return false;
if (x < bands[i++]) return true;
}
return false;
}
}
return false;
}
Returns true iff this Region contains the specified coordinate. |
public static int dimAdd(int start,
int dim) {
initIDs();
if (dim < = 0) return start;
if ((dim += start) < start) return Integer.MAX_VALUE;
return 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) {
return (this.bands == null &&
this.lox < = r.lox && this.loy < = r.loy &&
this.hix >= r.hix && this.hiy >= r.hiy);
}
|
public boolean encompassesXYWH(int x,
int y,
int w,
int h) {
return encompassesXYXY(x, y, dimAdd(x, w), dimAdd(y, h));
}
|
public boolean encompassesXYXY(int lox,
int loy,
int hix,
int hiy) {
return (this.bands == null &&
this.lox < = lox && this.loy < = loy &&
this.hix >= hix && this.hiy >= hiy);
}
|
public boolean equals(Object o) {
if (!(o instanceof Region)) {
return false;
}
Region r = (Region) o;
if (this.isEmpty()) {
return r.isEmpty();
} else if (r.isEmpty()) {
return false;
}
if (r.lox != this.lox || r.loy != this.loy ||
r.hiy != this.hiy || r.hiy != this.hiy)
{
return false;
}
if (this.bands == null) {
return (r.bands == null);
} else if (r.bands == null) {
return false;
}
if (this.endIndex != r.endIndex) {
return false;
}
int abands[] = this.bands;
int bbands[] = r.bands;
for (int i = 0; i < endIndex; i++) {
if (abands[i] != bbands[i]) {
return false;
}
}
return true;
}
|
public SpanIterator filter(SpanIterator si) {
if (bands == null) {
si.intersectClipBox(lox, loy, hix, hiy);
} else {
si = new RegionClipSpanIterator(this, si);
}
return si;
}
Returns a SpanIterator that is the argument iterator filtered by
this region. |
public void getBounds(int[] pathbox) {
pathbox[0] = lox;
pathbox[1] = loy;
pathbox[2] = hix;
pathbox[3] = hiy;
}
Gets the bbox of the available spans, clipped to the OutputArea. |
public Region getBoundsIntersection(Rectangle r) {
return getBoundsIntersectionXYWH(r.x, r.y, r.width, r.height);
}
|
public Region getBoundsIntersection(Region r) {
if (this.encompasses(r)) {
return r;
}
if (r.encompasses(this)) {
return this;
}
return new Region((r.lox < this.lox) ? this.lox : r.lox,
(r.loy < this.loy) ? this.loy : r.loy,
(r.hix > this.hix) ? this.hix : r.hix,
(r.hiy > this.hiy) ? this.hiy : r.hiy);
}
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) {
return getBoundsIntersectionXYXY(x, y, dimAdd(x, w), dimAdd(y, h));
}
|
public Region getBoundsIntersectionXYXY(int lox,
int loy,
int hix,
int hiy) {
if (this.bands == null &&
this.lox >= lox && this.loy >= loy &&
this.hix < = hix && this.hiy < = hiy)
{
return this;
}
return new Region((lox < this.lox) ? this.lox : lox,
(loy < this.loy) ? this.loy : loy,
(hix > this.hix) ? this.hix : hix,
(hiy > this.hiy) ? this.hiy : hiy);
}
|
public Region getDifference(Region r) {
if (!r.intersectsQuickCheck(this)) {
return this;
}
if (this.isInsideQuickCheck(r)) {
return EMPTY_REGION;
}
Region ret = new Region(this.lox, this.loy, this.hix, this.hiy);
ret.filterSpans(this, r, INCLUDE_A);
return ret;
}
Returns a Region object that represents the difference of the
specified Region object subtracted from this object.
If {@code A} and {@code B} are both Region Objects and
C = A.getDifference(B); then a point will
be contained in {@code C} iff it is contained in
{@code A} but not contained in {@code B}.
The return value may be this same object or the argument
Region object if no clipping occurs. |
public Region getExclusiveOr(Region r) {
if (r.isEmpty()) {
return this;
}
if (this.isEmpty()) {
return r;
}
Region ret = new Region((r.lox > this.lox) ? this.lox : r.lox,
(r.loy > this.loy) ? this.loy : r.loy,
(r.hix < this.hix) ? this.hix : r.hix,
(r.hiy < this.hiy) ? this.hiy : r.hiy);
ret.filterSpans(this, r, INCLUDE_A | INCLUDE_B);
return ret;
}
Returns a Region object that represents the exclusive or of this
object with the specified Region object.
If {@code A} and {@code B} are both Region Objects and
C = A.getExclusiveOr(B); then a point will
be contained in {@code C} iff it is contained in either
{@code A} or {@code 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() {
if (hiy < loy) return 0;
int h;
if ((h = hiy - loy) < 0) {
h = Integer.MAX_VALUE;
}
return h;
}
Returns the height of this Region clipped to the range (0 - MAX_INT). |
public final int getHiX() {
return hix;
}
Returns the highest X coordinate in the Region. |
public final int getHiY() {
return hiy;
}
Returns the highest Y coordinate in the Region. |
public static Region getInstance(Rectangle r) {
return Region.getInstanceXYWH(r.x, r.y, r.width, r.height);
}
|
public static Region getInstance(int[] box) {
return new Region(box[0], box[1], box[2], box[3]);
}
|
public static Region getInstance(Shape s,
AffineTransform at) {
return getInstance(WHOLE_REGION, false, s, 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. |
public static Region getInstance(Region devBounds,
Shape s,
AffineTransform at) {
return getInstance(devBounds, false, s, 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. |
public static Region getInstance(Region devBounds,
boolean normalize,
Shape s,
AffineTransform at) {
int box[] = new int[4];
ShapeSpanIterator sr = new ShapeSpanIterator(normalize);
try {
sr.setOutputArea(devBounds);
sr.appendPath(s.getPathIterator(at));
sr.getPathBox(box);
Region r = Region.getInstance(box);
r.appendSpans(sr);
return r;
} finally {
sr.dispose();
}
}
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. |
public static Region getInstanceXYWH(int x,
int y,
int w,
int h) {
return Region.getInstanceXYXY(x, y, dimAdd(x, w), dimAdd(y, h));
}
|
public static Region getInstanceXYXY(int lox,
int loy,
int hix,
int hiy) {
return new Region(lox, loy, hix, hiy);
}
|
public Region getIntersection(Rectangle r) {
return getIntersectionXYWH(r.x, r.y, r.width, r.height);
}
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 getIntersection(Region r) {
if (this.isInsideQuickCheck(r)) {
return this;
}
if (r.isInsideQuickCheck(this)) {
return r;
}
Region ret = new Region((r.lox < this.lox) ? this.lox : r.lox,
(r.loy < this.loy) ? this.loy : r.loy,
(r.hix > this.hix) ? this.hix : r.hix,
(r.hiy > this.hiy) ? this.hiy : r.hiy);
if (!ret.isEmpty()) {
ret.filterSpans(this, r, INCLUDE_COMMON);
}
return ret;
}
Returns a Region object that represents the intersection of this
object with the specified Region object.
If {@code A} and {@code B} are both Region Objects and
C = A.getIntersection(B); then a point will
be contained in {@code C} iff it is contained in both
{@code A} and {@code B}.
The return value may be this same object or the argument
Region object if no clipping occurs. |
public Region getIntersectionXYWH(int x,
int y,
int w,
int h) {
return getIntersectionXYXY(x, y, dimAdd(x, w), dimAdd(y, 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) {
if (isInsideXYXY(lox, loy, hix, hiy)) {
return this;
}
Region ret = new Region((lox < this.lox) ? this.lox : lox,
(loy < this.loy) ? this.loy : loy,
(hix > this.hix) ? this.hix : hix,
(hiy > this.hiy) ? this.hiy : hiy);
if (bands != null) {
ret.appendSpans(this.getSpanIterator());
}
return ret;
}
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() {
return new RegionIterator(this);
}
Gets an iterator object to iterate over the spans in this region. |
public final int getLoX() {
return lox;
}
Returns the lowest X coordinate in the Region. |
public final int getLoY() {
return loy;
}
Returns the lowest Y coordinate in the Region. |
public SpanIterator getSpanIterator() {
return new RegionSpanIterator(this);
}
Gets a span iterator object that iterates over the spans in this region |
public SpanIterator getSpanIterator(int[] bbox) {
SpanIterator result = getSpanIterator();
result.intersectClipBox(bbox[0], bbox[1], bbox[2], bbox[3]);
return result;
}
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) {
if ((dx | dy) == 0) {
return this;
}
int tlox = lox + dx;
int tloy = loy + dy;
int thix = hix + dx;
int thiy = hiy + dy;
if ((tlox > lox) != (dx > 0) ||
(tloy > loy) != (dy > 0) ||
(thix > hix) != (dx > 0) ||
(thiy > hiy) != (dy > 0))
{
return getSafeTranslatedRegion(dx, dy);
}
Region ret = new Region(tlox, tloy, thix, thiy);
int bands[] = this.bands;
if (bands != null) {
int end = endIndex;
ret.endIndex = end;
int newbands[] = new int[end];
ret.bands = newbands;
int i = 0;
int ncol;
while (i < end) {
newbands[i] = bands[i] + dy; i++;
newbands[i] = bands[i] + dy; i++;
newbands[i] = ncol = bands[i]; i++;
while (--ncol >= 0) {
newbands[i] = bands[i] + dx; i++;
newbands[i] = bands[i] + dx; i++;
}
}
}
return ret;
}
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) {
if (r.isEmpty() || r.isInsideQuickCheck(this)) {
return this;
}
if (this.isEmpty() || this.isInsideQuickCheck(r)) {
return r;
}
Region ret = new Region((r.lox > this.lox) ? this.lox : r.lox,
(r.loy > this.loy) ? this.loy : r.loy,
(r.hix < this.hix) ? this.hix : r.hix,
(r.hiy < this.hiy) ? this.hiy : r.hiy);
ret.filterSpans(this, r, INCLUDE_A | INCLUDE_B | INCLUDE_COMMON);
return ret;
}
Returns a Region object that represents the union of this
object with the specified Region object.
If {@code A} and {@code B} are both Region Objects and
C = A.getUnion(B); then a point will
be contained in {@code C} iff it is contained in either
{@code A} or {@code B}.
The return value may be this same object or the argument
Region object if no augmentation occurs. |
public final int getWidth() {
if (hix < lox) return 0;
int w;
if ((w = hix - lox) < 0) {
w = Integer.MAX_VALUE;
}
return w;
}
Returns the width of this Region clipped to the range (0 - MAX_INT). |
public int hashCode() {
return (isEmpty() ? 0 : (lox * 3 + loy * 5 + hix * 7 + hiy * 9));
}
|
public boolean intersectsQuickCheck(Region r) {
return (r.hix > this.lox && r.lox < this.hix &&
r.hiy > this.loy && r.loy < this.hiy);
}
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) {
return (hix > this.lox && lox < this.hix &&
hiy > this.loy && loy < this.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() {
return (hix < = lox || hiy < = loy);
}
Returns true iff this Region encloses no area. |
public boolean isInsideQuickCheck(Region r) {
return (r.bands == null &&
r.lox < = this.lox && r.loy < = this.loy &&
r.hix >= this.hix && r.hiy >= this.hiy);
}
|
public boolean isInsideXYWH(int x,
int y,
int w,
int h) {
return isInsideXYXY(x, y, dimAdd(x, w), dimAdd(y, 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) {
return (this.lox >= lox && this.loy >= loy &&
this.hix < = hix && this.hiy < = hiy);
}
Returns true iff this Region lies inside the indicated
rectangular area specified in lox, loy, hix, hiy format. |
public boolean isRectangular() {
return (bands == null);
}
Returns true iff this Region represents a single simple
rectangular area. |
public void setOutputArea(Rectangle r) {
setOutputAreaXYWH(r.x, r.y, r.width, r.height);
}
|
public void setOutputArea(int[] box) {
this.lox = box[0];
this.loy = box[1];
this.hix = box[2];
this.hiy = box[3];
}
|
public void setOutputAreaXYWH(int x,
int y,
int w,
int h) {
setOutputAreaXYXY(x, y, dimAdd(x, w), dimAdd(y, h));
}
|
public void setOutputAreaXYXY(int lox,
int loy,
int hix,
int hiy) {
this.lox = lox;
this.loy = loy;
this.hix = hix;
this.hiy = hiy;
}
|
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("Region[[");
sb.append(lox);
sb.append(", ");
sb.append(loy);
sb.append(" = > ");
sb.append(hix);
sb.append(", ");
sb.append(hiy);
sb.append("]");
if (bands != null) {
int col = 0;
while (col < endIndex) {
sb.append("y{");
sb.append(bands[col++]);
sb.append(",");
sb.append(bands[col++]);
sb.append("}[");
int end = bands[col++];
end = col + end * 2;
while (col < end) {
sb.append("x(");
sb.append(bands[col++]);
sb.append(", ");
sb.append(bands[col++]);
sb.append(")");
}
sb.append("]");
}
}
sb.append("]");
return sb.toString();
}
|