logo
#[repr(C)]
pub struct Box2D<T> { pub min: Vector2D<T>, pub max: Vector2D<T>, }
Expand description

A 2d axis aligned rectangle represented by its minimum and maximum coordinates.

Representation

This struct is similar to Rect, but stores rectangle as two endpoints instead of origin point and size. Such representation has several advantages over Rect representation:

  • Several operations are more efficient with Box2D, including intersection, union, and point-in-rect.
  • The representation is less susceptible to overflow. With Rect, computation of second point can overflow for a large range of values of origin and size. However, with Box2D, computation of size cannot overflow if the coordinates are signed and the resulting size is unsigned.

A known disadvantage of Box2D is that translating the rectangle requires translating both points, whereas translating Rect only requires translating one point.

Empty box

A box is considered empty (see is_empty) if any of the following is true:

  • it’s area is empty,
  • it’s area is negative (min.x > max.x or min.y > max.y),
  • it contains NaNs.

Fields

min: Vector2D<T>

Represents min point

max: Vector2D<T>

Represents max point

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.

Typed getter

Inspect the context.

Inspect the context.

Inspect the context.

Calls U::from(self).

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

Convert into color

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Sets value as a parameter of self.

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.