Struct euclid::Rect

source · []
#[repr(C)]
pub struct Rect<T, U> { pub origin: Point2D<T, U>, pub size: Size2D<T, U>, }
Expand description

A 2d Rectangle optionally tagged with a unit.

Representation

Rect is represented by an origin point and a size.

See Box2D for a rectangle represented by two endpoints.

Empty rectangle

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

  • it’s area is empty,
  • it’s area is negative (size.x < 0 or size.y < 0),
  • it contains NaNs.

Fields

origin: Point2D<T, U>size: Size2D<T, U>

Implementations

Constructor.

Constructor, setting all sides to zero.

Creates a rect of the given size, at offset zero.

Returns the same rectangle, translated by a vector.

Returns true if this rectangle contains the point. Points are considered in the rectangle if they are on the left or top edge, but outside if they are on the right or bottom edge.

Returns true if this rectangle contains the interior of rect. Always returns true if rect is empty, and always returns false if rect is nonempty but this rectangle is empty.

Calculate the size and position of an inner rectangle.

Subtracts the side offsets from all sides. The horizontal and vertical offsets must not be larger than the original side length. This method assumes y oriented downward.

Calculate the size and position of an outer rectangle.

Add the offsets to all sides. The expanded rectangle is returned. This method assumes y oriented downward.

Returns the smallest rectangle defined by the top/bottom/left/right-most points provided as parameter.

Note: This function has a behavior that can be surprising because the right-most and bottom-most points are exactly on the edge of the rectangle while the contains function is has exclusive semantic on these edges. This means that the right-most and bottom-most points provided to from_points will count as not contained by the rect. This behavior may change in the future.

Linearly interpolate between this rectangle and another rectangle.

Drop the units, preserving only the numeric value.

Tag a unitless value with units.

Cast the unit

Cast from one numeric representation to another, preserving the units.

When casting from floating point to integer coordinates, the decimals are truncated as one would expect from a simple cast, but this behavior does not always make sense geometrically. Consider using round(), round_in or round_out() before casting.

Fallible cast from one numeric representation to another, preserving the units.

When casting from floating point to integer coordinates, the decimals are truncated as one would expect from a simple cast, but this behavior does not always make sense geometrically. Consider using round(), round_in or round_out() before casting.

Cast into an f32 rectangle.

Cast into an f64 rectangle.

Cast into an usize rectangle, truncating decimals if any.

When casting from floating point rectangles, it is worth considering whether to round(), round_in() or round_out() before the cast in order to obtain the desired conversion behavior.

Cast into an u32 rectangle, truncating decimals if any.

When casting from floating point rectangles, it is worth considering whether to round(), round_in() or round_out() before the cast in order to obtain the desired conversion behavior.

Cast into an u64 rectangle, truncating decimals if any.

When casting from floating point rectangles, it is worth considering whether to round(), round_in() or round_out() before the cast in order to obtain the desired conversion behavior.

Cast into an i32 rectangle, truncating decimals if any.

When casting from floating point rectangles, it is worth considering whether to round(), round_in() or round_out() before the cast in order to obtain the desired conversion behavior.

Cast into an i64 rectangle, truncating decimals if any.

When casting from floating point rectangles, it is worth considering whether to round(), round_in() or round_out() before the cast in order to obtain the desired conversion behavior.

Returns true if all members are finite.

Return a rectangle with edges rounded to integer coordinates, such that the returned rectangle has the same set of pixel centers as the original one. Edges at offset 0.5 round up. Suitable for most places where integral device coordinates are needed, but note that any translation should be applied first to avoid pixel rounding errors. Note that this is not rounding to nearest integer if the values are negative. They are always rounding as floor(n + 0.5).

Usage notes

Note, that when using with floating-point T types that method can significantly loose precision for large values, so if you need to call this method very often it is better to use Box2D.

Return a rectangle with edges rounded to integer coordinates, such that the original rectangle contains the resulting rectangle.

Usage notes

Note, that when using with floating-point T types that method can significantly loose precision for large values, so if you need to call this method very often it is better to use Box2D.

Return a rectangle with edges rounded to integer coordinates, such that the original rectangle is contained in the resulting rectangle.

Usage notes

Note, that when using with floating-point T types that method can significantly loose precision for large values, so if you need to call this method very often it is better to use Box2D.

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

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

Performs the /= operation. Read more

Performs the /= operation. Read more

Converts to this type from the input type.

Feeds this value into the given Hasher. Read more

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

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

Performs the *= operation. Read more

Performs the *= operation. Read more

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

This method tests for !=.

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

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

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.