#[repr(C)]
pub struct Rect2 { pub position: Vector2, pub size: Vector2, }
Expand description

2D axis-aligned bounding box.

Rect2 consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.

The 3D counterpart to Rect2 is Aabb.

Fields

position: Vector2

The rectangle’s position in 2D space.

size: Vector2

Width and height.

Implementations

Creates a Rect2 by position and size.

Creates a Rect2 by x, y, width, and height.

Ending corner. This is calculated as position + size.

Ending corner. Setting this value will change the size.

Returns a rectangle with equivalent position and area, modified so that the top-left corner is the origin and width and height are positive.

Returns the area of the rectangle. See also has_no_area.

Returns true if the rectangle is flat or empty. See also area.

Note: If the Rect2 has a negative size and is not flat or empty, this method will return true. Use abs to make the size positive.

Example
let rect = Rect2::new(
    Vector2::new(2.0, 3.0),
    Vector2::new(-3.0, -4.0),
);
assert!(rect.has_no_area());
assert!(!rect.abs().has_no_area());

Returns true if the rectangle contains a point. By convention, the right and bottom edges of the rectangle are considered exclusive, so points on these edges are not included.

Note: This method is not reliable for Rect2 with a negative size. Use abs to get a positive sized equivalent rectangle to check for contained points.

Returns true if this rectangle and b are approximately equal, by calling is_equal_approx on each component.

Returns true if the inside of the rectangle overlaps with b (i.e. they have at least one point in common).

This excludes borders. See intersects_including_borders for inclusive check.

Note: This method is not reliable for Rect2 with a negative size. Use abs to get a positive sized equivalent rectangle to check for intersections.

Returns true if the rectangle overlaps with b (i.e. they have at least one point in common) or their borders touch even without intersection.

This includes borders. See intersects for exclusive check.

Note: This method is not reliable for Rect2 with a negative size. Use abs to get a positive sized equivalent rectangle to check for intersections.

Returns true if this rectangle (inclusively) encloses b.

This is true when self covers all the area of b, and possibly (but not necessarily) more.

Returns the intersection of this rectangle and b, or None if they don’t intersect.

This is similar to the GDScript clip function, but returns None instead of self if there is no intersection. This method excludes borders just like intersects.

Note: This method is not reliable for Rect2 with a negative size. Use abs to get a positive sized equivalent rectangle for clipping.

Returns a larger rectangle that contains this Rect2 and b.

Note: This method is not reliable for Rect2 with a negative size. Use abs to get a positive sized equivalent rectangle for merging.

Returns a copy of this rectangle expanded to include a given point.

Note: This method is not reliable for Rect2 with a negative size. Use abs to get a positive sized equivalent rectangle for expanding.

Example
let rect = Rect2::new(
    Vector2::new(-3.0, 2.0),
    Vector2::new(1.0, 1.0),
);

let rect2 = rect.expand(Vector2::new(0.0, -1.0));

assert_eq!(rect2.position, Vector2::new(-3.0, -1.0));
assert_eq!(rect2.size, Vector2::new(3.0, 4.0));

Returns a copy of this rectangle grown by a given amount of units on all the sides.

Returns a copy of this rectangle grown by a given amount of units towards each direction individually.

Returns a copy of this rectangle grown by a given amount of units towards the Margin direction.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
A type-specific hint type that is valid for the type being exported. Read more
Returns ExportInfo given an optional typed hint.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.