Region.java revision 2362
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * This code is free software; you can redistribute it and/or modify it
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * under the terms of the GNU General Public License version 2 only, as
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * published by the Free Software Foundation. Oracle designates this
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * particular file as subject to the "Classpath" exception as provided
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * by Oracle in the LICENSE file that accompanied this code.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * This code is distributed in the hope that it will be useful, but WITHOUT
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * version 2 for more details (a copy is included in the LICENSE file that
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * accompanied this code).
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * You should have received a copy of the GNU General Public License version
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * 2 along with this work; if not, write to the Free Software Foundation,
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * or visit www.oracle.com if you need additional information or have any
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * questions.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * This class encapsulates a definition of a two dimensional region which
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * consists of a number of Y ranges each containing multiple X bands.
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * A rectangular Region is allowed to have a null band list in which
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * case the rectangular shape is defined by the bounding box parameters
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * (lox, loy, hix, hiy).
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * The band list, if present, consists of a list of rows in ascending Y
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * order, ending at endIndex which is the index beyond the end of the
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * last row. Each row consists of at least 3 + 2n entries (n >= 1)
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * where the first 3 entries specify the Y range as start, end, and
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * the number of X ranges in that Y range. These 3 entries are
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * followed by pairs of X coordinates in ascending order:
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * bands[rowstart+0] = Y0; // starting Y coordinate
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * bands[rowstart+1] = Y1; // ending Y coordinate - endY > startY
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * bands[rowstart+2] = N; // number of X bands - N >= 1
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * bands[rowstart+3] = X10; // starting X coordinate of first band
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * bands[rowstart+4] = X11; // ending X coordinate of first band
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * bands[rowstart+5] = X20; // starting X coordinate of second band
faaa489e1cc905efd364e01fe09111173c95db68jeff.schenk * bands[rowstart+6] = X21; // ending X coordinate of second band
public class Region {
public void setOutputAreaXYWH(int x, int y, int w, int h) {}
int lox;
int loy;
int hix;
int hiy;
int endIndex;
int[] bands;
private static native void initIDs();
initIDs();
return dim;
return newv;
if (s instanceof RectangularShape &&
return EMPTY_REGION;
public void setOutputAreaXYWH(int x, int y, int w, int h) {
calcBBox();
int ncol;
while (i < end) {
return ret;
int ncol;
while (i < end) {
int savej = j;
if (j > savej) {
return ret;
return ret;
if (this.isInsideQuickCheck(r)) {
if (r.isInsideQuickCheck(this)) {
return ret;
return ret;
if (!r.intersectsQuickCheck(this)) {
if (this.isInsideQuickCheck(r)) {
return EMPTY_REGION;
return ret;
if (r.isEmpty()) {
if (this.isEmpty()) {
return ret;
int y = loy;
while (y < hiy) {
if (y >= ay2) {
if (y >= by2) {
int yend;
if (y < by1) {
if (y < ay1) {
} else if (y < ay1) {
while (x < hix) {
if (x >= ax2) {
if (x >= bx2) {
int xend;
boolean appendit;
if (x < bx1) {
if (x < ax1) {
appendit = false;
} else if (x < ax1) {
if (appendit) {
x = xend;
y = yend;
calcBBox();
if (this.encompasses(r)) {
if (r.encompasses(this)) {
num--;
private void calcBBox() {
while (i < endIndex) {
hiyindex = i;
public final int getLoX() {
return lox;
public final int getLoY() {
return loy;
public final int getHiX() {
return hix;
public final int getHiY() {
return hiy;
public final int getWidth() {
public final int getHeight() {
public boolean isEmpty() {
public boolean isRectangular() {
public boolean contains(int x, int y) {
while (i < endIndex) {
if (y < bands[i++]) {
if (y >= bands[i++]) {
while (i < end) {
if (x < bands[i++]) return false;
if (x < bands[i++]) return true;
public boolean isInsideXYWH(int x, int y, int w, int h) {
public boolean encompassesXYWH(int x, int y, int w, int h) {
return new RegionIterator(this);
return new RegionSpanIterator(this);
return result;
return si;
public int hashCode() {
if (!(o instanceof Region)) {
if (this.isEmpty()) {
return r.isEmpty();
} else if (r.isEmpty()) {