Struct primitives::Box2D[][src]

#[repr(C)]
pub struct Box2D<T> { pub min: Point<T>, pub max: Point<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: Point<T>max: Point<T>

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 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.