Skip to main content

PathBuilder

Struct PathBuilder 

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

路径构造器(多回路,支持 fill 三角化与 stroke 曲线导出)

Implementations§

Source§

impl PathBuilder

Source

pub fn new() -> Self

Source

pub fn transform(&mut self, sx: f32, sy: f32)

对所有已积累的坐标乘 (sx, sy) —— 用于把 viewBox 坐标缩放到屏幕像素。 段内 flatten 容差按 max(|sx|,|sy|) 同步缩放(均匀缩放下严格正确)。

Source

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

Source

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

Source

pub fn quad_to(&mut self, cx: f32, cy: f32, ex: f32, ey: f32, flat: f32)

二次贝塞尔(控制点 cx,cy,终点 ex,ey),flat = 当前坐标空间容差(0.5 / scale)。 存储期保留曲线,fill/paths 导出时才按 flat flatten。

Source

pub fn cubic_to( &mut self, c1x: f32, c1y: f32, c2x: f32, c2y: f32, ex: f32, ey: f32, flat: f32, )

三次贝塞尔(控制点 c1/c2,终点 ex,ey),flat 语义同 quad_to

Source

pub fn arc_to( &mut self, cx: f32, cy: f32, r: f32, start_angle: f32, end_angle: f32, num_segments: u32, )

圆弧(圆心 cx,cy + 半径 r + 起/终角度(弧度) + 分段数上限) 以三次贝塞尔段逼近存储(kappa 圆逼近),fill 导出时 flatten。

  • start_angle/end_angle 标准数学极坐标:0 = +X 轴,逆时针增大
  • num_segments 只是段数上限;实际段数 = ceil(|sweep| / 90°)
  • 自动处理跨过 ±TAU 的情况(end < start 时逆时针走大弧)
Source

pub fn close(&mut self)

Source

pub fn paths(&self) -> Vec<Vec<(f32, f32)>>

导出所有已闭合回路(去掉首尾重复点;曲线段 flatten 成折线)。 需要曲线时请用 curve_contours。

Source

pub fn curve_contours(&self) -> Vec<((f32, f32), Vec<PathSeg>, bool)>

曲线保留导出:每个回路 (起点, 段序列, 是否显式 close)。

与 paths() 的区别:Quad/Cubic 不 flatten,把曲线原样交给曲线感知 消费者(如 tiny-skia PathStroker 的 quad/cubic stroke 路径)——密集折线 逼近会让 stroker 在每个折点发 inner join 毛刺,锐角/密段时互相交叉。

Source

pub fn paths_with_closed(&self) -> Vec<(Vec<(f32, f32)>, bool)>

导出所有回路及其闭合状态:(回路折线, 是否显式 close)。

闭合判定:显式 close 的回路 closed=true;move_to 冲刷的未闭合回路 closed=false。stroke 需要区分开/闭路径(开放路径不补 closing 边)。

Source

pub fn fill(self, color: Color, list: &mut PaintList)

把已闭合回路三角化为 PaintCommand::Triangles 并写进 list。 支持多回路(外轮廓顺时针 + 内洞逆时针的 winding rule)。

Trait Implementations§

Source§

impl Clone for PathBuilder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PathBuilder

Source§

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

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

impl Default for PathBuilder

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Forget for PathBuilder

§

impl Freeze for PathBuilder

§

impl Move for PathBuilder

§

impl RefUnwindSafe for PathBuilder

§

impl Send for PathBuilder
where RawVecInner: Send,

§

impl Sync for PathBuilder
where RawVecInner: Sync,

§

impl Unpin for PathBuilder
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for PathBuilder

§

impl UnwindSafe for PathBuilder
where RawVecInner: UnwindSafe,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.