use std::fmt::Write as _;
use crate::svg::parity::flowchart::escape_attr;
use crate::svg::parity::{fmt, fmt_display};
use super::super::geom::{arc_points, path_from_points};
use super::super::roughjs::roughjs_hachure_paths_for_svg_path;
const FLOWCHART_NODE_HAND_DRAWN_ROUGHNESS: f32 = 0.7;
const FLOWCHART_NODE_HAND_DRAWN_FILL_WEIGHT: f32 = 4.0;
const FLOWCHART_NODE_HAND_DRAWN_HACHURE_GAP: f32 = 5.2;
pub(in crate::svg::parity::flowchart::render::node) fn render_rounded_rect(
out: &mut String,
_ctx: &crate::svg::parity::flowchart::types::FlowchartRenderCtx<'_>,
common: &super::super::FlowchartNodeRenderCommon<'_>,
details: &mut crate::svg::parity::flowchart::types::FlowchartRenderDetails,
) {
let w = common.layout_node.width.max(1.0);
let h = common.layout_node.height.max(1.0);
let radius = 5.0;
let taper = 5.0;
let mut pts: Vec<(f64, f64)> = Vec::new();
pts.push((-w / 2.0 + taper, -h / 2.0));
pts.push((w / 2.0 - taper, -h / 2.0));
pts.extend(arc_points(
w / 2.0 - taper,
-h / 2.0,
w / 2.0,
-h / 2.0 + taper,
radius,
radius,
true,
));
pts.push((w / 2.0, -h / 2.0 + taper));
pts.push((w / 2.0, h / 2.0 - taper));
pts.extend(arc_points(
w / 2.0,
h / 2.0 - taper,
w / 2.0 - taper,
h / 2.0,
radius,
radius,
true,
));
pts.push((w / 2.0 - taper, h / 2.0));
pts.push((-w / 2.0 + taper, h / 2.0));
pts.extend(arc_points(
-w / 2.0 + taper,
h / 2.0,
-w / 2.0,
h / 2.0 - taper,
radius,
radius,
true,
));
pts.push((-w / 2.0, h / 2.0 - taper));
pts.push((-w / 2.0, -h / 2.0 + taper));
pts.extend(arc_points(
-w / 2.0,
-h / 2.0 + taper,
-w / 2.0 + taper,
-h / 2.0,
radius,
radius,
true,
));
let path_data = path_from_points(&pts);
let rough_paths = if common.look_is_hand_drawn() {
super::super::helpers::timed_node_roughjs(common.timing_enabled, details, || {
roughjs_hachure_paths_for_svg_path(
&path_data,
common.fill_color,
common.stroke_color,
common.stroke_width,
common.stroke_dasharray,
FLOWCHART_NODE_HAND_DRAWN_FILL_WEIGHT,
FLOWCHART_NODE_HAND_DRAWN_HACHURE_GAP,
FLOWCHART_NODE_HAND_DRAWN_ROUGHNESS,
common.hand_drawn_seed,
)
})
} else {
None
};
if let Some((fill_d, stroke_d)) = rough_paths {
let _ = write!(
out,
r#"<g class="basic label-container" style="{}">"#,
escape_attr(common.rough_group_style)
);
let _ = write!(
out,
r#"<path d="{}" stroke="{}" stroke-width="{}" fill="none" stroke-dasharray="0 0"/>"#,
escape_attr(&fill_d),
escape_attr(common.fill_color),
fmt_display(FLOWCHART_NODE_HAND_DRAWN_FILL_WEIGHT as f64),
);
let _ = write!(
out,
r#"<path d="{}" stroke="{}" stroke-width="{}" fill="none" stroke-dasharray="{}"/>"#,
escape_attr(&stroke_d),
escape_attr(common.stroke_color),
common.stroke_width,
escape_attr(common.stroke_dasharray),
);
out.push_str("</g>");
} else {
let _ = write!(
out,
r#"<rect class="basic label-container" style="{}" x="{}" y="{}" width="{}" height="{}" rx="5" ry="5"/>"#,
escape_attr(common.style),
fmt(-w / 2.0),
fmt(-h / 2.0),
fmt(w),
fmt(h)
);
}
}