Skip to main content

Path

Struct Path 

Source
pub struct Path { /* private fields */ }
Expand description

路径的 safe 封装,对应 SkPath。Safe wrapper for SkPath.

Implementations§

Source§

impl Path

Source

pub fn new() -> Self

创建空路径。Creates an empty path.

Source

pub fn from_path(other: &Path) -> Self

从已有路径复制。Creates a copy of the given path.

Source

pub fn reset(&mut self)

清空路径。Empties the path.

Source

pub fn is_empty(&self) -> bool

是否为空。Returns true if the path has no points.

Source

pub fn count_points(&self) -> i32

点的数量。Returns the number of points in the path.

Source

pub fn count_verbs(&self) -> i32

动词的数量。Returns the number of verbs (move, line, quad, cubic, close).

Source

pub fn iter(&self, force_close: bool) -> PathIter<'_>

迭代路径中的动词与点。Iterates over path verbs and points.

force_close 为 true 时,开放轮廓会生成隐式 close。 When force_close is true, open contours generate implicit close.

Source

pub fn get_point(&self, index: i32) -> Option<Point>

获取第 i 个点。Returns the point at index, or None if out of range.

Source

pub fn tight_bounds(&self) -> Rect

计算紧密包围盒。Returns the tight axis-aligned bounding box.

永不失败;空路径返回 (0,0,0,0)。对复杂曲线,pathops_tight_bounds 可能更精确但可能返回 None。 Never fails; empty path returns (0,0,0,0). For complex curves, pathops_tight_bounds may be more accurate but can return None.

Source

pub fn is_last_contour_closed(&self) -> bool

最后一段轮廓是否闭合。Returns true if the last contour ends with close().

Source

pub fn conservatively_contains_rect(&self, rect: &Rect) -> bool

保守判断是否包含矩形。May return false for some contained rects. Works for single convex contour paths.

Source

pub fn is_rect(&self) -> Option<(Rect, bool)>

是否可表示为矩形。Returns Some((rect, is_closed)) if path is a rect, None otherwise.

Source

pub fn contains(&self, x: f32, y: f32) -> bool

是否包含点。Returns true if (x, y) is inside the filled path.

使用 SkPath 当前 fill type(默认 even-odd)。 Uses SkPath’s current fill type (default even-odd).

Source

pub fn move_to(&mut self, x: f32, y: f32) -> &mut Self

移动到 (x, y),开始新轮廓。Moves to (x, y) and starts a new contour.

Source

pub fn line_to(&mut self, x: f32, y: f32) -> &mut Self

画线到 (x, y)。Adds a line from current point to (x, y).

需先调用 move_to;否则 Skia 以 (0, 0) 为隐式起点。 Requires prior move_to; otherwise Skia uses (0, 0) as implicit start.

Source

pub fn quad_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32) -> &mut Self

二次贝塞尔曲线。Adds a quadratic bezier (control point, end point).

Source

pub fn cubic_to( &mut self, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, ) -> &mut Self

三次贝塞尔曲线。Adds a cubic bezier (ctrl1, ctrl2, end point).

Source

pub fn close(&mut self) -> &mut Self

闭合当前轮廓。Closes the current contour (line back to first point).

Source

pub fn add_rect( &mut self, rect: &Rect, dir: Direction, start: RectCorner, ) -> &mut Self

添加矩形。Adds a rectangle as a closed contour.

Source

pub fn add_oval(&mut self, rect: &Rect, dir: Direction) -> &mut Self

添加椭圆(由矩形包围)。Adds an oval (ellipse) bounded by the given rect.

Source

pub fn add_circle( &mut self, cx: f32, cy: f32, radius: f32, dir: Direction, ) -> &mut Self

添加圆。Adds a circle centered at (cx, cy) with given radius.

radius 应 ≥ 0;负值时 Skia 行为未定义。 radius should be ≥ 0; negative values have undefined Skia behavior.

Source

pub fn add_round_rect( &mut self, rect: &Rect, rx: f32, ry: f32, dir: Direction, ) -> &mut Self

添加圆角矩形。Adds a rounded rectangle (rx, ry = corner radii).

rx, ry 应 ≥ 0。Should be ≥ 0.

Source

pub fn add_rrect(&mut self, rrect: &RRect, dir: Direction) -> &mut Self

添加 RRect(支持四角独立半径)。Adds RRect with per-corner radii.

Source

pub fn add_rrect_with_start( &mut self, rrect: &RRect, dir: Direction, start: RectCorner, ) -> &mut Self

添加 RRect 并指定起始角。Adds RRect with start corner.

Source

pub fn is_rrect(&self) -> Option<RRect>

路径是否可表示为 RRect。Returns Some(rrect) if path is an RRect, None otherwise.

Trait Implementations§

Source§

impl Clone for Path

Source§

fn clone(&self) -> Self

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 Path

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Path

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Path

§

impl !RefUnwindSafe for Path

§

impl !Send for Path

§

impl !Sync for Path

§

impl Unpin for Path

§

impl UnsafeUnpin for Path

§

impl !UnwindSafe for Path

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.