# Rect

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/struct-rect/

**struct** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
struct Rect
```

Defines a rectangle.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L14)

## Members

- [`x`](#struct_field-x)
- [`y`](#struct_field-y)
- [`width`](#struct_field-width)
- [`height`](#struct_field-height)
- [`new`](#function-new)
- [`from_size`](#function-from_size)
- [`from_position_size`](#function-from_position_size)
- [`from_points`](#function-from_points)
- [`position`](#function-position)
- [`size`](#function-size)
- [`right`](#function-right)
- [`bottom`](#function-bottom)
- [`left`](#function-left)
- [`top`](#function-top)
- [`top_left`](#function-top_left)
- [`top_right`](#function-top_right)
- [`bottom_left`](#function-bottom_left)
- [`bottom_right`](#function-bottom_right)
- [`center`](#function-center)
- [`contains`](#function-contains)
- [`contains_exclusive`](#function-contains_exclusive)
- [`contains_rect`](#function-contains_rect)
- [`center_rect`](#function-center_rect)
- [`inflate`](#function-inflate)
- [`inflate_thickness`](#function-inflate_thickness)
- [`deflate`](#function-deflate)
- [`deflate_thickness`](#function-deflate_thickness)
- [`equals`](#function-equals)
- [`intersect`](#function-intersect)
- [`intersects`](#function-intersects)
- [`transform_to_aabb`](#function-transform_to_aabb)
- [`translate`](#function-translate)
- [`normalize`](#function-normalize)
- [`union`](#function-union)
- [`union_optional`](#function-union_optional)
- [`with_x`](#function-with_x)
- [`with_y`](#function-with_y)
- [`with_width`](#function-with_width)
- [`with_height`](#function-with_height)
- [`parse`](#function-parse)
- [`is_empty`](#function-is_empty)

<a id="struct_field-x"></a>

### x

```rust
x: f64
```

The X position.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L16)

<a id="struct_field-y"></a>

### y

```rust
y: f64
```

The Y position.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L18)

<a id="struct_field-width"></a>

### width

```rust
width: f64
```

The width.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L20)

<a id="struct_field-height"></a>

### height

```rust
height: f64
```

The height.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L22)

<a id="function-new"></a>

### new

```rust
const fn new(x: f64, y: f64, width: f64, height: f64) -> Self
```

Initializes a new instance of the `Rect` structure.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L28)

<a id="function-from_size"></a>

### from_size

```rust
const fn from_size(size: Size) -> Self
```

Initializes a `Rect` at the origin with the given size.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L39)

<a id="function-from_position_size"></a>

### from_position_size

```rust
const fn from_position_size(position: Point, size: Size) -> Self
```

Initializes a `Rect` from its position and size.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L45)

<a id="function-from_points"></a>

### from_points

```rust
fn from_points(top_left: Point, bottom_right: Point) -> Self
```

Initializes a `Rect` from its top left and bottom right corners.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L51)

<a id="function-position"></a>

### position

```rust
const fn position(self: &Self) -> Point
```

Gets the position of the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L62)

<a id="function-size"></a>

### size

```rust
const fn size(self: &Self) -> Size
```

Gets the size of the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L68)

<a id="function-right"></a>

### right

```rust
fn right(self: &Self) -> f64
```

Gets the right position of the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L74)

<a id="function-bottom"></a>

### bottom

```rust
fn bottom(self: &Self) -> f64
```

Gets the bottom position of the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L80)

<a id="function-left"></a>

### left

```rust
const fn left(self: &Self) -> f64
```

Gets the left position.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L86)

<a id="function-top"></a>

### top

```rust
const fn top(self: &Self) -> f64
```

Gets the top position.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L92)

<a id="function-top_left"></a>

### top_left

```rust
const fn top_left(self: &Self) -> Point
```

Gets the top left point of the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L98)

<a id="function-top_right"></a>

### top_right

```rust
fn top_right(self: &Self) -> Point
```

Gets the top right point of the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L104)

<a id="function-bottom_left"></a>

### bottom_left

```rust
fn bottom_left(self: &Self) -> Point
```

Gets the bottom left point of the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L110)

<a id="function-bottom_right"></a>

### bottom_right

```rust
fn bottom_right(self: &Self) -> Point
```

Gets the bottom right point of the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L116)

<a id="function-center"></a>

### center

```rust
fn center(self: &Self) -> Point
```

Gets the center point of the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L122)

<a id="function-contains"></a>

### contains

```rust
fn contains(self: &Self, p: Point) -> bool
```

Determines whether a point is in the bounds of the rectangle (edges inclusive).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L128)

<a id="function-contains_exclusive"></a>

### contains_exclusive

```rust
fn contains_exclusive(self: &Self, p: Point) -> bool
```

Determines whether a point is in the bounds of the rectangle, exclusive of
the rectangle's bottom/right edge.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L135)

<a id="function-contains_rect"></a>

### contains_rect

```rust
fn contains_rect(self: &Self, r: Rect) -> bool
```

Determines whether the rectangle fully contains another rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L141)

<a id="function-center_rect"></a>

### center_rect

```rust
fn center_rect(self: &Self, rect: Rect) -> Rect
```

Centers another rectangle in this rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L147)

<a id="function-inflate"></a>

### inflate

```rust
fn inflate(self: &Self, thickness: f64) -> Rect
```

Inflates the rectangle by the same amount on every side.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L158)

<a id="function-inflate_thickness"></a>

### inflate_thickness

```rust
fn inflate_thickness(self: &Self, thickness: Thickness) -> Rect
```

Inflates the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L164)

<a id="function-deflate"></a>

### deflate

```rust
fn deflate(self: &Self, thickness: f64) -> Rect
```

Deflates the rectangle by the same amount on every side.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L173)

<a id="function-deflate_thickness"></a>

### deflate_thickness

```rust
fn deflate_thickness(self: &Self, thickness: Thickness) -> Rect
```

Deflates the rectangle by a `Thickness`. The deflated rectangle size
cannot be less than 0.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L180)

<a id="function-equals"></a>

### equals

```rust
fn equals(self: &Self, other: Rect) -> bool
```

Returns a boolean indicating whether the rect is equal to the other given
rect (exact comparison).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L190)

<a id="function-intersect"></a>

### intersect

```rust
fn intersect(self: &Self, rect: Rect) -> Rect
```

Gets the intersection of two rectangles, or an empty (default) rectangle
if they do not overlap.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L199)

<a id="function-intersects"></a>

### intersects

```rust
fn intersects(self: &Self, rect: Rect) -> bool
```

Determines whether a rectangle intersects with this rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L227)

<a id="function-transform_to_aabb"></a>

### transform_to_aabb

```rust
fn transform_to_aabb(self: &Self, matrix: Matrix) -> Rect
```

Returns the axis-aligned bounding box of a transformed rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L235)

<a id="function-translate"></a>

### translate

```rust
fn translate(self: &Self, offset: Vector) -> Rect
```

Translates the rectangle by an offset.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L268)

<a id="function-normalize"></a>

### normalize

```rust
fn normalize(self: &Self) -> Rect
```

Normalizes the rectangle so both the width and height are positive, without
changing its location: positive-size rects are returned unchanged, negative
sizes are flipped. A rect with any NaN edge becomes the default rect.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L275)

<a id="function-union"></a>

### union

```rust
fn union(self: &Self, rect: Rect) -> Rect
```

Gets the union of two rectangles. A rectangle whose width and height are
both zero is ignored.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L307)

<a id="function-union_optional"></a>

### union_optional

```rust
fn union_optional(left: Option<Rect>, right: Option<Rect>) -> Option<Rect>
```

Union of two optional rectangles; a missing side yields the other side.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L324)

<a id="function-with_x"></a>

### with_x

```rust
const fn with_x(self: &Self, x: f64) -> Rect
```

Returns a new `Rect` with the specified X position.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L334)

<a id="function-with_y"></a>

### with_y

```rust
const fn with_y(self: &Self, y: f64) -> Rect
```

Returns a new `Rect` with the specified Y position.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L340)

<a id="function-with_width"></a>

### with_width

```rust
const fn with_width(self: &Self, width: f64) -> Rect
```

Returns a new `Rect` with the specified width.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L346)

<a id="function-with_height"></a>

### with_height

```rust
const fn with_height(self: &Self, height: f64) -> Rect
```

Returns a new `Rect` with the specified height.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L352)

<a id="function-parse"></a>

### parse

```rust
fn parse(s: &str) -> Result<Self, FormatError>
```

Parses a `Rect` string (`"x, y, width, height"`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L357)

<a id="function-is_empty"></a>

### is_empty

```rust
fn is_empty(self: &Self) -> bool
```

This method should be used internally to check for the rect emptiness.
Once a dedicated "empty" value exists this is the single place to update.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/rect.rs#L371)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`PropertyValue`](/docs/0.5.0/api/ferroui-base/trait-propertyvalue/)
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `ToString`
- `ErasedDestructor`
- `IntoEither`
- `From<Rect>`
- `BatchValue`
- [`MarkupTyped`](/docs/0.5.0/api/ferroui-base/metadata/trait-markuptyped/)
- [`ValueTypeRegistration`](/docs/0.5.0/api/ferroui-base/data/core/trait-valuetyperegistration/)
- `Clone`
- `Copy`
- `Debug`
- `StructuralPartialEq`
- `PartialEq`
- `Default`
- `Mul<Vector>`
- `Mul<f64>`
- `Div<Vector>`
- `MulAssign<Vector>`
- `MulAssign<f64>`
- `DivAssign<Vector>`
- `FromStr`
- `Display`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
