pub struct Path { /* private fields */ }Expand description
路径的 safe 封装,底层为 C++ pk::SkPath。
Safe wrapper around pk::SkPath.
Implementations§
Source§impl Path
impl Path
Sourcepub fn rewind(&mut self)
pub fn rewind(&mut self)
清空几何并复位内部字段,与 Self::reset 类似,但 保留 已分配的 SkPath 内部缓冲区(适合反复构建同规模路径)。
Same as SkPath::rewind(): clears geometry and fields like reset, but retains storage for reuse.
Sourcepub fn is_empty(&self) -> bool
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).
Sourcepub fn count_points(&self) -> i32
pub fn count_points(&self) -> i32
点的数量。Returns the number of points in the path.
Sourcepub fn count_verbs(&self) -> i32
pub fn count_verbs(&self) -> i32
动词的数量。Returns the number of verbs (move, line, quad, cubic, close).
Sourcepub fn iter(&self, force_close: bool) -> PathIter<'_> ⓘ
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.
Sourcepub fn get_point(&self, index: i32) -> Option<Point>
pub fn get_point(&self, index: i32) -> Option<Point>
获取第 i 个点。Returns the point at index, or None if out of range.
Sourcepub fn tight_bounds(&self) -> Rect
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.
Sourcepub fn bounds(&self) -> Rect
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.
Sourcepub fn is_finite(&self) -> bool
pub fn is_finite(&self) -> bool
当且仅当所有控制点坐标均为有限值(无 ±∞、无 NaN)时为真。SkPath::isFinite。
True if every stored coordinate is finite (no infinities or NaNs). SkPath::isFinite.
Sourcepub fn is_convex(&self) -> bool
pub fn is_convex(&self) -> bool
填充时是否为凸区域(可能按需计算并缓存)。SkPath::isConvex。
Whether the filled path is convex (computed lazily if needed). SkPath::isConvex.
Sourcepub fn is_oval(&self) -> Option<Rect>
pub fn is_oval(&self) -> Option<Rect>
若路径等价于标准椭圆/圆(四段圆锥闭合),返回 Some 外接矩形;否则 None。SkPath::isOval。
Some(bounds) if the path is a circle/oval; None otherwise. SkPath::isOval.
Sourcepub fn is_line(&self) -> Option<(Point, Point)>
pub fn is_line(&self) -> Option<(Point, Point)>
若路径仅为 move + line(一条开线段),返回 (起点, 终点);否则 None。SkPath::isLine。
If the path is one open line segment (move + line), returns endpoints; else None. SkPath::isLine.
Sourcepub fn points(&self) -> Vec<Point>
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.
Sourcepub fn verbs(&self) -> Vec<u8> ⓘ
pub fn verbs(&self) -> Vec<u8> ⓘ
拷贝动词序列,每字节为 pk::SkPathVerb 枚举底层值(与 crate::PathVerb 取值一致)。SkPath::getVerbs。
Raw verb bytes matching pk::SkPathVerb / crate::PathVerb. SkPath::getVerbs.
Sourcepub fn inc_reserve(&mut self, extra_pt_count: i32)
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.
Sourcepub fn is_interpolatable_with(&self, other: &Path) -> bool
pub fn is_interpolatable_with(&self, other: &Path) -> bool
是否可与 other 做逐点插值(动词种类与点数一致,含圆锥权重)。应先调用再 Self::try_interpolate。SkPath::isInterpolatable。
True if paths can be blended pointwise (verbs/point count/conic weights match). SkPath::isInterpolatable.
Sourcepub fn try_interpolate(&self, ending: &Path, weight: f32) -> Option<Path>
pub fn try_interpolate(&self, ending: &Path, weight: f32) -> Option<Path>
在 self 与 ending 之间插值:weight 为 1 偏向起点、0 偏向终点(可超出 [0,1])。不兼容返回 None。SkPath::interpolate。
Blends points between self (weight toward start) and ending; returns None if incompatible. SkPath::interpolate.
Sourcepub fn last_pt(&self) -> Option<Point>
pub fn last_pt(&self) -> Option<Point>
点列末尾坐标;无任何点时 None。SkPath::getLastPt。
Last point in the point array, or None if empty. SkPath::getLastPt.
Sourcepub fn set_last_pt(&mut self, x: f32, y: f32)
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.
Sourcepub fn segment_masks(&self) -> u32
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.
Sourcepub fn has_multiple_contours(&self) -> bool
pub fn has_multiple_contours(&self) -> bool
是否包含多于一条独立轮廓(多于一个起始 move 所隐含的轮廓)。SkPath::hasMultipleContours。
True if the path has more than one contour. SkPath::hasMultipleContours.
Sourcepub fn add_path_offset(
&mut self,
src: &Path,
dx: f32,
dy: f32,
extend: bool,
) -> &mut Self
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.
Sourcepub fn reverse_add_path(&mut self, src: &Path) -> &mut Self
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.
Sourcepub fn swap(&mut self, other: &mut Self)
pub fn swap(&mut self, other: &mut Self)
以 O(1) 代价交换两条路径的内容(替换底层 UniquePtr,语义等价于 SkPath::swap)。
Exchanges path contents by swapping owning pointers (like SkPath::swap).
Sourcepub fn transform(&mut self, matrix: &Matrix)
pub fn transform(&mut self, matrix: &Matrix)
按 Matrix 就地变换所有点与权重(含透视矩阵行为,与 SkPath::transform 一致)。
Transforms geometry in place; matches SkPath::transform(const SkMatrix&, this).
Sourcepub fn transformed(&self, matrix: &Matrix) -> Path
pub fn transformed(&self, matrix: &Matrix) -> Path
返回变换后的新路径;self 不变。等价于 SkPath::makeTransform。
Returns a transformed copy; leaves self unchanged. Like SkPath::makeTransform.
Sourcepub fn is_last_contour_closed(&self) -> bool
pub fn is_last_contour_closed(&self) -> bool
最后一段轮廓是否闭合。Returns true if the last contour ends with close().
Sourcepub fn conservatively_contains_rect(&self, rect: &Rect) -> bool
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.
Sourcepub fn is_rect(&self) -> Option<(Rect, bool)>
pub fn is_rect(&self) -> Option<(Rect, bool)>
是否可表示为矩形。Returns Some((rect, is_closed)) if path is a rect, None otherwise.
Sourcepub fn contains(&self, x: f32, y: f32) -> bool
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).
Sourcepub fn fill_type(&self) -> PathFillType
pub fn fill_type(&self) -> PathFillType
当前填充规则。Current fill rule.
Sourcepub fn set_fill_type(&mut self, ft: PathFillType)
pub fn set_fill_type(&mut self, ft: PathFillType)
设置填充规则。Sets fill rule.
Sourcepub fn is_inverse_fill_type(&self) -> bool
pub fn is_inverse_fill_type(&self) -> bool
是否为反色填充(InverseWinding / InverseEvenOdd)。
True if fill type is inverse winding or inverse even-odd.
Sourcepub fn toggle_inverse_fill_type(&mut self)
pub fn toggle_inverse_fill_type(&mut self)
在「普通 / 反色」之间切换(Winding ↔ InverseWinding,EvenOdd ↔ InverseEvenOdd)。
Toggles between normal and inverse fill (winding/even-odd pairs).
Sourcepub fn move_to(&mut self, x: f32, y: f32) -> &mut Self
pub fn move_to(&mut self, x: f32, y: f32) -> &mut Self
移动到 (x, y),开始新轮廓。Moves to (x, y) and starts a new contour.
Sourcepub fn line_to(&mut self, x: f32, y: f32) -> &mut Self
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.
Sourcepub fn quad_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32) -> &mut Self
pub fn quad_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32) -> &mut Self
二次贝塞尔曲线。Adds a quadratic bezier (control point, end point).
Sourcepub fn cubic_to(
&mut self,
x1: f32,
y1: f32,
x2: f32,
y2: f32,
x3: f32,
y3: f32,
) -> &mut Self
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).
Sourcepub fn conic_to(
&mut self,
x1: f32,
y1: f32,
x2: f32,
y2: f32,
w: f32,
) -> &mut Self
pub fn conic_to( &mut self, x1: f32, y1: f32, x2: f32, y2: f32, w: f32, ) -> &mut Self
从当前点到 (x2,y2),控制点为 (x1,y1),圆锥权重 w(w==1 时可能降为二次曲线)。SkPath::conicTo。
Conic from current point to (x2,y2) with control (x1,y1) and weight w. SkPath::conicTo.
Sourcepub fn arc_to(
&mut self,
x1: f32,
y1: f32,
x2: f32,
y2: f32,
radius: f32,
) -> &mut Self
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.
Sourcepub fn add_poly(&mut self, pts: &[Point], close: bool) -> &mut Self
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.
Sourcepub fn close(&mut self) -> &mut Self
pub fn close(&mut self) -> &mut Self
闭合当前轮廓。Closes the current contour (line back to first point).
Sourcepub fn add_rect(
&mut self,
rect: &Rect,
dir: Direction,
start: RectCorner,
) -> &mut Self
pub fn add_rect( &mut self, rect: &Rect, dir: Direction, start: RectCorner, ) -> &mut Self
添加矩形。Adds a rectangle as a closed contour.
Sourcepub fn add_oval(&mut self, rect: &Rect, dir: Direction) -> &mut Self
pub fn add_oval(&mut self, rect: &Rect, dir: Direction) -> &mut Self
添加椭圆(由矩形包围)。Adds an oval (ellipse) bounded by the given rect.
Sourcepub fn add_oval_with_start(
&mut self,
rect: &Rect,
dir: Direction,
start: RectCorner,
) -> &mut Self
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).
Sourcepub fn add_circle(
&mut self,
cx: f32,
cy: f32,
radius: f32,
dir: Direction,
) -> &mut Self
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.
Sourcepub fn add_round_rect(
&mut self,
rect: &Rect,
rx: f32,
ry: f32,
dir: Direction,
) -> &mut Self
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.
Sourcepub fn add_rrect(&mut self, rrect: &RRect, dir: Direction) -> &mut Self
pub fn add_rrect(&mut self, rrect: &RRect, dir: Direction) -> &mut Self
添加 RRect(支持四角独立半径)。Adds RRect with per-corner radii.
Sourcepub fn add_rrect_with_start(
&mut self,
rrect: &RRect,
dir: Direction,
start: RectCorner,
) -> &mut Self
pub fn add_rrect_with_start( &mut self, rrect: &RRect, dir: Direction, start: RectCorner, ) -> &mut Self
添加 RRect 并指定起始角。Adds RRect with start corner.
Trait Implementations§
Source§impl PartialEq for Path
路径相等性,与 pk::SkPath::operator== 一致(填充类型 + 动词/点/圆锥权重数据)。
Path equality per pk::SkPath::operator== (fill type and path ref data).
impl PartialEq for Path
路径相等性,与 pk::SkPath::operator== 一致(填充类型 + 动词/点/圆锥权重数据)。
Path equality per pk::SkPath::operator== (fill type and path ref data).