File: `../../Developer.FoundationDotJS.org/wwwroot/Library/Foundation.Geometry.js`

## `Foundation` Class Rectangle

````Object`
Foundation.Rectangle
```

All Implemented Interfaces:

`Class`

```Foundation.Rectangle
implements `Foundation.Class````

Two dimensional rectangle class with x, y, width and height.

 Constructor Summary `Foundation.Rectangle(/*Number*/ x, /*Number*/ y, /*Number*/ width, /*Number*/ height)` Creates a rectangle from x, y, width and height values. `Foundation.Rectangle(/*Rectangle*/ rectangle)` Creates a rectangle from another rectangle.

 Field Summary `Number` `height` The height of the rectangle. `Number` `width` The width of the rectangle. `Number` `x` The x origin of the rectangle. `Number` `y` The y origin of the rectangle.

 Method Summary `[this]` `add(/*Point*/ Point)` Positively offsets the rectangle by a point. `[this]` `add(/*Number*/ x, /*Number*/ y)` Positively offsets the by x and y values. `[this]` `ceil()` Ceils the x, y, width and height values of the rectangle. `[this]` `center(/*Point*/ point)` Moves the rectangle as necessary to center it on a point. `Rectangle` `clone()` Creates a copy of the rectangle. `Point` `constrainPoint(/*Point*/ point)` Gets a point inside the rectangle that is closest to a target point. `Rectangle` `constrainRectangle(/*Rectangle*/ point)` Gets a rectangle inside the rectangle that is closest to a target rectangle. `[this]` `containPoint(/*Point*/ point)` Alters the rectangle as necessary to contain a point. `[this]` `containPolygon(/*Polygon*/ polygon)` Alters the rectangle as necessary to contain a polygon. `[this]` `containRectangle(/*Rectangle*/ rectangle)` Alters the rectangle as necessary to contain another rectangle. `Boolean` `containsPoint(/*Point*/ point)` Checks to see if a point is inside the rectangle. `Boolean` `containsXY(/*Number*/ x, /*Number*/ y)` Checks to see if an x y pair is inside the rectangle. ` ` `dispose()` `Number` `distanceToPoint(/*Point*/ point)` The distance to a point, or zero if the point is contained in the rectangle. `Boolean` `equals(/*Rectangle*/ rectangle)` Compares a rectangle with another rectangle. `Boolean` `equals(/*Number*/ x, /*Number*/ y, /*Number*/ width, /*Number*/ hheight)` Compares a rectangle with x, y, width and height values. `[this]` `floor()` Floors the x, y, width and height values of the rectangle. `Point` `getCenter()` Gets the center of the rectangle as a point. `Point` `getSize()` The size of the rectangle as a `Foundation.Point`. `[this]` `inset(/*Point*/ point)` Insets the rectangle by point values. `[this]` `inset(/*Number*/ x, /*Number*/ y)` Insets the rectangle by x and y values. `static Rectangle` `parse(/*String*/ rectangleString)` Parses a string representation of a rectangle into a new `Foundation.Rectangle`. `[this]` `resize(/*Point*/ point)` Resizes the rectangle to point values. `[this]` `resize(/*Number*/ width, /*Number*/ height)` Resizes the rectangle to width and height values. `[this]` `resizeBy(/*Point*/ point)` Resizes the rectangle by point values. `[this]` `resizeBy(/*Number*/ width, /*Number*/ height)` Resizes the rectangle by width and height values. `[this]` `rotate(/*Number*/ radians)` Rotates the rectangle by an angle. The rectangle returned is the actually the smallest rectagle that will contain the rotated rectagle. `[this]` `round()` Rounds the x, y, width and height values of the rectangle. `[this]` `scale(/*Number*/ scale)` Scales the rectangle. Both the origin and size are scaled. `[this]` `set(/*Rectangle*/ rectangle)` Sets the rectangle equal to another rectangle. `[this]` `set(/*Number*/ x, /*Number*/ y, /*Number*/ width, /*Number*/ height)` Sets the rectangle equal to x, y, width and height values. `[this]` `subtract(/*Rectangle*/ rectangle)` Negatively offsets the rectangle by another rectangle or by x,y,w,h values. `[this]` `subtract(/*Number*/ x, /*Number*/ y)` Negatively offsets the rectangle by x and y values. `String` `toString()` A string representation of the rectangle. `[this]` `transform(/*TMatrix*/ tMatrix)` Transforms the rectangle by an transformation matrix.

 Methods inherited from `Foundation.Class` `getTypePath`, `isInstanceOf`

 Constructor Detail

