Skip to main content

smooth_frame/process/corner/
mod.rs

1mod arc;
2mod cubics;
3mod geometry;
4
5use crate::output::path::CubicSegment;
6use crate::process::Processor;
7use crate::types::{Point, Vector};
8
9use cubics::build_cubics;
10use geometry::resolve_geometry;
11
12/// 单个 smooth corner 解析后的参数,便于测试或调试 Sketch 对齐。
13#[derive(Debug, Clone, Copy, PartialEq)]
14pub struct SmoothCornerGeometry {
15    /// 原始角点。
16    pub origin: Point,
17    /// 从角点指向上一条边的单位方向。
18    pub incoming_axis: Vector,
19    /// 从角点指向下一条边的单位方向。
20    pub outgoing_axis: Vector,
21    /// clamp 后实际使用的核心圆半径。
22    pub radius: f64,
23    /// clamp 到 `[0, 1]` 后的平滑系数。
24    pub smoothing: f64,
25    /// incoming 方向的最大影响范围。
26    pub incoming_limit: f64,
27    /// outgoing 方向的最大影响范围。
28    pub outgoing_limit: f64,
29    /// incoming 与 outgoing 方向之间的夹角,单位为弧度。
30    pub angle: f64,
31    /// 核心圆在未平滑时的切点距离。
32    pub base_tangent: f64,
33    /// incoming 方向最终影响范围。
34    pub incoming_influence: f64,
35    /// outgoing 方向最终影响范围。
36    pub outgoing_influence: f64,
37    /// incoming 侧过渡角,单位为弧度。
38    pub alpha0: f64,
39    /// outgoing 侧过渡角,单位为弧度。
40    pub alpha1: f64,
41    /// 中间圆弧段角度,单位为弧度。
42    pub middle_arc_angle: f64,
43    /// 角点 smooth cubic 的起点。
44    pub start: Point,
45    /// 角点 smooth cubic 的终点。
46    pub end: Point,
47}
48
49#[derive(Debug, Clone, Copy, PartialEq)]
50pub(crate) struct SmoothCornerRequest {
51    pub(crate) origin: Point,
52    pub(crate) incoming_axis: Vector,
53    pub(crate) outgoing_axis: Vector,
54    pub(crate) radius: f64,
55    pub(crate) smoothing: f64,
56    pub(crate) incoming_limit: f64,
57    pub(crate) outgoing_limit: f64,
58    pub(crate) angle: f64,
59}
60
61#[derive(Debug, Clone, PartialEq)]
62pub(crate) struct ProcessedSmoothCorner {
63    pub(crate) geometry: SmoothCornerGeometry,
64    pub(crate) cubics: Vec<CubicSegment>,
65}
66
67#[derive(Debug, Clone, Copy, PartialEq)]
68pub(crate) struct SmoothCornerProcessor {
69    request: SmoothCornerRequest,
70}
71
72impl SmoothCornerProcessor {
73    pub(crate) fn new(request: SmoothCornerRequest) -> Self {
74        Self { request }
75    }
76}
77
78impl Processor for SmoothCornerProcessor {
79    type Output = ProcessedSmoothCorner;
80
81    fn process(&self) -> Self::Output {
82        let geometry = resolve_geometry(self.request);
83        let cubics = build_cubics(geometry);
84        ProcessedSmoothCorner { geometry, cubics }
85    }
86}