Rect class

A two-dimensional immutable rectangle with integer coordinates.

Many operations treat a Rect as a collection of discrete points. In those cases, the boundaries of the rect are two half-open intervals when determining which points are inside the rect. For example, consider the rect whose coordinates are (-1, 1)-(3, 4):

 -2 -1  0  1  2  3  4
  |  |  |  |  |  |  |
0-
1-   +-----------+
2-   |           |
3-   |           |
4-   +-----------+
5-

It contains all points within that region except for the ones that lie directly on the right and bottom edges. (It's always right and bottom, even if the rectangle has negative coordinates.) In the above examples, that's these points:

 -2 -1  0  1  2  3  4
  |  |  |  |  |  |  |
0-
1-   *--*--*--*--+
2-   *  *  *  *  |
3-   *  *  *  *  |
4-   +-----------+
5-

This seems a bit odd, but does what you want in almost all respects. For example, the width of this rect, determined by subtracting the left coordinate (-1) from the right (3) is 4 and indeed it contains four columns of points.

Inheritance
Available Extensions

Constructors

Rect(int x, int y, int width, int height)
Rect.column(int x, int y, int size)
Creates a new rectangle a single column in width, as tall as size, with its top left corner at pos.
Rect.leftTopRightBottom(int left, int top, int right, int bottom)
Rect.posAndSize(Vec pos, Vec size)
const
Rect.row(int x, int y, int size)
Creates a new rectangle a single row in height, as wide as size, with its top left corner at pos.

Properties

area int
no setter
bottom int
no setter
bottomLeft Vec
no setter
bottomRight Vec
no setter
center Vec
no setter
first Vec
The first element.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
height int
no setter
isEmpty bool
Whether this collection has no elements.
no setterinherited
isNotEmpty bool
Whether this collection has at least one element.
no setterinherited
iterator RectIterator
A new Iterator that allows iterating the elements of this Iterable.
no setteroverride
last Vec
The last element.
no setterinherited
left int
no setter
length int
The number of elements in this.
no setterinherited
pos Vec
final
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
single Vec
Checks that this iterable has only one element, and returns that element.
no setterinherited
size Vec
final
top int
no setter
topLeft Vec
no setter
topRight Vec
no setter
width int
no setter
x int
no setter
y int
no setter

Methods

any(bool test(Vec element)) bool
Checks whether any element of this iterable satisfies test.
inherited
cast<R>() Iterable<R>
A view of this iterable as an iterable of R instances.
inherited
clamp(Vec vec) Vec
Returns a new Vec that is as near to vec as possible while being in bounds.
contains(Object? element) bool
Whether the collection contains an element equal to element.
override
containsRect(Rect rect) bool
distanceTo(Rect other) int
Returns the distance between this Rect and other. This is minimum length that a corridor would have to be to go from one Rect to the other. If the two Rects are adjacent, returns zero. If they overlap, returns -1.
elementAt(int index) Vec
Returns the indexth element.
inherited
every(bool test(Vec element)) bool
Checks whether every element of this iterable satisfies test.
inherited
expand<T>(Iterable<T> toElements(Vec element)) Iterable<T>
Expands each element of this Iterable into zero or more elements.
inherited
firstWhere(bool test(Vec element), {Vec orElse()?}) Vec
The first element that satisfies the given predicate test.
inherited
fold<T>(T initialValue, T combine(T previousValue, Vec element)) → T
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
inherited
followedBy(Iterable<Vec> other) Iterable<Vec>
Creates the lazy concatenation of this iterable and other.
inherited
forEach(void action(Vec element)) → void
Invokes action on each element of this iterable in iteration order.
inherited
inflate(int distance) Rect
join([String separator = ""]) String
Converts each element to a String and concatenates the strings.
inherited
lastWhere(bool test(Vec element), {Vec orElse()?}) Vec
The last element that satisfies the given predicate test.
inherited
map<T>(T toElement(Vec e)) Iterable<T>
The current elements of this iterable modified by toElement.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
offset(int x, int y) Rect
reduce(Vec combine(Vec value, Vec element)) Vec
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
inherited
singleWhere(bool test(Vec element), {Vec orElse()?}) Vec
The single element that satisfies test.
inherited
skip(int count) Iterable<Vec>
Creates an Iterable that provides all but the first count elements.
inherited
skipWhile(bool test(Vec value)) Iterable<Vec>
Creates an Iterable that skips leading elements while test is satisfied.
inherited
take(int count) Iterable<Vec>
Creates a lazy iterable of the count first elements of this iterable.
inherited
takeWhile(bool test(Vec value)) Iterable<Vec>
Creates a lazy iterable of the leading elements satisfying test.
inherited
toList({bool growable = true}) List<Vec>
Creates a List containing the elements of this Iterable.
inherited
toSet() Set<Vec>
Creates a Set containing the same elements as this iterable.
inherited
toString() String
Returns a string representation of (some of) the elements of this.
override
trace() Iterable<Vec>
Iterates over the points along the edge of the Rect.
where(bool test(Vec element)) Iterable<Vec>
Creates a new lazy Iterable with all elements that satisfy the predicate test.
inherited
whereType<T>() Iterable<T>
Creates a new lazy Iterable with all elements that have type T.
inherited

Operators

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

Static Methods

centerIn(Rect toCenter, Rect main) Rect
intersect(Rect a, Rect b) Rect
Creates a new rectangle that is the intersection of a and b.

Constants

empty → const Rect
Gets the empty rectangle.