squid_n_core/section_shape/
label.rs1use super::types::SectionShape;
8
9fn dim(v: f64) -> String {
12 if v.is_finite() && v.fract() == 0.0 {
13 format!("{}", v as i64)
14 } else {
15 let s = format!("{v:.3}");
18 s.trim_end_matches('0').trim_end_matches('.').to_string()
19 }
20}
21
22fn dims(vs: &[f64]) -> String {
24 vs.iter().map(|v| dim(*v)).collect::<Vec<_>>().join("x")
25}
26
27impl SectionShape {
28 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 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}