Skip to main content

Rect

Struct Rect 

Source
pub struct Rect {
    pub left: f64,
    pub bottom: f64,
    pub right: f64,
    pub top: f64,
}
Expand description

A rectangle in PDF coordinate space.

PDF rectangles are defined by two diagonally opposite corners. By convention, left < right and bottom < top in the standard PDF coordinate system (origin at bottom-left).

Fields§

§left: f64

Left edge (minimum x).

§bottom: f64

Bottom edge (minimum y).

§right: f64

Right edge (maximum x).

§top: f64

Top edge (maximum y).

Implementations§

Source§

impl Rect

Source

pub fn new(left: f64, bottom: f64, right: f64, top: f64) -> Self

Create a new rectangle from its four edges.

Source

pub fn width(&self) -> f64

Width of the rectangle.

Source

pub fn height(&self) -> f64

Height of the rectangle.

Source

pub fn size(&self) -> Size

Size of the rectangle.

Source

pub fn is_empty(&self) -> bool

Returns true if the rectangle has zero or negative area.

A rectangle is considered empty when left >= right or bottom >= top, meaning it has no positive-area interior.

Equivalent to CFX_FloatRect::IsEmpty() in PDFium.

Source

pub fn contains(&self, point: Point) -> bool

Returns true if the rectangle contains the given point.

Normalizes the rectangle before testing, so this works correctly even when left > right or bottom > top (non-canonical orientation).

Source

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

Returns true if this rectangle completely contains other.

Both rectangles are normalized before comparison, matching upstream CFX_FloatRect::Contains(const CFX_FloatRect&) in PDFium.

Source

pub fn normalize(&self) -> Self

Return the rectangle normalized so that left <= right and bottom <= top.

Source

pub fn intersect(&self, other: &Rect) -> Option<Rect>

Return the intersection of two rectangles, or None if they do not overlap.

Equivalent to CFX_FloatRect::Intersect() in PDFium.

Source

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

Return the smallest rectangle containing both self and other.

Equivalent to CFX_FloatRect::Union() in PDFium.

Source

pub fn inflate(&self, x: f64, y: f64) -> Rect

Return a rectangle expanded outward by x horizontally and y vertically.

Equivalent to CFX_FloatRect::Inflate(x, y) in PDFium.

Source

pub fn inflate_sides( &self, left: f64, bottom: f64, right: f64, top: f64, ) -> Rect

Return a rectangle expanded outward by independent amounts on each side.

Equivalent to CFX_FloatRect::Inflate(left, bottom, right, top) in PDFium.

Source

pub fn deflate_sides( &self, left: f64, bottom: f64, right: f64, top: f64, ) -> Rect

Return a rectangle shrunk inward by independent amounts on each side.

Equivalent to CFX_FloatRect::Deflate(left, bottom, right, top) in PDFium.

Source

pub fn deflate(&self, x: f64, y: f64) -> Rect

Return a rectangle shrunk inward by x horizontally and y vertically.

Equivalent to CFX_FloatRect::Deflate() in PDFium.

Source

pub fn from_points(points: &[Point]) -> Option<Rect>

Return the bounding box of a set of points, or None if points is empty.

Equivalent to CFX_FloatRect::GetBBox() in PDFium.

Source

pub fn translate(&self, dx: f64, dy: f64) -> Rect

Return a copy of this rectangle shifted by (dx, dy).

Equivalent to CFX_FloatRect::Translate(e, f) in PDFium.

Source

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

Return a copy of this rectangle with all edges scaled by factor.

Equivalent to CFX_FloatRect::Scale(fScale) in PDFium.

Source

pub fn outer_rect(&self) -> RectI

Return the smallest integer rectangle that contains this rectangle.

Left and bottom are floored; right and top are ceiled. Equivalent to CFX_FloatRect::GetOuterRect() in PDFium.

Source

pub fn get_outer_rect(&self) -> RectI

Upstream-aligned alias for Self::outer_rect().

Corresponds to CFX_FloatRect::GetOuterRect().

Source

pub fn inner_rect(&self) -> RectI

Return the largest integer rectangle contained within this rectangle.

Left and bottom are ceiled; right and top are floored. Equivalent to CFX_FloatRect::GetInnerRect() in PDFium.

Source

pub fn get_inner_rect(&self) -> RectI

Upstream-aligned alias for Self::inner_rect().

Corresponds to CFX_FloatRect::GetInnerRect().

Source

pub fn closest_rect(&self) -> RectI

Return the integer rectangle that minimizes rounding error.

Chooses the starting edge (floor or ceil) that produces the smallest total deviation from the floating-point extent in both dimensions. Equivalent to CFX_FloatRect::GetClosestRect() in PDFium.

Source

pub fn get_closest_rect(&self) -> RectI

Upstream-aligned alias for Self::closest_rect().

Corresponds to CFX_FloatRect::GetClosestRect().

Source

pub fn to_rect_i(&self) -> RectI

Return an integer rectangle by truncating all edges toward zero.

Equivalent to CFX_FloatRect::ToFxRect() in PDFium.

Source

pub fn to_fx_rect(&self) -> RectI

Upstream-aligned alias for to_rect_i.

Corresponds to CFX_FloatRect::ToFxRect() in PDFium upstream.

Source

pub fn center(&self) -> Point

Returns the center point of this rectangle.

Equivalent to computing the midpoint of the LBRT edges.

Source

pub fn scale_from_center_point(&self, factor: f64) -> Self

Scales this rectangle by factor around its center point.

Corresponds to upstream CFX_RectF::ScaleFromCenterPoint().

Source

pub fn center_square(&self) -> Self

Returns the largest square with the same center as this rectangle.

The square’s side length equals the shorter dimension of this rectangle. Corresponds to upstream CFX_RectF::GetCenterSquare().

Source

pub fn get_center_square(&self) -> Self

Upstream-aligned alias for Self::center_square().

Corresponds to CFX_FloatRect::GetCenterSquare().

Source

pub fn to_rounded_rect_i(&self) -> RectI

Return an integer rectangle by rounding all edges to the nearest integer.

Equivalent to CFX_FloatRect::ToRoundedFxRect() in PDFium.

Source

pub fn to_rounded_fx_rect(&self) -> RectI

Upstream-aligned alias for to_rounded_rect_i.

Corresponds to CFX_FloatRect::ToRoundedFxRect() in PDFium upstream.

Source

pub fn get_deflated(&self, x: f64, y: f64) -> Self

Upstream-aligned alias for deflate.

Corresponds to CFX_FloatRect::GetDeflated() in PDFium upstream.

Source

pub fn update_rect(&self, point: Point) -> Self

Extend this rectangle’s bounding box to include the given point.

If the point is already inside the rectangle, the rectangle is unchanged. Equivalent to CFX_FloatRect::UpdateRect(point) in PDFium.

Source

pub fn get_bbox(points: &[Point]) -> Option<Self>

Return the bounding box of a set of points, or None if points is empty.

Upstream-aligned alias for Self::from_points(). Corresponds to CFX_FloatRect::GetBBox() in PDFium.

Trait Implementations§

Source§

impl Clone for Rect

Source§

fn clone(&self) -> Rect

Returns a duplicate 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 PartialEq for Rect

Source§

fn eq(&self, other: &Rect) -> 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 Copy for Rect

Source§

impl StructuralPartialEq 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 UnsafeUnpin 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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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