# Rect class finalGrids

An immutable 2D fixed-point rectangle.

Note

It is valid to have any integer value for any of the edges.

It is up to its consumers to ensure that the rectangle is valid for their use case. For example, right can be less than left, or bottom can be negative.

## Equality

A rectangle is defined by its left, top, right, and bottom edges.

## Example

Creating a rectangle:

final rect = Rect.fromLTRB(0, 0, 10, 10);

Using pattern matching to extract multiple values in one statement:

final Rect(:left, :top, :right, :bottom) = rect;
Annotations
• @immutable

## Constructors

Rect.encloses(Pos a, Pos b)
Creates the smallest rectangle that encloses the two provided positions.
factory
Rect.fromLTRB(int left, int top, int right, int bottom)
Creates a rectangle from its left, top, right, and bottom edges.
const
Rect.fromLTWH(int left, int top, int width, int height)
Creates a rectangle from its left and top edges, and its width and height.
const
Rect.fromTLBR(Pos topLeft, Pos bottomRight)
Creates a rectangle from its top-left and bottom-right corners.
Rect.fromWH(int width, int height, {Pos offset = Pos.zero})
Creates an origin-based rectangle from its width and height.

## Properties

area int
The area of the rectangle.
no setter
bottom int
The bottom, or y-coordinate of the bottom edge.
final
bottomLeft Pos
The bottom-left corner of the rectangle.
no setter
bottomRight Pos
The bottom-right corner of the rectangle.
no setter
center List<Pos>
Returns the center positions of the rectangle.
no setter
columns Iterable<Rect>
Returns a rectangle for each column in the rectangle.
no setter
edges Iterable<Pos>
Returns the positions of the edges of the rectangle.
no setter
hashCode int
The hash code for this object.
no setteroverride
height int
The height of the rectangle.
no setter
isEmpty bool
Returns whether the rectangle is empty.
no setter
isNotEmpty bool
Returns whether the rectangle is not empty.
no setter
left int
The left, or x-coordinate of the left edge.
final
longestSide int
The longest side of the rectangle.
no setter
positions Iterable<Pos>
Returns the positions of the rectangle.
no setter
The right, or x-coordinate of the right edge.
final
rows Iterable<Rect>
Returns a rectangle for each row in the rectangle.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shortestSide int
The shortest side of the rectangle.
no setter
size Pos
A position where Pos.x si width and Pos.y is height.
no setter
top int
The top, or y-coordinate of the top edge.
final
topLeft Pos
The top-left corner of the rectangle.
no setter
topRight Pos
The top-right corner of the rectangle.
no setter
width int
The width of the rectangle.
no setter

## Methods

contains(Pos position) bool
Returns whether the provided position is within the rectangle.
containsRect(Rect other) bool
Returns whether the provided rectangle is within this rectangle.
deflate(int delta) Rect
Returns a new rectangle with edges moved inwards by the provided delta.
inflate(int delta) Rect
Returns a new rectangle with edges moved outwards by the provided delta.
intersect(Rect other) Rect
Returns the intersection of this rectangle and the provided rectangle.
normalize() Rect
Returns a normalized rectangle where left <= right and top <= bottom.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
overlaps(Rect other) bool
Returns whether the provided rectangle overlaps this rectangle.
toString()
A string representation of this object.
override
translate(Pos offset) Rect
Returns a new rectangle translated by the provided position as an offset.

## Operators

operator ==(Object other) bool
The equality operator.
override

## Constants

byArea → const Comparator<Rect>
A comparator that sorts rectangle by their area.
zero → const Rect
A rectangle with all edges at 0.