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: boolWhether anti-aliasing (supersampling) is enabled; scales coordinates by
AA_SIZE when testing path clips.
x_min: f64Left edge of the clip rectangle in floating-point device space (inclusive).
y_min: f64Top edge of the clip rectangle in floating-point device space (inclusive).
x_max: f64Right edge of the clip rectangle in floating-point device space (exclusive).
y_max: f64Bottom edge of the clip rectangle in floating-point device space (exclusive).
x_min_i: i32Integer pixel column of the left clip edge: floor(x_min).
y_min_i: i32Integer pixel row of the top clip edge: floor(y_min).
x_max_i: i32Integer pixel column of the right clip edge: ceil(x_max) - 1.
y_max_i: i32Integer pixel row of the bottom clip edge: ceil(y_max) - 1.
Implementations§
Source§impl Clip
impl Clip
Sourcepub fn new(x0: f64, y0: f64, x1: f64, y1: f64, antialias: bool) -> Self
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.
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.
Sourcepub fn reset_to_rect(&mut self, x0: f64, y0: f64, x1: f64, y1: f64)
pub fn reset_to_rect(&mut self, x0: f64, y0: f64, x1: f64, y1: f64)
Replace the clip rectangle and clear all path clips.
Sourcepub fn clip_to_rect(&mut self, x0: f64, y0: f64, x1: f64, y1: f64)
pub fn clip_to_rect(&mut self, x0: f64, y0: f64, x1: f64, y1: f64)
Intersect the clip rectangle with [x0, y0, x1, y1].
Sourcepub fn clip_to_path(&mut self, xpath: &XPath, eo: bool)
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).
Sourcepub fn test(&self, x: i32, y: i32) -> bool
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.
Sourcepub fn test_rect(
&self,
left: i32,
top: i32,
right: i32,
bottom: i32,
) -> ClipResult
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].
Sourcepub fn test_span(&self, x0: i32, x1: i32, y: i32) -> ClipResult
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.
Sourcepub fn clip_aa_line(
&self,
aa_buf: &mut AaBuf,
x0: &mut i32,
x1: &mut i32,
y: i32,
)
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.