pub struct SmoothRect { /* private fields */ }Expand description
矩形便捷封装。
Implementations§
Source§impl SmoothRect
impl SmoothRect
Sourcepub fn new(width: f64, height: f64) -> Self
pub fn new(width: f64, height: f64) -> Self
创建矩形便捷封装。
宽高为非有限数、负数或零时会退化为单点闭合路径。
Examples found in repository?
examples/demo/main.rs (line 28)
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 with_radius(self, radius: f64) -> Self
pub fn with_radius(self, radius: f64) -> Self
设置矩形角半径。
负数或非有限数会按 0 处理,过大的半径会 clamp 到短边的一半。
Examples found in repository?
examples/demo/main.rs (line 29)
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 with_smoothing(self, smoothing: f64) -> Self
pub fn with_smoothing(self, smoothing: f64) -> Self
设置 Sketch-like smoothing。
有限数会 clamp 到 [0, 1],非有限数会按 0 处理。
Examples found in repository?
examples/demo/main.rs (line 30)
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 to_path(&self) -> SmoothPath
pub fn to_path(&self) -> SmoothPath
生成矩形 smooth corner 路径。
Examples found in repository?
examples/demo/main.rs (line 31)
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 SmoothRect
impl Clone for SmoothRect
Source§fn clone(&self) -> SmoothRect
fn clone(&self) -> SmoothRect
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 SmoothRect
impl Debug for SmoothRect
Source§impl PartialEq for SmoothRect
impl PartialEq for SmoothRect
Source§fn eq(&self, other: &SmoothRect) -> bool
fn eq(&self, other: &SmoothRect) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Copy for SmoothRect
impl StructuralPartialEq for SmoothRect
Auto Trait Implementations§
impl Freeze for SmoothRect
impl RefUnwindSafe for SmoothRect
impl Send for SmoothRect
impl Sync for SmoothRect
impl Unpin for SmoothRect
impl UnsafeUnpin for SmoothRect
impl UnwindSafe for SmoothRect
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