1255 lines · 42.3 KB · Java
RawDownload
    }     /**     * Returns true iff this Region contains the specified coordinate.     */    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 lies inside the indicated     * rectangular area specified in x, y, width, height format     * with appropriate clipping performed as per the dimAdd method.     */    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 lox, loy, hix, hiy format.     */    public boolean isInsideXYXY(int lox, int loy, int hix, int hiy) {        return (this.lox >= lox && this.loy >= loy &&                this.hix <= hix && this.hiy <= hiy);     }     /**     * Quickly checks if this Region lies inside the specified     * Region object.     * <p>     * This method will return false if the specified Region     * object is not a simple rectangle.     */    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);    }     /**     * Quickly checks if this Region intersects the specified     * rectangular area specified in lox, loy, hix, hiy format.     * <p>     * 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     * Region object.     * <p>     * 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 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 surrounds the specified     * Region object.     * <p>     * This method will return false if this Region object is     * not a simple rectangle.     */    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);    }     /**     * Quickly checks if this Region surrounds the specified     * rectangular area specified in x, y, width, height format.     * <p>     * 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) {        return encompassesXYXY(x, y, dimAdd(x, w), dimAdd(y, h));    }     /**     * Quickly checks if this Region surrounds the specified     * rectangular area specified in lox, loy, hix, hiy format.     * <p>     * 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) {        return (this.bands == null &&                this.lox <= lox && this.loy <= loy &&                this.hix >= hix && this.hiy >= hiy);    }     /**     * Gets the bbox of the available spans, clipped to the OutputArea.     */    public void getBounds(int pathbox[]) {        pathbox[0] = lox;        pathbox[1] = loy;        pathbox[2] = hix;        pathbox[3] = hiy;    }     /**     * Clips the indicated bbox array to the bounds of this Region.     */    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;    }     /**     * Gets an iterator object to iterate over the spans in this region.     */    public RegionIterator getIterator() {        return new RegionIterator(this);    }     /**     * Gets a span iterator object that iterates over the spans in this region     */    public SpanIterator getSpanIterator() {        return new RegionSpanIterator(this);    }     /**     * 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 SpanIterator getSpanIterator(int bbox[]) {        SpanIterator result = getSpanIterator();        result.intersectClipBox(bbox[0], bbox[1], bbox[2], bbox[3]);        return result;    }     /**     * Returns a SpanIterator that is the argument iterator filtered by     * this region.     */    public SpanIterator filter(SpanIterator si) {        if (bands == null) {            si.intersectClipBox(lox, loy, hix, hiy);        } else {            si = new RegionClipSpanIterator(this, si);        }        return si;    }     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();    }     public int hashCode() {        return (isEmpty() ? 0 : (lox * 3 + loy * 5 + hix * 7 + hiy * 9));    }     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.hix != this.hix || 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;    }}

Lines 1001–1255 of 1255. Previous lines