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: f64Left edge (minimum x).
bottom: f64Bottom edge (minimum y).
right: f64Right edge (maximum x).
top: f64Top edge (maximum y).
Implementations§
Source§impl Rect
impl Rect
Sourcepub fn new(left: f64, bottom: f64, right: f64, top: f64) -> Self
pub fn new(left: f64, bottom: f64, right: f64, top: f64) -> Self
Create a new rectangle from its four edges.
Sourcepub fn is_empty(&self) -> bool
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.
Sourcepub fn contains(&self, point: Point) -> bool
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).
Sourcepub fn contains_rect(&self, other: &Rect) -> bool
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.
Sourcepub fn normalize(&self) -> Self
pub fn normalize(&self) -> Self
Return the rectangle normalized so that left <= right and bottom <= top.
Sourcepub fn intersect(&self, other: &Rect) -> Option<Rect>
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.
Sourcepub fn union(&self, other: &Rect) -> Rect
pub fn union(&self, other: &Rect) -> Rect
Return the smallest rectangle containing both self and other.
Equivalent to CFX_FloatRect::Union() in PDFium.
Sourcepub fn inflate(&self, x: f64, y: f64) -> Rect
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.
Sourcepub fn inflate_sides(
&self,
left: f64,
bottom: f64,
right: f64,
top: f64,
) -> Rect
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.
Sourcepub fn deflate_sides(
&self,
left: f64,
bottom: f64,
right: f64,
top: f64,
) -> Rect
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.
Sourcepub fn deflate(&self, x: f64, y: f64) -> Rect
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.
Sourcepub fn from_points(points: &[Point]) -> Option<Rect>
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.
Sourcepub fn translate(&self, dx: f64, dy: f64) -> Rect
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.
Sourcepub fn scale(&self, factor: f64) -> Rect
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.
Sourcepub fn outer_rect(&self) -> RectI
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.
Sourcepub fn get_outer_rect(&self) -> RectI
pub fn get_outer_rect(&self) -> RectI
Upstream-aligned alias for Self::outer_rect().
Corresponds to CFX_FloatRect::GetOuterRect().
Sourcepub fn inner_rect(&self) -> RectI
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.
Sourcepub fn get_inner_rect(&self) -> RectI
pub fn get_inner_rect(&self) -> RectI
Upstream-aligned alias for Self::inner_rect().
Corresponds to CFX_FloatRect::GetInnerRect().
Sourcepub fn closest_rect(&self) -> RectI
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.
Sourcepub fn get_closest_rect(&self) -> RectI
pub fn get_closest_rect(&self) -> RectI
Upstream-aligned alias for Self::closest_rect().
Corresponds to CFX_FloatRect::GetClosestRect().
Sourcepub fn to_rect_i(&self) -> RectI
pub fn to_rect_i(&self) -> RectI
Return an integer rectangle by truncating all edges toward zero.
Equivalent to CFX_FloatRect::ToFxRect() in PDFium.
Sourcepub fn to_fx_rect(&self) -> RectI
pub fn to_fx_rect(&self) -> RectI
Upstream-aligned alias for to_rect_i.
Corresponds to CFX_FloatRect::ToFxRect() in PDFium upstream.
Sourcepub fn center(&self) -> Point
pub fn center(&self) -> Point
Returns the center point of this rectangle.
Equivalent to computing the midpoint of the LBRT edges.
Sourcepub fn scale_from_center_point(&self, factor: f64) -> Self
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().
Sourcepub fn center_square(&self) -> Self
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().
Sourcepub fn get_center_square(&self) -> Self
pub fn get_center_square(&self) -> Self
Upstream-aligned alias for Self::center_square().
Corresponds to CFX_FloatRect::GetCenterSquare().
Sourcepub fn to_rounded_rect_i(&self) -> RectI
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.
Sourcepub fn to_rounded_fx_rect(&self) -> RectI
pub fn to_rounded_fx_rect(&self) -> RectI
Upstream-aligned alias for to_rounded_rect_i.
Corresponds to CFX_FloatRect::ToRoundedFxRect() in PDFium upstream.
Sourcepub fn get_deflated(&self, x: f64, y: f64) -> Self
pub fn get_deflated(&self, x: f64, y: f64) -> Self
Upstream-aligned alias for deflate.
Corresponds to CFX_FloatRect::GetDeflated() in PDFium upstream.
Sourcepub fn update_rect(&self, point: Point) -> Self
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.
Sourcepub fn get_bbox(points: &[Point]) -> Option<Self>
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.