Struct graphene::Rect[][src]

pub struct Rect(_);
Expand description

The location and size of a rectangle region.

The width and height of a Rect can be negative; for instance, a Rect with an origin of [ 0, 0 ] and a size of [ 10, 10 ] is equivalent to a Rect with an origin of [ 10, 10 ] and a size of [ -10, -10 ].

Application code can normalize rectangles using normalize(); this function will ensure that the width and height of a rectangle are positive values. All functions taking a Rect as an argument will internally operate on a normalized copy; all functions returning a Rect will always return a normalized rectangle.

Implementations

Checks whether a Rect contains the given coordinates.

p

a Point

Returns

true if the rectangle contains the point

Checks whether a Rect fully contains the given rectangle.

b

a Rect

Returns

true if the rectangle self fully contains b

Expands a Rect to contain the given Point.

p

a Point

Returns

res

return location for the expanded rectangle

Compute the area of given normalized rectangle.

Returns

the area of the normalized rectangle

Retrieves the coordinates of the bottom-left corner of the given rectangle.

Returns

p

return location for a Point

Retrieves the coordinates of the bottom-right corner of the given rectangle.

Returns

p

return location for a Point

Retrieves the coordinates of the center of the given rectangle.

Returns

p

return location for a Point

Retrieves the normalized height of the given rectangle.

Returns

the normalized height of the rectangle

Retrieves the coordinates of the top-left corner of the given rectangle.

Returns

p

return location for a Point

Retrieves the coordinates of the top-right corner of the given rectangle.

Returns

p

return location for a Point

Retrieves the normalized width of the given rectangle.

Returns

the normalized width of the rectangle

Retrieves the normalized X coordinate of the origin of the given rectangle.

Returns

the normalized X coordinate of the rectangle

Retrieves the normalized Y coordinate of the origin of the given rectangle.

Returns

the normalized Y coordinate of the rectangle

Initializes the given Rect with the given values.

This function will implicitly normalize the Rect before returning.

x

the X coordinate of the Rect

y

the Y coordinate of the Rect

width

the width of the Rect

height

the height of the Rect

Returns

the initialized rectangle

Initializes self using the given src rectangle.

This function will implicitly normalize the Rect before returning.

src

a Rect

Returns

the initialized rectangle

Changes the given rectangle to be smaller, or larger depending on the given inset parameters.

To create an inset rectangle, use positive d_x or d_y values; to create a larger, encompassing rectangle, use negative d_x or d_y values.

The origin of the rectangle is offset by d_x and d_y, while the size is adjusted by (2 * d_x, 2 * d_y). If d_x and d_y are positive values, the size of the rectangle is decreased; if d_x and d_y are negative values, the size of the rectangle is increased.

If the size of the resulting inset rectangle has a negative width or height then the size will be set to zero.

d_x

the horizontal inset

d_y

the vertical inset

Returns

the inset rectangle

Changes the given rectangle to be smaller, or larger depending on the given inset parameters.

To create an inset rectangle, use positive d_x or d_y values; to create a larger, encompassing rectangle, use negative d_x or d_y values.

The origin of the rectangle is offset by d_x and d_y, while the size is adjusted by (2 * d_x, 2 * d_y). If d_x and d_y are positive values, the size of the rectangle is decreased; if d_x and d_y are negative values, the size of the rectangle is increased.

If the size of the resulting inset rectangle has a negative width or height then the size will be set to zero.

d_x

the horizontal inset

d_y

the vertical inset

Returns

res

return location for the inset rectangle

Linearly interpolates the origin and size of the two given rectangles.

b

a Rect

factor

the linear interpolation factor

Returns

res

return location for the interpolated rectangle

Computes the intersection of the two given rectangles.

The intersection in the image above is the blue outline.

If the two rectangles do not intersect, res will contain a degenerate rectangle with origin in (0, 0) and a size of 0.

b

a Rect

Returns

true if the two rectangles intersect

res

return location for a Rect

Normalizes the passed rectangle.

This function ensures that the size of the rectangle is made of positive values, and that the origin is the top-left corner of the rectangle.

Returns

the normalized rectangle

Normalizes the passed rectangle.

This function ensures that the size of the rectangle is made of positive values, and that the origin is in the top-left corner of the rectangle.

Returns

res

the return location for the normalized rectangle

Offsets the origin by d_x and d_y.

The size of the rectangle is unchanged.

d_x

the horizontal offset

d_y

the vertical offset

Returns

the offset rectangle

Offsets the origin of the given rectangle by d_x and d_y.

The size of the rectangle is left unchanged.

d_x

the horizontal offset

d_y

the vertical offset

Returns

res

return location for the offset rectangle

Rounds the origin of the given rectangle to its nearest integer value and and recompute the size so that the rectangle is large enough to contain all the conrners of the original rectangle.

This function is the equivalent of calling floor on the coordinates of the origin, and recomputing the size calling ceil on the bottom-right coordinates.

If you want to be sure that the rounded rectangle completely covers the area that was covered by the original rectangle — i.e. you want to cover the area including all its corners — this function will make sure that the size is recomputed taking into account the ceiling of the coordinates of the bottom-right corner. If the difference between the original coordinates and the coordinates of the rounded rectangle is greater than the difference between the original size and and the rounded size, then the move of the origin would not be compensated by a move in the anti-origin, leaving the corners of the original rectangle outside the rounded one.

Returns

res

return location for the rectangle with rounded extents

Scales the size and origin of a rectangle horizontaly by s_h, and vertically by s_v. The result res is normalized.

s_h

horizontal scale factor

s_v

vertical scale factor

Returns

res

return location for the scaled rectangle

Computes the union of the two given rectangles.

The union in the image above is the blue outline.

b

a Rect

Returns

res

return location for a Rect

Returns a degenerate rectangle with origin fixed at (0, 0) and a size of 0, 0.

Returns

a fixed rectangle

Computes the four vertices of a Rect.

Returns

vertices

return location for an array of 4 Vec2

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

Feeds this value into the given Hasher. Read more

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

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

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

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Returns the type identifier of Self.

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.