Code example for RectF

Methods: contains, height, width

0
     
    /** 
     * {@inheritDoc}  
     */ 
    public boolean contains(float x, float y, float width, float height) {
        return mRect.contains((int)x, (int)y, (int) (x + width), (int) (y + height));
    } 
     
    /** 
     * {@inheritDoc}  
     */ 
    public boolean contains(PointF point) {
        return mRect.contains(point.x, point.y);
    } 
 
     
    /** 
     * {@inheritDoc}  
     */ 
    @Deprecated 
    public RectShape getBounds() { 
        return this;
    } 
     
     
    /** 
     * {@inheritDoc}  
     */ 
    public void getBounds(RectShape rect) {
        rect.setRect(this);
    } 
 
     
    /** 
     * {@inheritDoc}  
     */ 
    public boolean intersects(float x, float y, float width, float height) {
    	return mRect.intersects(x, y, x+width, y+height);
    } 
 
     
    /** 
     * {@inheritDoc}  
     */ 
    public boolean intersects(Rect rect) {
        return intersects(rect.left, rect.top, Math.abs(rect.right - rect.left), Math.abs(rect.bottom - rect.top));
    } 
 
     
    /** 
     * {@inheritDoc}  
     */ 
    public boolean intersects(RectShape rect) {
        return intersects(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
    } 
     
    /** 
     * Returns true if specified line intersects with the shape. 
     * @param x1 The x-coordinate of line starting point 
     * @param y1 The y-coordinate of line starting point 
     * @param x2 The x-coordinate of line ending point 
     * @param y2 The y-coordinate of line ending point 
     * @return If specified line intersects with the shape, return true 
     */ 
    public boolean intersectsLine(float x1, float y1, float x2, float y2) {
        return intersectsLine(new LineShape(x1, y1, x2, y2));
    } 
     
    /** 
     * Returns true if specified line intersects with the shape. 
     * @param line specified line 
     * @return If specified line intersects with the shape, return true 
     */ 
    public boolean intersectsLine(LineShape line) {
        if (line.intersectsLine(getMinX(), getMinY(), getMaxX(), getMinY())) return true;
        if (line.intersectsLine(getMinX(), getMinY(), getMinX(), getMaxY())) return true;
        if (line.intersectsLine(getMaxX(), getMinY(), getMaxX(), getMaxY())) return true;
        if (line.intersectsLine(getMinX(), getMaxY(), getMaxX(), getMaxY())) return true;
        if (contains(line.getX1(), line.getY1()) || contains(line.getX2(), line.getY2())) return true;
         
        return false; 
    } 
     
    /** 
     * Returns new rectangle representing the union of this rectangle with the specified rectangle. 
     * @param rect The specified rectangle 
     * @return The smallest rectangle containing both the specified rectangle and this rectangle. 
     */ 
    public RectShape createUnion(RectShape rect) {
        float l, t, r, b;
        l = this.getX() < rect.getX() ? this.getX() : rect.getX();
        t = this.getY() < rect.getY() ? this.getY() : rect.getY();
        r = this.getX() + this.getWidth() < rect.getX() + rect.getWidth() ? rect.getX() + rect.getWidth() : this.getX() + this.getWidth();
        b = this.getY() + this.getHeight() < rect.getY() + rect.getHeight() ? rect.getY() + rect.getHeight() : this.getY() + this.getHeight();
         
        return new RectShape( l, t, r - l, b - t );
    } 
 
    /** 
     * Returns true If this rect is empty. 
     * @return If this rect is empty, true 
     */ 
    public boolean isEmpty() { 
        return (getWidth() <= 0.0f) || (getHeight() <= 0.0f); 
    } 
     
    /** 
     * {@inheritDoc}  
     */ 
    public void translate(float x, float y) {
        this.mRect.left += x;
        this.mRect.top += y;
        this.mRect.right += x;
        this.mRect.bottom += y;
    } 
     
    /** 
     * Sets the rectangle shape from specified float coordinates. 
     * @param x The x-coordinate of upper-left corner 
     * @param y The y-coordinate of upper-left corner 
     * @param width The width of rectangle 
     * @param height The height of rectangle 
     */ 
    public void setRect(float x, float y, float width, float height) {
        this.mRect.left = x;
        this.mRect.top = y;
        this.mRect.right = x + width;
        this.mRect.bottom = y + height;
    } 
     
    /** 
     * Sets the rectangle shape from specified double coordinates. 
     * @param x The x-coordinate of upper-left corner 
     * @param y The y-coordinate of upper-left corner 
     * @param width The width of rectangle 
     * @param height The height of rectangle 
     */ 
    public void setRect(double x, double y, double width, double height) {
        this.mRect.left = (float)x;
        this.mRect.top = (float)y;
        this.mRect.right = (float)(x + width);
        this.mRect.bottom = (float)(y + height);
    } 
     
    /** 
     * Sets the rectangle shape representing specified rectangle. 
     * @param rect specified rectangle 
     */ 
    public void setRect(RectShape rect) {
        this.mRect.left = rect.getX();
        this.mRect.top = rect.getY();
        this.mRect.right = rect.getMaxX();
        this.mRect.bottom = rect.getMaxY();
    } 
     
    /** 
     * Sets the rectangle shape representing specified Rect. 
     * @param rect specified rectangle 
     */ 
    public void setRect(Rect rect) {
        this.mRect.set(rect);
    } 
     
    /** 
     * Sets the rectangle shape representing specified rectangle. 
     * @param rect specified rectangle 
     */ 
    public void setRectF(RectF rectF) {
        this.mRect.set(rectF);
    } 
     
    /** 
     * Returns new rectangle representing this rectangle. 
     * @return new rectangle representing this rectangle 
     */ 
    public RectF getRectF() {
        return new RectF(getMinX(), getMinY(), getMaxX(), getMaxY());
    } 
     
    /** 
     * Returns this x-coordinate. 
     * @return this x-coordinate 
     */ 
    public float getX() { 
        return mRect.left;
    } 
     
    /** 
     * Sets the x-coordinate from specified x-coordinate. 
     * @param x The specified x-coordinate 
     */ 
    public void setX(float x) {
        this.mRect.left = x;
    } 
 
    /** 
     * Returns this y-coordinate. 
     * @return this y-coordinate 
     */ 
    public float getY() { 
        return mRect.top;
    } 
 
    /** 
     * Sets the y-coordinate from specified y-coordinate. 
     * @param y The specified y-coordinate 
     */ 
    public void setY(float y) {
        this.mRect.top = y;
    } 
 
    /** 
     * Returns this width. 
     * @return this width 
     */ 
    public float getWidth() { 
        return mRect.width();
    } 
 
    /** 
     * Sets the width from specified width. 
     * @param width The specified width 
     */ 
    public void setWidth(float width) {
        this.mRect.right = getMinX() + width;
    } 
 
    /** 
     * Returns this height. 
     * @return this height 
     */ 
    public float getHeight() { 
        return mRect.height();
    } 
     
    /** 
     * Sets the height from specified height. 
     * @param height The specified height