Skip to main content

Path

Struct Path 

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

路径的 safe 封装,底层为 C++ pk::SkPath。 Safe wrapper around pk::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 rewind(&mut self)

清空几何并复位内部字段,与 Self::reset 类似,但 保留 已分配的 SkPath 内部缓冲区(适合反复构建同规模路径)。 Same as SkPath::rewind(): clears geometry and fields like reset, but retains storage for reuse.

Source

pub fn is_empty(&self) -> bool

是否无动词数组(空路径)。与 SkPath::isEmpty 一致(countVerbs() == 0),注意与「无控制点」不同。 True when the path has no verbs (countVerbs() == 0), matching SkPath::isEmpty (not the same as zero 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 bounds(&self) -> Rect

全部控制点的轴对齐包围盒(SkPath::getBounds),含 move 点;通常有缓存,直线轮廓下与 Self::tight_bounds 接近。 AABB of all path points (including moves); SkPath::getBounds(). Often cached; for lines, close to Self::tight_bounds.

Source

pub fn is_finite(&self) -> bool

当且仅当所有控制点坐标均为有限值(无 ±∞、无 NaN)时为真。SkPath::isFinite。 True if every stored coordinate is finite (no infinities or NaNs). SkPath::isFinite.

Source

pub fn is_convex(&self) -> bool

填充时是否为凸区域(可能按需计算并缓存)。SkPath::isConvex。 Whether the filled path is convex (computed lazily if needed). SkPath::isConvex.

Source

pub fn is_oval(&self) -> Option<Rect>

若路径等价于标准椭圆/圆(四段圆锥闭合),返回 Some 外接矩形;否则 NoneSkPath::isOvalSome(bounds) if the path is a circle/oval; None otherwise. SkPath::isOval.

Source

pub fn is_line(&self) -> Option<(Point, Point)>

若路径仅为 move + line(一条开线段),返回 (起点, 终点);否则 NoneSkPath::isLine。 If the path is one open line segment (move + line), returns endpoints; else None. SkPath::isLine.

Source

pub fn points(&self) -> Vec<Point>

按内部顺序拷贝所有控制点(与 Self::get_point 下标一致)。SkPath::getPoints。 Copies all stored points in order (same indexing as Self::get_point). SkPath::getPoints.

Source

pub fn verbs(&self) -> Vec<u8>

拷贝动词序列,每字节为 pk::SkPathVerb 枚举底层值(与 crate::PathVerb 取值一致)。SkPath::getVerbs。 Raw verb bytes matching pk::SkPathVerb / crate::PathVerb. SkPath::getVerbs.

Source

pub fn inc_reserve(&mut self, extra_pt_count: i32)

为即将追加的点预留容量以减小程序分配(extra_pt_count ≤ 0 时忽略)。SkPath::incReserve。 Hints extra point capacity before building; no-op if extra_pt_count <= 0. SkPath::incReserve.

Source

pub fn is_interpolatable_with(&self, other: &Path) -> bool

是否可与 other 做逐点插值(动词种类与点数一致,含圆锥权重)。应先调用再 Self::try_interpolateSkPath::isInterpolatable。 True if paths can be blended pointwise (verbs/point count/conic weights match). SkPath::isInterpolatable.

Source

pub fn try_interpolate(&self, ending: &Path, weight: f32) -> Option<Path>

selfending 之间插值:weight 为 1 偏向起点、0 偏向终点(可超出 [0,1])。不兼容返回 NoneSkPath::interpolate。 Blends points between self (weight toward start) and ending; returns None if incompatible. SkPath::interpolate.

Source

pub fn last_pt(&self) -> Option<Point>

点列末尾坐标;无任何点时 NoneSkPath::getLastPt。 Last point in the point array, or None if empty. SkPath::getLastPt.

Source

pub fn set_last_pt(&mut self, x: f32, y: f32)

修改最后一个点;若当前无点则等价于 move_to(x, y)SkPath::setLastPt。 Updates the last point, or inserts a moveTo if the path is empty. SkPath::setLastPt.

Source

pub fn segment_masks(&self) -> u32

路径中出现过的段类型位或运算结果,与 pk::SkPathSegmentMask 一致:1<<0 line、1<<1 quad、1<<2 conic、1<<3 cubic。 Bitmask of segment kinds present (line/quad/conic/cubic). Matches pk::SkPathSegmentMask.

Source

pub fn has_multiple_contours(&self) -> bool

是否包含多于一条独立轮廓(多于一个起始 move 所隐含的轮廓)。SkPath::hasMultipleContours。 True if the path has more than one contour. SkPath::hasMultipleContours.

Source

pub fn add_path_offset( &mut self, src: &Path, dx: f32, dy: f32, extend: bool, ) -> &mut Self

追加 src 的几何,所有点加上 (dx, dy)extend == true 时若当前轮廓未闭合会先接一条线再拼接(kExtend_AddPathMode)。SkPath::addPath(src, dx, dy, mode)。 Appends src translated by (dx, dy); extend selects append vs extend mode. SkPath::addPath.

Source

pub fn reverse_add_path(&mut self, src: &Path) -> &mut Self

src第一段 轮廓逆序追加到本路径(总是新开轮廓)。SkPath::reverseAddPath。 Appends the first contour of src in reverse. Always starts a new contour. SkPath::reverseAddPath.

Source

pub fn swap(&mut self, other: &mut Self)

以 O(1) 代价交换两条路径的内容(替换底层 UniquePtr,语义等价于 SkPath::swap)。 Exchanges path contents by swapping owning pointers (like SkPath::swap).

Source

pub fn transform(&mut self, matrix: &Matrix)

Matrix 就地变换所有点与权重(含透视矩阵行为,与 SkPath::transform 一致)。 Transforms geometry in place; matches SkPath::transform(const SkMatrix&, this).

Source

pub fn transformed(&self, matrix: &Matrix) -> Path

返回变换后的新路径;self 不变。等价于 SkPath::makeTransform。 Returns a transformed copy; leaves self unchanged. Like SkPath::makeTransform.

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

保守判断是否包含矩形(可能将部分内含矩形判为 false)。 Conservatively tests rect containment; 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.

使用当前 fill_type(新建路径默认为 PathFillType::Winding)。 Uses current fill_type (new paths default to PathFillType::Winding).

Source

pub fn fill_type(&self) -> PathFillType

当前填充规则。Current fill rule.

Source

pub fn set_fill_type(&mut self, ft: PathFillType)

设置填充规则。Sets fill rule.

Source

pub fn is_inverse_fill_type(&self) -> bool

是否为反色填充(InverseWinding / InverseEvenOdd)。 True if fill type is inverse winding or inverse even-odd.

Source

pub fn toggle_inverse_fill_type(&mut self)

在「普通 / 反色」之间切换(WindingInverseWindingEvenOddInverseEvenOdd)。 Toggles between normal and inverse fill (winding/even-odd pairs).

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 conic_to( &mut self, x1: f32, y1: f32, x2: f32, y2: f32, w: f32, ) -> &mut Self

从当前点到 (x2,y2),控制点为 (x1,y1),圆锥权重 ww==1 时可能降为二次曲线)。SkPath::conicTo。 Conic from current point to (x2,y2) with control (x1,y1) and weight w. SkPath::conicTo.

