path-kit
基于 Skia PathOps 和 PathKit 的 Rust 路径运算库,提供 safe 的 API 封装。
A Rust path operations library based on Skia PathOps and PathKit with safe API wrappers.
功能 / Features
- 路径构建:线段、二次/三次贝塞尔、矩形、椭圆、圆、圆角矩形、RRect(四角独立半径)
- 路径布尔运算:并集、交集、差集、异或
- 路径简化、包围盒:
simplify,path.tight_bounds,pathops_tight_bounds - 路径迭代:按动词遍历 Move/Line/Quad/Cubic/Close
- 描边:将路径转为描边轮廓
线程安全 / Thread safety
当前未保证 Send / Sync,请勿跨线程共享 Path、RRect、StrokeRec 等类型。
Send / Sync are not guaranteed; do not share Path, RRect, StrokeRec, etc. across threads.
安装 / Installation
[]
= "0.1"
示例 / Examples
路径布尔运算
use ;
let mut path1 = new;
path1.add_rect;
let mut path2 = new;
path2.add_rect;
let union = path_op.unwrap;
// 批量运算
let result = new
.add
.add
.resolve
.unwrap;
圆角矩形 RRect
use ;
// 统一圆角
let rr = from_rect_xy;
let mut path = new;
path.add_rrect;
// 四角独立半径
let radii = ;
let rr2 = from_rect_radii;
path.add_rrect;
路径迭代
use ;
let mut path = new;
path.move_to.line_to.line_to.close;
for item in path.iter
描边
use ;
let rec = new_stroke;
let mut path = new;
path.move_to.line_to;
let stroked = rec.apply_to_path.unwrap;
致谢 / Acknowledgments
感谢以下开源项目:
- Skia — 2D 图形库,本库的 PathOps 能力源自 Skia
- libpag/pathkit — 从 Skia 提取的 PathOps 库,提供轻量级 PathOps API
Thanks to:
- Skia — 2D graphics library, PathOps capabilities originate from Skia
- libpag/pathkit — PathOps library extracted from Skia, providing a lightweight PathOps API
License
BSD-3-Clause (与 Skia 一致 / Same as Skia)