Skip to main content

Clip

Struct Clip 

Source
pub struct Clip {
    pub antialias: bool,
    pub x_min: f64,
    pub y_min: f64,
    pub x_max: f64,
    pub y_max: f64,
    pub x_min_i: i32,
    pub y_min_i: i32,
    pub x_max_i: i32,
    pub y_max_i: i32,
    /* private fields */
}
Expand description

A clipping region combining an axis-aligned rectangle with an optional stack of arbitrary path clips.

The effective clip is the intersection of the rectangle and all path clips.

Fields§

§antialias: bool

Whether anti-aliasing (supersampling) is enabled; scales coordinates by AA_SIZE when testing path clips.

§x_min: f64

Left edge of the clip rectangle in floating-point device space (inclusive).

§y_min: f64

Top edge of the clip rectangle in floating-point device space (inclusive).

§x_max: f64

Right edge of the clip rectangle in floating-point device space (exclusive).

§y_max: f64

Bottom edge of the clip rectangle in floating-point device space (exclusive).

§x_min_i: i32

Integer pixel column of the left clip edge: floor(x_min).

§y_min_i: i32

Integer pixel row of the top clip edge: floor(y_min).

§x_max_i: i32

Integer pixel column of the right clip edge: ceil(x_max) - 1.

§y_max_i: i32

Integer pixel row of the bottom clip edge: ceil(y_max) - 1.

Implementations§

Source§

impl Clip

Source

pub fn new(x0: f64, y0: f64, x1: f64, y1: f64, antialias: bool) -> Self

Create a new clip region from a rectangle.

Matches SplashClip(x0, y0, x1, y1, antialiasA) in SplashClip.cc.

Source

pub fn clone_shared(&self) -> Self

Clone this Clip, sharing all path-clip scanners via Arc.

The cloned value and the original share the same XPathScanner instances. Because scanners are immutable after construction there is no interior-mutability hazard. This mirrors C++ shared_ptr copy semantics used in GraphicsState::save.

Source

pub fn reset_to_rect(&mut self, x0: f64, y0: f64, x1: f64, y1: f64)

Replace the clip rectangle and clear all path clips.

Source

pub fn clip_to_rect(&mut self, x0: f64, y0: f64, x1: f64, y1: f64)

Intersect the clip rectangle with [x0, y0, x1, y1].

Source

pub fn clip_to_path(&mut self, xpath: &XPath, eo: bool)

Intersect with an arbitrary path clip.

If the path resolves to a simple axis-aligned rectangle (4 segments, axis-aligned), it is reduced to clip_to_rect. Otherwise a new XPathScanner is pushed onto the scanner stack.

An empty path forces the clip to be empty (nothing passes through).

§Panics

Panics in debug builds if the AA y-range arithmetic overflows i32. In practice y_max_i is bounded by the bitmap height (≪ i32::MAX / AA_SIZE).

Source

pub fn test(&self, x: i32, y: i32) -> bool

Test whether pixel (x, y) is inside the clip region.

Returns false immediately if (x, y) is outside the axis-aligned rectangle; otherwise all path-clip scanners are consulted.

Source

pub fn test_rect( &self, left: i32, top: i32, right: i32, bottom: i32, ) -> ClipResult

Test a pixel rectangle against the clip region.

The rectangle is inclusive on both ends: [left, right] × [top, bottom].

Source

pub fn test_span(&self, x0: i32, x1: i32, y: i32) -> ClipResult

Test whether the span [x0, x1] on scanline y is fully inside the clip.

Returns ClipResult::AllInside only when the span is inside both the bounding rectangle and every path-clip scanner. Returns ClipResult::AllOutside when the span is fully outside the rectangle. Otherwise returns ClipResult::Partial.

Source

pub fn clip_aa_line( &self, aa_buf: &mut AaBuf, x0: &mut i32, x1: &mut i32, y: i32, )

Clip an AA buffer row, zeroing bits outside the clip region.

Matches SplashClip::clipAALine in SplashClip.cc. Each path-clip scanner is asked to render its coverage into aa_buf, and the output span [*x0, *x1] is clamped to the integer clip bounds.

This method does not panic. AA_SIZE is the compile-time constant 4, which is always representable as usize.

Auto Trait Implementations§

§

impl Freeze for Clip

§

impl RefUnwindSafe for Clip

§

impl Send for Clip

§

impl Sync for Clip

§

impl Unpin for Clip

§

impl UnsafeUnpin for Clip

§

impl UnwindSafe for Clip

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