mod axis;
mod corner;
mod path_builder;
use crate::output::path::SmoothPath;
use crate::utils::clamp01;
use path_builder::build_rect_path;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SmoothRect {
width: f64,
height: f64,
radius: f64,
smoothing: f64,
}
impl SmoothRect {
#[must_use]
pub fn new(width: f64, height: f64) -> Self {
Self {
width,
height,
radius: 0.0,
smoothing: 0.0,
}
}
#[must_use]
pub fn with_radius(mut self, radius: f64) -> Self {
self.radius = radius;
self
}
#[must_use]
pub fn with_smoothing(mut self, smoothing: f64) -> Self {
self.smoothing = smoothing;
self
}
#[must_use]
pub fn to_path(&self) -> SmoothPath {
let width = sanitize_dimension(self.width);
let height = sanitize_dimension(self.height);
let requested_radius = sanitize_dimension(self.radius);
let radius = requested_radius.min(width.min(height) / 2.0);
let smoothing = if self.smoothing.is_finite() {
clamp01(self.smoothing)
} else {
0.0
};
build_rect_path(width, height, radius, smoothing)
}
}
fn sanitize_dimension(value: f64) -> f64 {
if value.is_finite() && value > 0.0 {
value
} else {
0.0
}
}