### Rectangle

````Foundation.Rectangle(/*````Number*/ x,
/*Number*/ y,
/*Number*/ width,
/*Number*/ height)```
```

Creates a rectangle from x, y, width and height values.

Parameters:
`x - `
X value.
`y - `
Y value.
`width - `
Width value.
`height - `
Height value.

### Rectangle

````Foundation.Rectangle(/*``Rectangle*/ rectangle)`
```

Creates a rectangle from another rectangle.

Parameters:
`rectangle - `
Rectangle to copy.

 Field Detail

### height

````Number height`
```

The height of the rectangle.

### width

````Number width`
```

The width of the rectangle.

### x

````Number x`
```

The x origin of the rectangle.

### y

````Number y`
```

The y origin of the rectangle.

 Method Detail

````[this] add(/*``Point*/ Point)`
```

Positively offsets the rectangle by a point.

Parameters:
`Point - `
Returns:
The rectangle (this) after addition.
`subtract`, `set`, `scale`

````[this] add(/*````Number*/ x,
/*Number*/ y)```
```

Positively offsets the by x and y values.

Parameters:
`x - `
X value to add by.
`y - `
Y value to add by.
Returns:
The rectangle (this) after addition.
`subtract`, `set`, `scale`

### ceil

````[this] ceil()`
```

Ceils the x, y, width and height values of the rectangle.

Returns:
The rectangle (this) after ceiling.
`floor`, `round`

### center

````[this] center(/*``Point*/ point)`
```

Moves the rectangle as necessary to center it on a point.

Parameters:
`point - `
Point on which to center.
Returns:
The rectangle (this) after moving.

### clone

````Rectangle clone()`
```

Creates a copy of the rectangle.

Returns:
A new copy of the rectangle.

### constrainPoint

````Point constrainPoint(/*Point*/ point)`
```

Gets a point inside the rectangle that is closest to a target point.

Parameters:
`point - `
The target point. This point is not altered.
Returns:
The closest point.

### constrainRectangle

````Rectangle constrainRectangle(/*Rectangle*/ point)`
```

Gets a rectangle inside the rectangle that is closest to a target rectangle.

Parameters:
`point - `
The target rectangle. This rectangle is not altered.
Returns:
The intersection of the two rectangles. If the rectangles do not intersect, the x,y will be contained within this rectagle and closest to the target, and will have a zero width and/or height.

### containPoint

````[this] containPoint(/*``Point*/ point)`
```

Alters the rectangle as necessary to contain a point.

Parameters:
`point - `
Point value to contain.
Returns:
The rectangle (this) after altering.

### containPolygon

````[this] containPolygon(/*``Polygon*/ polygon)`
```

Alters the rectangle as necessary to contain a polygon.

Parameters:
`polygon - `
Polygon value to contain.
Returns:
The rectangle (this) after altering.

### containRectangle

````[this] containRectangle(/*``Rectangle*/ rectangle)`
```

Alters the rectangle as necessary to contain another rectangle.

Parameters:
`rectangle - `
Rectangle value to contain.
Returns:
The rectangle (this) after altering.

### containsPoint

````Boolean containsPoint(/*Point*/ point)`
```

Checks to see if a point is inside the rectangle.

Parameters:
`point - `
The point to check.
Returns:
True if the point is inclusively inside the rectagle, else false.

### containsXY

``````Boolean containsXY(/*Number*/ x,
/*Number*/ y)```
```

Checks to see if an x y pair is inside the rectangle.

Parameters:
`x - `
The x value to check.
`y - `
The y value to check.
Returns:
True if the x y pair is inclusively inside the rectagle, else false.

### dispose

````dispose()`
```
Overrides:
`dispose` in class `Class`

### distanceToPoint

````Number distanceToPoint(/*Point*/ point)`
```

The distance to a point, or zero if the point is contained in the rectangle.

Parameters:
`point - `
The target point.
Returns:
The distance to the point.

### equals

````Boolean equals(/*Rectangle*/ rectangle)`
```

Compares a rectangle with another rectangle.

Parameters:
`rectangle - `
Other rectangle to compare to.
Returns:
True if the rectangles equal, else false.

### equals

``````Boolean equals(/*Number*/ x,
/*Number*/ y,
/*Number*/ width,
/*Number*/ hheight)```
```

Compares a rectangle with x, y, width and height values.

Parameters:
`x - `
X value to compare to.
`y - `
Y value to compare to.
`width - `
Width value to compare to.
`hheight - `
Height value to compare to.
Returns:
True if the rectangle equals the x, y, width and height values, else false.

### floor

