Struct graphene::Rect

source ·
pub struct Rect { /* private fields */ }
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§

source§

impl Rect

source

pub fn as_ptr(&self) -> *mut graphene_rect_t

source

pub unsafe fn from_glib_ptr_borrow<'a>(ptr: *const graphene_rect_t) -> &'a Self

Borrows the underlying C value.

source

pub unsafe fn from_glib_ptr_borrow_mut<'a>( ptr: *mut graphene_rect_t ) -> &'a mut Self

Borrows the underlying C value mutably.

source§

impl Rect

source

pub fn contains_point(&self, p: &Point) -> bool

Checks whether a Rect contains the given coordinates.

§p

a Point

§Returns

true if the rectangle contains the point

source

pub fn contains_rect(&self, b: &Rect) -> bool

Checks whether a Rect fully contains the given rectangle.

§b

a Rect

§Returns

true if the rectangle self fully contains b

source

pub fn expand(&self, p: &Point) -> Rect

Expands a Rect to contain the given Point.

§p

a Point

§Returns
§res

return location for the expanded rectangle

source

pub fn area(&self) -> f32

Compute the area of given normalized rectangle.

§Returns

the area of the normalized rectangle

source

pub fn bottom_left(&self) -> Point

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

§Returns
§p

return location for a Point

source

pub fn bottom_right(&self) -> Point

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

§Returns
§p

return location for a Point

source

pub fn center(&self) -> Point

Retrieves the coordinates of the center of the given rectangle.

§Returns
§p

return location for a Point

source

pub fn height(&self) -> f32

Retrieves the normalized height of the given rectangle.

§Returns

the normalized height of the rectangle

source

pub fn top_left(&self) -> Point

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

§Returns
§p

return location for a Point

source

pub fn top_right(&self) -> Point

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

§Returns
§p

return location for a Point

source

pub fn width(&self) -> f32

Retrieves the normalized width of the given rectangle.

§Returns

the normalized width of the rectangle

source

pub fn x(&self) -> f32

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

§Returns

the normalized X coordinate of the rectangle

source

pub fn y(&self) -> f32

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

§Returns

the normalized Y coordinate of the rectangle

source

pub fn inset(&mut self, d_x: f32, d_y: f32)

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

source

pub fn inset_r(&self, d_x: f32, d_y: f32) -> Rect

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

source

pub fn interpolate(&self, b: &Rect, factor: f64) -> Rect

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

source

pub fn intersection(&self, b: &Rect) -> Option<Rect>

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

source

pub fn normalize(&mut self)

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

source

pub fn normalize_r(&self) -> Rect

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

source

pub fn offset(&mut self, d_x: f32, d_y: f32)

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

source

pub fn offset_r(&self, d_x: f32, d_y: f32) -> Rect

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

source

pub fn round_extents(&self) -> Rect

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

source

pub fn scale(&self, s_h: f32, s_v: f32) -> Rect

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

source

pub fn union(&self, b: &Rect) -> Rect

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

source

pub fn zero() -> Rect

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

§Returns

a fixed rectangle

source§

impl Rect

source

pub fn vertices(&self) -> &[Vec2; 4]

Computes the four vertices of a Rect.

§Returns
§vertices

return location for an array of 4 Vec2

source

pub fn new(x: f32, y: f32, width: f32, height: f32) -> Self

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

Trait Implementations§

source§

impl Clone for Rect

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Rect

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Rect

source§

fn default() -> Self

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

impl HasParamSpec for Rect

§

type ParamSpec = ParamSpecBoxed

§

type SetValue = Rect

Preferred value to be used as setter for the associated ParamSpec.
§

type BuilderFn = fn(_: &str) -> ParamSpecBoxedBuilder<'_, Rect>

source§

fn param_spec_builder() -> Self::BuilderFn

source§

impl PartialEq for Rect

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StaticType for Rect

source§

fn static_type() -> Type

Returns the type identifier of Self.
source§

impl Copy for Rect

source§

impl Eq for Rect

Auto Trait Implementations§

§

impl Freeze for Rect

§

impl RefUnwindSafe for Rect

§

impl Send for Rect

§

impl Sync for Rect

§

impl Unpin for Rect

§

impl UnwindSafe for Rect

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> IntoClosureReturnValue for T
where T: Into<Value>,

source§

impl<T> Property for T
where T: HasParamSpec,

§

type Value = T

source§

impl<T> PropertyGet for T
where T: HasParamSpec,

§

type Value = T

source§

fn get<R, F>(&self, f: F) -> R
where F: Fn(&<T as PropertyGet>::Value) -> R,

source§

impl<T> StaticTypeExt for T
where T: StaticType,

source§

fn ensure_type()

Ensures that the type has been registered with the type system.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToSendValue for T
where T: Send + ToValue + ?Sized,

source§

fn to_send_value(&self) -> SendValue

Returns a SendValue clone of self.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T> TryFromClosureReturnValue for T
where T: for<'a> FromValue<'a> + StaticType + 'static,

source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<'a, T, C, E> FromValueOptional<'a> for T
where T: FromValue<'a, Checker = C>, C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError<E>>, E: Error + Send + 'static,