Skip to main content

squid_n_core/section_shape/
label.rs

1//! 断面形状の寸法表記([`SectionShape::dimension_label`])。
2//!
3//! 断面リスト上で形状と各寸法を 1 つの文字列で示すための表記で、記号は
4//! ASCII のみを用いる。表記の一覧と各記号の意味は
5//! `docs/model_io/断面形状の表記.md` を参照。
6
7use super::types::SectionShape;
8
9/// 寸法 1 つの表記。整数値は小数点以下を落とし、端数のある値はそのまま出す
10/// (`300.0` → `300`、`6.5` → `6.5`、`216.3` → `216.3`)。
11fn dim(v: f64) -> String {
12    if v.is_finite() && v.fract() == 0.0 {
13        format!("{}", v as i64)
14    } else {
15        // 冷間成形材の板厚 3.2 のように小数第 1 位までで足りるが、
16        // 丸めで別寸法が同じ表記になるのを避けるため 3 桁まで許し末尾 0 を落とす。
17        let s = format!("{v:.3}");
18        s.trim_end_matches('0').trim_end_matches('.').to_string()
19    }
20}
21
22/// 寸法列を `x` で連結する(`H-` などの接頭辞は呼び出し側が付ける)。
23fn dims(vs: &[f64]) -> String {
24    vs.iter().map(|v| dim(*v)).collect::<Vec<_>>().join("x")
25}
26
27impl SectionShape {
28    /// 形状と各寸法を表す表記(例 `H-500x250x9x16`・`BD-300x600`)。
29    ///
30    /// 記号は ASCII のみで、断面の種別が接頭辞から一意に読み取れるようにしている。
31    /// 円形は用途で記号を分ける(鋼管 `P-`、中実丸鋼 `RB-`、RC 円形 `RD-`)。
32    /// SRC は内蔵鉄骨の寸法まで含める(外形が同じで内蔵鉄骨だけが違う断面を
33    /// 表記で見分けられるようにするため)。
34    pub fn dimension_label(&self) -> String {
35        match self {
36            SectionShape::SteelH {
37                height,
38                width,
39                web_thick,
40                flange_thick,
41            } => format!("H-{}", dims(&[*height, *width, *web_thick, *flange_thick])),
42            SectionShape::SteelBuiltH {
43                height,
44                upper_width,
45                upper_thick,
46                lower_width,
47                lower_thick,
48                web_thick,
49            } => format!(
50                "BH-{}",
51                dims(&[
52                    *height,
53                    *upper_width,
54                    *upper_thick,
55                    *lower_width,
56                    *lower_thick,
57                    *web_thick,
58                ])
59            ),
60            // 角部外半径 r は表記に含めない(断面性能ではなくせん断有効断面積の
61            // 補正にのみ用いる寸法で、表記に入れると列が長くなるため)。
62            SectionShape::SteelBox {
63                height,
64                width,
65                thick,
66                ..
67            } => format!("BOX-{}", dims(&[*height, *width, *thick])),
68            SectionShape::SteelPipe { outer_dia, thick } => {
69                format!("P-{}", dims(&[*outer_dia, *thick]))
70            }
71            SectionShape::SteelAngle {
72                leg_a,
73                leg_b,
74                thick,
75            } => format!("L-{}", dims(&[*leg_a, *leg_b, *thick])),
76            SectionShape::SteelChannel {
77                height,
78                width,
79                web_thick,
80                flange_thick,
81            } => format!("CH-{}", dims(&[*height, *width, *web_thick, *flange_thick])),
82            SectionShape::SteelLipChannel {
83                height,
84                width,
85                lip,
86                thick,
87            } => format!("LC-{}", dims(&[*height, *width, *lip, *thick])),
88            SectionShape::SteelTee {
89                height,
90                width,
91                web_thick,
92                flange_thick,
93            } => format!("T-{}", dims(&[*height, *width, *web_thick, *flange_thick])),
94            SectionShape::SteelFlatBar { width, thick } => {
95                format!("FB-{}", dims(&[*width, *thick]))
96            }
97            SectionShape::SteelRoundBar { dia } => format!("RB-{}", dim(*dia)),
98            SectionShape::RcRect { b, d, .. } => format!("BD-{}", dims(&[*b, *d])),
99            SectionShape::RcCircle { d, .. } => format!("RD-{}", dim(*d)),
100            SectionShape::SrcRect {
101                b,
102                d,
103                steel_height,
104                steel_width,
105                steel_web_thick,
106                steel_flange_thick,
107                ..
108            } => format!(
109                "SRC-{}+H-{}",
110                dims(&[*b, *d]),
111                dims(&[
112                    *steel_height,
113                    *steel_width,
114                    *steel_web_thick,
115                    *steel_flange_thick,
116                ])
117            ),
118            SectionShape::CftBox {
119                height,
120                width,
121                thick,
122            } => format!("CFT-BOX-{}", dims(&[*height, *width, *thick])),
123            SectionShape::CftPipe { outer_dia, thick } => {
124                format!("CFT-P-{}", dims(&[*outer_dia, *thick]))
125            }
126            SectionShape::RcWall { thickness, .. } => format!("W-t{}", dim(*thickness)),
127            SectionShape::RcSlab { thickness } => format!("S-t{}", dim(*thickness)),
128        }
129    }
130}