````[this] floor()`
```

Floors the x, y, width and height values of the rectangle.

Returns:
The rectangle (this) after flooring.
`round`, `ceil`

### getCenter

````Point getCenter()`
```

Gets the center of the rectangle as a point.

Returns:
The center.

### getSize

````Point getSize()`
```

The size of the rectangle as a `Foundation.Point`.

Returns:
The size of the rectangle.

### inset

````[this] inset(/*``Point*/ point)`
```

Insets the rectangle by point values.

Parameters:
`point - `
Point value to inset by.
Returns:
The rectangle (this) after inseting.

### inset

````[this] inset(/*````Number*/ x,
/*Number*/ y)```
```

Insets the rectangle by x and y values.

Parameters:
`x - `
X value to inset by.
`y - `
Y value to inset by.
Returns:
The rectangle (this) after inseting.

### parse

````static ``Rectangle parse(/*String*/ rectangleString)`
```

Parses a string representation of a rectangle into a new `Foundation.Rectangle`.

Parameters:
`rectangleString - `
The string representation of the rectangle.
Returns:
The new rectangle.
`toString`

### resize

````[this] resize(/*``Point*/ point)`
```

Resizes the rectangle to point values.

Parameters:
`point - `
Point values to resize to.
Returns:
The rectangle (this) after resizing.
`resizeBy`

### resize

````[this] resize(/*````Number*/ width,
/*Number*/ height)```
```

Resizes the rectangle to width and height values.

Parameters:
`width - `
Width value to resize to.
`height - `
Height value to resize to.
Returns:
The rectangle (this) after resizing.
`resizeBy`

### resizeBy

````[this] resizeBy(/*``Point*/ point)`
```

Resizes the rectangle by point values.

Parameters:
`point - `
Point values to resize by.
Returns:
The rectangle (this) after resizing.
`resize`

### resizeBy

````[this] resizeBy(/*````Number*/ width,
/*Number*/ height)```
```

Resizes the rectangle by width and height values.

Parameters:
`width - `
Width value to resize by.
`height - `
Height value to resize by.
Returns:
The rectangle (this) after resizing.
`resize`

### rotate

````[this] rotate(/*``Number*/ radians)`
```

Rotates the rectangle by an angle. The rectangle returned is the actually the smallest rectagle that will contain the rotated rectagle.

Parameters:
`radians - `
The angle (in radians) to rotate the rectangle by.
Returns:
The rectangle (this) after rotating.

### round

````[this] round()`
```

Rounds the x, y, width and height values of the rectangle.

Returns:
The rectangle (this) after rounding.
`floor`, `ceil`

### scale

````[this] scale(/*``Number*/ scale)`
```

Scales the rectangle. Both the origin and size are scaled.

Parameters:
`scale - `
The number to scale by.
Returns:
The rectangle (this) after scaling.
`add`, `subtract`, `set`

### set

````[this] set(/*``Rectangle*/ rectangle)`
```

Sets the rectangle equal to another rectangle.

Parameters:
`rectangle - `
Other rectangle to set by.
Returns:
The rectangle (this) after setting.
`add`, `subtract`, `scale`

### set

````[this] set(/*````Number*/ x,
/*Number*/ y,
/*Number*/ width,
/*Number*/ height)```
```

Sets the rectangle equal to x, y, width and height values.

Parameters:
`x - `
X value to set by.
`y - `
Y value to set by.
`width - `
Width value to set by.
`height - `
Height value to set by.
Returns:
The rectangle (this) after setting.
`add`, `subtract`, `scale`

### subtract

````[this] subtract(/*``Rectangle*/ rectangle)`
```

Negatively offsets the rectangle by another rectangle or by x,y,w,h values.

Parameters:
`rectangle - `
Other rectangle subtract by.
Returns:
The rectangle (this) after subtraction.
`add`, `set`, `scale`

### subtract

````[this] subtract(/*````Number*/ x,
/*Number*/ y)```
```

Negatively offsets the rectangle by x and y values.

Parameters:
`x - `
X value to subtract by.
`y - `
Y value to subtract by.
Returns:
The rectangle (this) after subtraction.
`add`, `set`, `scale`

### toString

````String toString()`
```

A string representation of the rectangle.

Overrides:
`toString` in class `Class`
Returns:
The rectangle as a '[x,y,w,h]' string.
`parse`

### transform

````[this] transform(/*``TMatrix*/ tMatrix)`
```

Transforms the rectangle by an transformation matrix.

Parameters:
`tMatrix - `
The transformation matrix.
Returns:
The rectangle (this) after transforming.