Source

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

(x1,y1)(x2,y2)radius 约束下追加与当前点相切的圆弧(PostScript arct)。需已有轮廓起点。SkPath::arcTo。 Tangent arc through the tangent at (x1,y1) toward (x2,y2) with radius (PostScript arct). SkPath::arcTo.

Source

pub fn add_poly(&mut self, pts: &[Point], close: bool) -> &mut Self

pts[0] 为起点依次连线;pts 为空时行为与 Skia 一致(仅 move 等);close == true 时闭合轮廓。SkPath::addPoly。 Polyline from pts[0]; empty slice uses Skia addPoly semantics; optional close. SkPath::addPoly.

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_oval_with_start( &mut self, rect: &Rect, dir: Direction, start: RectCorner, ) -> &mut Self

添加椭圆,起始点由 start(四角之一)与 dir 决定,与矩形 addRect 角语义一致。SkPath::addOval(rect, dir, start)。 Adds an oval starting at corner start, wound per dir. SkPath::addOval(rect, dir, start).

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
Source§

impl PartialEq for Path

路径相等性,与 pk::SkPath::operator== 一致(填充类型 + 动词/点/圆锥权重数据)。 Path equality per pk::SkPath::operator== (fill type and path ref data).

Source§

fn eq(&self, other: &Self) -> 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 Eq for Path

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.