Rectangle class

An axis-aligned rectangle.

This is similar to ui Rect, except that this class is mutable and conforms to the Shape API.

Unlike with Rect, the Rectangle is always correctly oriented, in the sense that its left edge is to the left from the right edge, and its top edge is above the bottom edge.

The edges of a Rectangle can also coincide: the left edge can coincide with the right edge, and the top side with the bottom.

Inheritance

Constructors

Rectangle.fromCenter({required Vector2 center, required Vector2 size})
Constructs a Rectangle from a center point and a size.
factory
Rectangle.fromLTRB(double _left, double _top, double _right, double _bottom)
Constructs the Rectangle from left, top, right and bottom edges.
Rectangle.fromLTWH(double left, double top, double width, double height)
Rectangle.fromPoints(Vector2 a, Vector2 b)
Constructs a Rectangle from two opposite corners. The points can be in any disposition to each other.
factory
Rectangle.fromRect(Rect rect)
Constructs a Rectangle from a Rect.
factory

Properties

aabb Aabb2
The axis-aligned bounding box of the shape.
no setteroverride
area double
no setter
bottom double
no setter
bottomEdge LineSegment
no setter
bottomLeft Vector2
no setter
bottomRight Vector2
no setter
center Vector2
The central point of the shape.
no setteroverride
edges List<LineSegment>
The 4 edges of this rectangle, returned in a clockwise fashion.
no setter
hashCode int
The hash code for this object.
no setterinherited
height double
no setter
isClosed bool
True if the shape is "closed", in the sense that it has an interior. For example, a closed shape can be filled with a paint.
no setterinherited
isConvex bool
True if the shape is convex, i.e. a line segment connecting any two points of the shape would lie completely within the shape.
no setteroverride
left double
no setter
leftEdge LineSegment
no setter
perimeter double
The length of the shape's boundary. For some more complicated shapes this can be computed approximately.
no setteroverride
no setter
rightEdge LineSegment
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
top double
no setter
topEdge LineSegment
no setter
topLeft Vector2
no setter
topRight Vector2
no setter
vertices List<Vector2>
The 4 corners of this rectangle, returned in a clockwise fashion.
no setter
width double
no setter

Methods

asPath() Path
Converts the shape to a Path object, suitable for rendering on a canvas. If a particular geometric primitive cannot be represented as a Path faithfully, an approximate path can be returned.
override
containsPoint(Vector2 point) bool
Returns true if the given point is inside the shape or on the boundary.
override
intersections(LineSegment line) Set<Vector2>
Returns all intersections between this rectangle's edges and the given line segment.
move(Vector2 offset) → void
Translates the shape by the specified offset vector, in-place.
override
nearestPoint(Vector2 point) Vector2
Returns a point on the shape's boundary which is closest to the given point.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
project(Transform2D transform, [Shape? target]) Shape
Returns the result of applying an affine transformation to the shape.
override
randomPoint({Random? random, bool within = true}) Vector2
Returns a random point within the shape if within is true (default) and otherwise a point along the edges of the shape. Do note that within=true also includes the edges.
override
support(Vector2 direction) Vector2
Finds the intersection of this shape with another one, if it exists. Returns a point on the boundary that is furthest in the given direction.
override
toRect() Rect
toString() String
A string representation of this object.
override

Operators

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