Struct vek::geom::repr_c::Rect[][src]

pub struct Rect<P, E> {
    pub x: P,
    pub y: P,
    pub w: E,
    pub h: E,
}
Expand description

2D rectangle, represented by a bottom-left position, and 2D extents.

Most operations on a Rect are better done by converting it to Aabr form. In fact, most existing code in the wild implicitly does this and so does this crate.

Aabr structs are often more convenient, faster and probably less confusing. The Rect type is provided because it exists for a lot of APIs (including some system APIs, OpenGL, and others).

Please note that in most APIs in the wild (but NOT in vek), the Y axis is treated as pointing downwards because it’s the one of window space.

Keeping the Y axis upwards is a lot more convenient implementation-wise, and still matches the convention used in 3D spaces.

Fields

x: P

X position of the bottom-left corner.

y: P

Y position of the bottom-left corner.

w: E

Width.

h: E

Height, with Y axis going upwards.

Implementations

Creates a new rectangle from position elements and extent elements.

Gets this rectangle’s position.

Gets this rectangle’s extent (size).

Gets this rectangle’s position and extent (size).

Returns this rectangle, converted with the given closures (one for position elements, the other for extent elements).

Converts this rectangle to a rectangle of another type, using the as conversion.

Converts this into the matching axis-aligned bounding shape representation.

Does this rectangle contain the given point ?

Does this rectangle fully contain the given one ?

Does this rectangle collide with another ?

Gets this rectangle’s center.

Returns this shape so that it contains the given point.

Expands this shape so that it contains the given point.

Gets the smallest rectangle that contains both this one and another.

Gets the largest rectangle contained by both this one and another.

Sets this rectangle to the union of itself with another.

Sets this rectangle to the intersection of itself with another.

Gets a vector that tells how much self penetrates other.

Splits this shape in two, by a straight plane along the x axis. The returned tuple is (low, high).

Panics

sp is assumed to be a position along the x axis that is within this shape’s bounds.

Splits this shape in two, by a straight plane along the y axis. The returned tuple is (low, high).

Panics

sp is assumed to be a position along the y axis that is within this shape’s bounds.

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

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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.