graphene

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

GLib type: Inline allocated boxed type with stack copy semantics.

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

Copies the inline boxed type by value with the type-specific copy function.

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

Source§

type ParamSpec = ParamSpecBoxed

Source§

type SetValue = Rect

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

Source§

type Value = T

Source§

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

Source§

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,

Source§

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

Source§

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

Source§

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,