smooth_frame/input/rect/
mod.rs1mod axis;
2mod corner;
3mod path_builder;
4
5use crate::output::path::SmoothPath;
6use crate::utils::clamp01;
7
8use path_builder::build_rect_path;
9
10#[derive(Debug, Clone, Copy, PartialEq)]
12pub struct SmoothRect {
13 width: f64,
14 height: f64,
15 radius: f64,
16 smoothing: f64,
17}
18
19impl SmoothRect {
20 #[must_use]
24 pub fn new(width: f64, height: f64) -> Self {
25 Self {
26 width,
27 height,
28 radius: 0.0,
29 smoothing: 0.0,
30 }
31 }
32
33 #[must_use]
37 pub fn with_radius(mut self, radius: f64) -> Self {
38 self.radius = radius;
39 self
40 }
41
42 #[must_use]
46 pub fn with_smoothing(mut self, smoothing: f64) -> Self {
47 self.smoothing = smoothing;
48 self
49 }
50
51 #[must_use]
53 pub fn to_path(&self) -> SmoothPath {
54 let width = sanitize_dimension(self.width);
55 let height = sanitize_dimension(self.height);
56 let requested_radius = sanitize_dimension(self.radius);
57 let radius = requested_radius.min(width.min(height) / 2.0);
58 let smoothing = if self.smoothing.is_finite() {
59 clamp01(self.smoothing)
60 } else {
61 0.0
62 };
63
64 build_rect_path(width, height, radius, smoothing)
65 }
66}
67
68fn sanitize_dimension(value: f64) -> f64 {
70 if value.is_finite() && value > 0.0 {
71 value
72 } else {
73 0.0
74 }
75}