pub struct SmoothPath { /* private fields */ }Expand description
平滑路径。
Implementations§
Source§impl SmoothPath
impl SmoothPath
Sourcepub fn commands(&self) -> &[PathCommand]
pub fn commands(&self) -> &[PathCommand]
返回底层路径命令。
Examples found in repository?
examples/demo/main.rs (line 51)
14fn main() {
15 let config = match parse_args(env::args().skip(1)) {
16 Ok(Some(config)) => config,
17 Ok(None) => return,
18 Err(message) => {
19 eprintln!("参数错误:{message}");
20 eprintln!("运行 `cargo run --example demo -- --help` 查看用法。");
21 process::exit(2);
22 }
23 };
24
25 let drawable_width = drawable_dimension(config.width, config.border_width);
26 let drawable_height = drawable_dimension(config.height, config.border_width);
27 let radius = effective_radius(&config);
28 let path = SmoothRect::new(drawable_width, drawable_height)
29 .with_radius(radius)
30 .with_smoothing(config.smoothing)
31 .to_path();
32 let path_data = path.to_svg_path_with_precision(config.precision);
33
34 if let Some(output) = config.output.as_ref() {
35 let svg = render_svg(&config, &path_data);
36 if let Err(error) = fs::write(output, svg) {
37 eprintln!("写入 SVG 文件失败:{}:{error}", output.display());
38 process::exit(1);
39 }
40 println!("已生成 SVG 文件:{}", output.display());
41 } else if config.svg {
42 println!("{}", render_svg(&config, &path_data));
43 } else {
44 println!("SVG 宽度:{}", format_number(config.width));
45 println!("SVG 高度:{}", format_number(config.height));
46 println!("路径宽度:{}", format_number(drawable_width));
47 println!("路径高度:{}", format_number(drawable_height));
48 println!("半径:{}", format_number(radius));
49 println!("平滑:{}", format_number(config.smoothing));
50 println!("边框:{}", format_number(config.border_width));
51 println!("命令数:{}", path.commands().len());
52 println!("SVG path:{path_data}");
53 }
54}Sourcepub fn cubics(&self) -> Vec<CubicSegment>
pub fn cubics(&self) -> Vec<CubicSegment>
提取路径中的所有 cubic 段。
Sourcepub fn export_with<F>(&self, formatter: &F) -> F::Outputwhere
F: PathFormatter + ?Sized,
pub fn export_with<F>(&self, formatter: &F) -> F::Outputwhere
F: PathFormatter + ?Sized,
使用指定 formatter 导出路径。
这是输出层的主要扩展点:调用方可以实现 PathFormatter,把同一组
PathCommand 转换成 SVG、Godot、Canvas 或自定义函数调用格式。
Sourcepub fn to_svg_path(&self) -> String
pub fn to_svg_path(&self) -> String
以默认 6 位小数输出 SVG path data。
Sourcepub fn to_svg_path_with_precision(&self, precision: usize) -> String
pub fn to_svg_path_with_precision(&self, precision: usize) -> String
按指定小数位数输出 SVG path data,最多保留 12 位。
Examples found in repository?
examples/demo/main.rs (line 32)
14fn main() {
15 let config = match parse_args(env::args().skip(1)) {
16 Ok(Some(config)) => config,
17 Ok(None) => return,
18 Err(message) => {
19 eprintln!("参数错误:{message}");
20 eprintln!("运行 `cargo run --example demo -- --help` 查看用法。");
21 process::exit(2);
22 }
23 };
24
25 let drawable_width = drawable_dimension(config.width, config.border_width);
26 let drawable_height = drawable_dimension(config.height, config.border_width);
27 let radius = effective_radius(&config);
28 let path = SmoothRect::new(drawable_width, drawable_height)
29 .with_radius(radius)
30 .with_smoothing(config.smoothing)
31 .to_path();
32 let path_data = path.to_svg_path_with_precision(config.precision);
33
34 if let Some(output) = config.output.as_ref() {
35 let svg = render_svg(&config, &path_data);
36 if let Err(error) = fs::write(output, svg) {
37 eprintln!("写入 SVG 文件失败:{}:{error}", output.display());
38 process::exit(1);
39 }
40 println!("已生成 SVG 文件:{}", output.display());
41 } else if config.svg {
42 println!("{}", render_svg(&config, &path_data));
43 } else {
44 println!("SVG 宽度:{}", format_number(config.width));
45 println!("SVG 高度:{}", format_number(config.height));
46 println!("路径宽度:{}", format_number(drawable_width));
47 println!("路径高度:{}", format_number(drawable_height));
48 println!("半径:{}", format_number(radius));
49 println!("平滑:{}", format_number(config.smoothing));
50 println!("边框:{}", format_number(config.border_width));
51 println!("命令数:{}", path.commands().len());
52 println!("SVG path:{path_data}");
53 }
54}Trait Implementations§
Source§impl Clone for SmoothPath
impl Clone for SmoothPath
Source§fn clone(&self) -> SmoothPath
fn clone(&self) -> SmoothPath
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SmoothPath
impl Debug for SmoothPath
Source§impl Default for SmoothPath
impl Default for SmoothPath
Source§fn default() -> SmoothPath
fn default() -> SmoothPath
Returns the “default value” for a type. Read more
Source§impl PartialEq for SmoothPath
impl PartialEq for SmoothPath
Source§fn eq(&self, other: &SmoothPath) -> bool
fn eq(&self, other: &SmoothPath) -> bool
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for SmoothPath
Auto Trait Implementations§
impl Freeze for SmoothPath
impl RefUnwindSafe for SmoothPath
impl Send for SmoothPath
impl Sync for SmoothPath
impl Unpin for SmoothPath
impl UnsafeUnpin for SmoothPath
impl UnwindSafe for SmoothPath
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more