fit(rectangle)
    {
        if (this.x < rectangle.x)
        {
            this.width += this.x;

            if (this.width < 0) this.width = 0;

            this.x = rectangle.x;
        }

        if (this.y < rectangle.y)
        {
            this.height += this.y;

            if (this.height < 0) this.height = 0;

            this.y = rectangle.y;
        }

        if (this.x + this.width > rectangle.x + rectangle.width)
        {
            this.width = rectangle.width - this.x;

            if (this.width < 0) this.width = 0;
        }

        if (this.y + this.height > rectangle.y + rectangle.height)
        {
            this.height = rectangle.height - this.y;

            if (this.height < 0) this.height = 0;
        }

        return this;
    }
/**
     * Manipulates this rectangle so that becomes the same size as the passed rectangle.
     * The big difference between this method and just copying the values of the other
     * rectangle is that this ensures that the width/height never goes below 0.
     *
     * @param {Rectangle} rectangle - The rectangle to grow to encompass.
     * @return {Rectangle} returns itself.
     */
Manipulates this rectangle so that becomes the same size as the passed rectangle.
The big difference between this method and just copying the values of the other
rectangle is that this ensures that the width/height never goes below 0.

@param {Rectangle} rectangle - The rectangle to grow to encompass.
@return {Rectangle} returns itself.
Manipulates this rectangle so that becomes the same size as the passed rectangle . The big difference between this method and just copying the values of the other rectangle is that this ensures that the width / height never goes below 0 . @param { Rectangle } rectangle - The rectangle to grow to encompass . @return { Rectangle } returns itself .
fit(rectangle)
    {
        if (this.x < rectangle.x)
        {
            this.width += this.x;
            if (this.width < 0) this.width = 0;
            this.x = rectangle.x;
        }
        if (this.y < rectangle.y)
        {
            this.height += this.y;
            if (this.height < 0) this.height = 0;
            this.y = rectangle.y;
        }
        if (this.x + this.width > rectangle.x + rectangle.width)
        {
            this.width = rectangle.width - this.x;
            if (this.width < 0) this.width = 0;
        }
        if (this.y + this.height > rectangle.y + rectangle.height)
        {
            this.height = rectangle.height - this.y;
            if (this.height < 0) this.height = 0;
        }
        return this;
    }
fit ( rectangle ) { if ( this . x < rectangle . x ) { this . width += this . x ; if ( this . width < 0 ) this . width = 0 ; this . x = rectangle . x ; } if ( this . y < rectangle . y ) { this . height += this . y ; if ( this . height < 0 ) this . height = 0 ; this . y = rectangle . y ; } if ( this . x + this . width > rectangle . x + rectangle . width ) { this . width = rectangle . width - this . x ; if ( this . width < 0 ) this . width = 0 ; } if ( this . y + this . height > rectangle . y + rectangle . height ) { this . height = rectangle . height - this . y ; if ( this . height < 0 ) this . height = 0 ; } return this ; }
Manipulates this rectangle so that becomes the same size as the passed rectangle.
Manipulates this rectangle so that becomes the same size as the passed rectangle .