Skip to main content

section_properties/section_library/
cold_formed.rs

1//! Cold-formed steel sections (EN 1993-1-3, AISI S100, GB/T 6723, etc.).
2//!
3//! Includes lipped channels, Z-sections, hat sections, and custom profiles.
4
5use crate::geometry::{Point, Polygon};
6use crate::material::Material;
7use crate::section::Section;
8use crate::section_library::ParametricSection;
9
10/// Cold-formed lipped channel (C-section with lips).
11#[derive(Debug, Clone, Copy, PartialEq)]
12pub struct LippedChannel {
13    pub depth: f64,        // h - overall depth
14    pub flange_width: f64, // b - flange width
15    pub lip_length: f64,   // c - lip length
16    pub thickness: f64,    // t - thickness
17    pub inner_radius: f64, // r - inner bend radius
18    pub outer_radius: f64, // r + t
19}
20
21impl LippedChannel {
22    pub fn new(
23        depth: f64,
24        flange_width: f64,
25        lip_length: f64,
26        thickness: f64,
27        inner_radius: f64,
28    ) -> Self {
29        assert!(depth > 0.0 && flange_width > 0.0 && lip_length >= 0.0 && thickness > 0.0);
30        assert!(
31            2.0 * thickness < depth && thickness < flange_width && thickness < lip_length + 1e-9
32        );
33        Self {
34            depth,
35            flange_width,
36            lip_length,
37            thickness,
38            inner_radius,
39            outer_radius: inner_radius + thickness,
40        }
41    }
42
43    /// Standard sizes per EN 1993-1-3 / GB/T 6723
44    pub fn from_designation(designation: &str) -> Option<Self> {
45        // Format: "LC{d}h{b}l{c}t{t}r{r}" or standard codes
46        let dims = match designation.to_uppercase().as_str() {
47            // GB/T 6723 Cold-formed equal-leg lipped channels
48            "LC80X40X15X2.0" => (80.0, 40.0, 15.0, 2.0, 3.0),
49            "LC100X50X15X2.0" => (100.0, 50.0, 15.0, 2.0, 3.0),
50            "LC100X50X20X2.5" => (100.0, 50.0, 20.0, 2.5, 4.0),
51            "LC120X50X20X2.5" => (120.0, 50.0, 20.0, 2.5, 4.0),
52            "LC140X60X20X3.0" => (140.0, 60.0, 20.0, 3.0, 4.5),
53            "LC150X50X20X2.5" => (150.0, 50.0, 20.0, 2.5, 4.0),
54            "LC160X60X20X3.0" => (160.0, 60.0, 20.0, 3.0, 4.5),
55            "LC180X60X25X3.0" => (180.0, 60.0, 25.0, 3.0, 4.5),
56            "LC200X70X25X3.0" => (200.0, 70.0, 25.0, 3.0, 5.0),
57            "LC200X75X25X3.0" => (200.0, 75.0, 25.0, 3.0, 5.0),
58            "LC220X70X25X3.0" => (220.0, 70.0, 25.0, 3.0, 5.0),
59            "LC250X75X30X3.0" => (250.0, 75.0, 30.0, 3.0, 5.0),
60            "LC300X90X30X4.0" => (300.0, 90.0, 30.0, 4.0, 6.0),
61
62            // AISI standard lipped channels
63            "LC350S162-33" => (88.9, 41.1, 12.7, 0.84, 2.5), // 3.5" x 1.625" x 0.125" x 33mil
64            "LC350S162-43" => (88.9, 41.1, 12.7, 1.09, 3.3),
65            "LC350S162-54" => (88.9, 41.1, 12.7, 1.37, 4.1),
66            "LC350S162-68" => (88.9, 41.1, 12.7, 1.73, 5.2),
67            "LC350S162-97" => (88.9, 41.1, 12.7, 2.46, 7.4),
68            "LC550S162-43" => (139.7, 41.1, 12.7, 1.09, 3.3),
69            "LC550S162-54" => (139.7, 41.1, 12.7, 1.37, 4.1),
70            "LC550S162-68" => (139.7, 41.1, 12.7, 1.73, 5.2),
71            "LC800S162-54" => (203.2, 41.1, 12.7, 1.37, 4.1),
72            "LC800S162-68" => (203.2, 41.1, 12.7, 1.73, 5.2),
73            "LC1000S162-68" => (254.0, 41.1, 12.7, 1.73, 5.2),
74            "LC1200S162-68" => (304.8, 41.1, 12.7, 1.73, 5.2),
75
76            // Wide flange lipped channels
77            "LC200S200-54" => (50.8, 50.8, 15.0, 1.37, 4.1),
78            "LC250S200-68" => (63.5, 50.8, 15.0, 1.73, 5.2),
79
80            _ => return None,
81        };
82
83        let (h, b, c, t, r) = dims;
84        Some(Self::new(
85            h / 1000.0,
86            b / 1000.0,
87            c / 1000.0,
88            t / 1000.0,
89            r / 1000.0,
90        ))
91    }
92}
93
94impl ParametricSection for LippedChannel {
95    fn build(&self) -> Section {
96        let h = self.depth;
97        let b = self.flange_width;
98        let c = self.lip_length;
99        let t = self.thickness;
100        let _r = self.inner_radius;
101
102        let hh = h / 2.0;
103
104        // Lipped channel: web on left (x ∈ [0, t]), flanges extend RIGHT.
105        // Lips fold inward at flange outer ends (x = b).
106        // CCW outline starting from web outer bottom-left.
107        let mut vertices = Vec::new();
108
109        vertices.push(Point::new(0.0, -hh));
110        vertices.push(Point::new(0.0, hh));
111        vertices.push(Point::new(b, hh));
112        if c > 0.0 {
113            vertices.push(Point::new(b, hh - t - c));
114            vertices.push(Point::new(b - t, hh - t - c));
115            vertices.push(Point::new(b - t, hh - t));
116        } else {
117            vertices.push(Point::new(b, hh - t));
118        }
119        vertices.push(Point::new(t, hh - t));
120        vertices.push(Point::new(t, -hh + t));
121        if c > 0.0 {
122            vertices.push(Point::new(b - t, -hh + t));
123            vertices.push(Point::new(b - t, -hh + t + c));
124            vertices.push(Point::new(b, -hh + t + c));
125        } else {
126            vertices.push(Point::new(b, -hh + t));
127        }
128        vertices.push(Point::new(b, -hh));
129
130        let mut clean = Vec::new();
131        for v in vertices {
132            if clean.last() != Some(&v) {
133                clean.push(v);
134            }
135        }
136        if clean.len() > 1 && clean[0] == clean[clean.len() - 1] {
137            clean.pop();
138        }
139
140        Section::new(Polygon::new(clean), Vec::new())
141    }
142
143    fn designation(&self) -> String {
144        format!(
145            "LC{:.0}x{:.0}x{:.0}x{:.1}",
146            self.depth * 1000.0,
147            self.flange_width * 1000.0,
148            self.lip_length * 1000.0,
149            self.thickness * 1000.0
150        )
151    }
152}
153
154/// Cold-formed Z-section (Z-purlin).
155#[derive(Debug, Clone, Copy, PartialEq)]
156pub struct ZSection {
157    pub depth: f64,
158    pub flange_width: f64,
159    pub lip_length: f64,
160    pub thickness: f64,
161    pub inner_radius: f64,
162}
163
164impl ZSection {
165    pub fn new(
166        depth: f64,
167        flange_width: f64,
168        lip_length: f64,
169        thickness: f64,
170        inner_radius: f64,
171    ) -> Self {
172        assert!(depth > 0.0 && flange_width > 0.0 && lip_length >= 0.0 && thickness > 0.0);
173        Self {
174            depth,
175            flange_width,
176            lip_length,
177            thickness,
178            inner_radius,
179        }
180    }
181
182    pub fn from_designation(designation: &str) -> Option<Self> {
183        let dims = match designation.to_uppercase().as_str() {
184            // Common Z-purlin sizes (mm)
185            "Z100X50X15X2.0" => (100.0, 50.0, 15.0, 2.0, 3.0),
186            "Z120X50X15X2.0" => (120.0, 50.0, 15.0, 2.0, 3.0),
187            "Z140X60X20X2.5" => (140.0, 60.0, 20.0, 2.5, 4.0),
188            "Z150X50X20X2.5" => (150.0, 50.0, 20.0, 2.5, 4.0),
189            "Z160X60X20X3.0" => (160.0, 60.0, 20.0, 3.0, 4.5),
190            "Z180X60X25X3.0" => (180.0, 60.0, 25.0, 3.0, 4.5),
191            "Z200X70X25X3.0" => (200.0, 70.0, 25.0, 3.0, 5.0),
192            "Z200X75X25X3.0" => (200.0, 75.0, 25.0, 3.0, 5.0),
193            "Z250X75X30X3.0" => (250.0, 75.0, 30.0, 3.0, 5.0),
194            "Z300X90X30X4.0" => (300.0, 90.0, 30.0, 4.0, 6.0),
195
196            // AISI Z-sections
197            "Z350S162-33" => (88.9, 41.1, 12.7, 0.84, 2.5),
198            "Z350S162-43" => (88.9, 41.1, 12.7, 1.09, 3.3),
199            "Z350S162-54" => (88.9, 41.1, 12.7, 1.37, 4.1),
200            "Z550S162-54" => (139.7, 41.1, 12.7, 1.37, 4.1),
201            "Z800S162-68" => (203.2, 41.1, 12.7, 1.73, 5.2),
202
203            _ => return None,
204        };
205
206        let (h, b, c, t, r) = dims;
207        Some(Self::new(
208            h / 1000.0,
209            b / 1000.0,
210            c / 1000.0,
211            t / 1000.0,
212            r / 1000.0,
213        ))
214    }
215}
216
217impl ParametricSection for ZSection {
218    fn build(&self) -> Section {
219        let h = self.depth;
220        let b = self.flange_width;
221        let c = self.lip_length;
222        let t = self.thickness;
223        let _r = self.inner_radius;
224
225        let hh = h / 2.0;
226
227        // Z-section: top flange extends LEFT from web, bottom flange extends RIGHT.
228        // Web: x ∈ [0, t], y ∈ [-hh, hh]
229        // Top flange: x ∈ [-b, 0], y ∈ [hh-t, hh]
230        // Bottom flange: x ∈ [t, t+b], y ∈ [-hh, -hh+t]
231        // CCW outline starting from top-left outer corner.
232        let mut vertices = Vec::new();
233
234        vertices.push(Point::new(-b, hh));
235        vertices.push(Point::new(0.0, hh));
236        vertices.push(Point::new(t, hh));
237        vertices.push(Point::new(t, -hh + t));
238        if c > 0.0 {
239            vertices.push(Point::new(b, -hh + t));
240            vertices.push(Point::new(b, -hh + t + c));
241            vertices.push(Point::new(t + b, -hh + t + c));
242        } else {
243            vertices.push(Point::new(t + b, -hh + t));
244        }
245        vertices.push(Point::new(t + b, -hh));
246        vertices.push(Point::new(t, -hh));
247        vertices.push(Point::new(0.0, -hh));
248        vertices.push(Point::new(0.0, hh - t));
249        if c > 0.0 {
250            vertices.push(Point::new(-b + t, hh - t));
251            vertices.push(Point::new(-b + t, hh - t - c));
252            vertices.push(Point::new(-b, hh - t - c));
253        } else {
254            vertices.push(Point::new(-b, hh - t));
255        }
256
257        let mut clean = Vec::new();
258        for v in vertices {
259            if clean.last() != Some(&v) {
260                clean.push(v);
261            }
262        }
263        if clean.len() > 1 && clean[0] == clean[clean.len() - 1] {
264            clean.pop();
265        }
266
267        Section::new(Polygon::new(clean), Vec::new())
268    }
269
270    fn designation(&self) -> String {
271        format!(
272            "Z{:.0}x{:.0}x{:.0}x{:.1}",
273            self.depth * 1000.0,
274            self.flange_width * 1000.0,
275            self.lip_length * 1000.0,
276            self.thickness * 1000.0
277        )
278    }
279}
280
281/// Cold-formed hat section (omega section).
282#[derive(Debug, Clone, Copy, PartialEq)]
283pub struct HatSection {
284    pub depth: f64,
285    pub top_flange: f64,
286    pub bottom_flange: f64,
287    pub lip_length: f64,
288    pub thickness: f64,
289    pub inner_radius: f64,
290}
291
292impl HatSection {
293    pub fn new(
294        depth: f64,
295        top_flange: f64,
296        bottom_flange: f64,
297        lip_length: f64,
298        thickness: f64,
299        inner_radius: f64,
300    ) -> Self {
301        assert!(depth > 0.0 && top_flange > 0.0 && bottom_flange > 0.0 && thickness > 0.0);
302        Self {
303            depth,
304            top_flange,
305            bottom_flange,
306            lip_length,
307            thickness,
308            inner_radius,
309        }
310    }
311}
312
313impl ParametricSection for HatSection {
314    fn build(&self) -> Section {
315        let h = self.depth;
316        let bt = self.top_flange;
317        let bb = self.bottom_flange;
318        let c = self.lip_length;
319        let t = self.thickness;
320
321        let hh = h / 2.0;
322
323        // Hat section outer boundary: traces the full perimeter of the section
324        // including webs as solid material. The enclosed region between the webs
325        // is carved out as a hole.
326        //
327        // Path (CCW): bottom flange bottom → right lip → right web outer face
328        //   → top flange outer face → left web outer face → left lip → close
329        let mut outer = Vec::new();
330
331        // Bottom flange: bottom edge (left to right)
332        outer.push(Point::new(-bb / 2.0, -hh));
333        outer.push(Point::new(bb / 2.0, -hh));
334
335        // Right lip (folds upward from bottom flange outer edge)
336        if c > 0.0 {
337            outer.push(Point::new(bb / 2.0, -hh + t + c));
338            outer.push(Point::new(bb / 2.0 - t, -hh + t + c));
339            outer.push(Point::new(bb / 2.0 - t, -hh + t));
340        }
341
342        // Right web: outer edge (bottom to top) — rises from bottom flange to top flange
343        outer.push(Point::new(bt / 2.0, -hh + t));
344        outer.push(Point::new(bt / 2.0, hh - t));
345
346        // Top flange: outer face (right to left)
347        outer.push(Point::new(bt / 2.0, hh));
348        outer.push(Point::new(-bt / 2.0, hh));
349        outer.push(Point::new(-bt / 2.0, hh - t));
350
351        // Left web: outer edge (top to bottom) — descends from top flange to bottom flange
352        outer.push(Point::new(-bt / 2.0, -hh + t));
353
354        // Left lip (folds upward from bottom flange outer edge)
355        if c > 0.0 {
356            outer.push(Point::new(-bb / 2.0 + t, -hh + t));
357            outer.push(Point::new(-bb / 2.0 + t, -hh + t + c));
358            outer.push(Point::new(-bb / 2.0, -hh + t + c));
359        }
360
361        // Bottom flange: top edge (right to left) — closes the polygon
362        outer.push(Point::new(-bb / 2.0, -hh));
363
364        let mut clean = Vec::new();
365        for v in outer {
366            if clean.last() != Some(&v) {
367                clean.push(v);
368            }
369        }
370        if clean.len() > 1 && clean[0] == clean[clean.len() - 1] {
371            clean.pop();
372        }
373
374        // Enclosed region between the webs (bounded by web inner faces)
375        let mut holes = Vec::new();
376        let hole = vec![
377            Point::new(-bt / 2.0 + t, -hh + t),
378            Point::new(bt / 2.0 - t, -hh + t),
379            Point::new(bt / 2.0 - t, hh - t),
380            Point::new(-bt / 2.0 + t, hh - t),
381        ];
382        holes.push(Polygon::new(hole));
383
384        Section::new(Polygon::new(clean), holes)
385    }
386
387    fn designation(&self) -> String {
388        format!(
389            "HAT{:.0}x{:.0}x{:.0}x{:.0}x{:.1}",
390            self.depth * 1000.0,
391            self.top_flange * 1000.0,
392            self.bottom_flange * 1000.0,
393            self.lip_length * 1000.0,
394            self.thickness * 1000.0
395        )
396    }
397}
398
399/// Cold-formed sigma section (Σ-section).
400#[derive(Debug, Clone, Copy, PartialEq)]
401pub struct SigmaSection {
402    pub depth: f64,
403    pub top_flange: f64,
404    pub bottom_flange: f64,
405    pub top_lip: f64,
406    pub bottom_lip: f64,
407    pub thickness: f64,
408    pub inner_radius: f64,
409}
410
411impl SigmaSection {
412    pub fn new(
413        depth: f64,
414        top_flange: f64,
415        bottom_flange: f64,
416        top_lip: f64,
417        bottom_lip: f64,
418        thickness: f64,
419        inner_radius: f64,
420    ) -> Self {
421        assert!(depth > 0.0 && top_flange > 0.0 && bottom_flange > 0.0 && thickness > 0.0);
422        Self {
423            depth,
424            top_flange,
425            bottom_flange,
426            top_lip,
427            bottom_lip,
428            thickness,
429            inner_radius,
430        }
431    }
432}
433
434impl ParametricSection for SigmaSection {
435    fn build(&self) -> Section {
436        let h = self.depth;
437        let bt = self.top_flange;
438        let bb = self.bottom_flange;
439        let ct = self.top_lip;
440        let cb = self.bottom_lip;
441        let t = self.thickness;
442
443        let hh = h / 2.0;
444
445        // Sigma section outer boundary: traces the full perimeter including webs
446        // as solid material. Bottom lips fold upward from bottom flange outer edges.
447        // Top lips fold downward from top flange into the enclosed region (hole).
448        // The enclosed region between the webs (including top lips) is carved out as a hole.
449        //
450        // Path (CCW): bottom flange bottom → right bottom lip → right web outer face
451        //   → top flange outer face → left web outer face → left bottom lip → close
452        let mut outer = Vec::new();
453
454        // Bottom flange: bottom edge (left to right)
455        outer.push(Point::new(-bb / 2.0, -hh));
456        outer.push(Point::new(bb / 2.0, -hh));
457
458        // Right bottom lip (folds upward from bottom flange outer edge)
459        if cb > 0.0 {
460            outer.push(Point::new(bb / 2.0, -hh + t + cb));
461            outer.push(Point::new(bb / 2.0 - t, -hh + t + cb));
462            outer.push(Point::new(bb / 2.0 - t, -hh + t));
463        }
464
465        // Right web: outer edge (bottom to top)
466        outer.push(Point::new(bt / 2.0, -hh + t));
467        outer.push(Point::new(bt / 2.0, hh - t));
468
469        // Top flange: outer face (right to left)
470        outer.push(Point::new(bt / 2.0, hh));
471        outer.push(Point::new(-bt / 2.0, hh));
472        outer.push(Point::new(-bt / 2.0, hh - t));
473
474        // Left web: outer edge (top to bottom)
475        outer.push(Point::new(-bt / 2.0, -hh + t));
476
477        // Left bottom lip (folds upward from bottom flange outer edge)
478        if cb > 0.0 {
479            outer.push(Point::new(-bb / 2.0 + t, -hh + t));
480            outer.push(Point::new(-bb / 2.0 + t, -hh + t + cb));
481            outer.push(Point::new(-bb / 2.0, -hh + t + cb));
482        }
483
484        // Bottom flange: top edge (right to left) — closes the polygon
485        outer.push(Point::new(-bb / 2.0, -hh));
486
487        let mut clean = Vec::new();
488        for v in outer {
489            if clean.last() != Some(&v) {
490                clean.push(v);
491            }
492        }
493        if clean.len() > 1 && clean[0] == clean[clean.len() - 1] {
494            clean.pop();
495        }
496
497        // Enclosed region between the webs, including top lip notches.
498        // The top lips fold downward from the top flange into this region.
499        let mut holes = Vec::new();
500        if ct > 0.0 {
501            let hole = vec![
502                Point::new(-bt / 2.0 + t, -hh + t),
503                Point::new(bt / 2.0 - t, -hh + t),
504                Point::new(bt / 2.0 - t, hh - t),
505                Point::new(bt / 2.0, hh - t),
506                Point::new(bt / 2.0, hh - t - ct),
507                Point::new(bt / 2.0 - t, hh - t - ct),
508                Point::new(-bt / 2.0 + t, hh - t - ct),
509                Point::new(-bt / 2.0, hh - t - ct),
510                Point::new(-bt / 2.0, hh - t),
511                Point::new(-bt / 2.0 + t, hh - t),
512            ];
513            holes.push(Polygon::new(hole));
514        } else {
515            let hole = vec![
516                Point::new(-bt / 2.0 + t, -hh + t),
517                Point::new(bt / 2.0 - t, -hh + t),
518                Point::new(bt / 2.0 - t, hh - t),
519                Point::new(-bt / 2.0 + t, hh - t),
520            ];
521            holes.push(Polygon::new(hole));
522        }
523
524        Section::new(Polygon::new(clean), holes)
525    }
526
527    fn designation(&self) -> String {
528        format!(
529            "SIGMA{:.0}x{:.0}x{:.0}x{:.0}x{:.0}x{:.1}",
530            self.depth * 1000.0,
531            self.top_flange * 1000.0,
532            self.bottom_flange * 1000.0,
533            self.top_lip * 1000.0,
534            self.bottom_lip * 1000.0,
535            self.thickness * 1000.0
536        )
537    }
538}
539
540/// Cold-formed deck profile (trapezoidal sheet).
541#[derive(Debug, Clone, Copy, PartialEq)]
542pub struct DeckProfile {
543    pub depth: f64,        // h - profile height
544    pub pitch: f64,        // w - pitch (width of one wave)
545    pub top_width: f64,    // top flat width
546    pub bottom_width: f64, // bottom flat width
547    pub thickness: f64,
548    pub web_angle: f64, // web angle from horizontal (degrees)
549}
550
551impl DeckProfile {
552    pub fn new(
553        depth: f64,
554        pitch: f64,
555        top_width: f64,
556        bottom_width: f64,
557        thickness: f64,
558        web_angle: f64,
559    ) -> Self {
560        assert!(depth > 0.0 && pitch > 0.0 && thickness > 0.0);
561        assert!(top_width >= 0.0 && bottom_width >= 0.0);
562        assert!(web_angle > 0.0 && web_angle < 90.0);
563        Self {
564            depth,
565            pitch,
566            top_width,
567            bottom_width,
568            thickness,
569            web_angle,
570        }
571    }
572
573    pub fn reentrant(
574        depth: f64,
575        pitch: f64,
576        top_width: f64,
577        bottom_width: f64,
578        thickness: f64,
579        _reentrant_depth: f64,
580    ) -> Self {
581        // Reentrant profile has stiffener in web
582        Self::new(depth, pitch, top_width, bottom_width, thickness, 45.0)
583    }
584}
585
586impl ParametricSection for DeckProfile {
587    fn build(&self) -> Section {
588        let h = self.depth;
589        let w = self.pitch;
590        let wb = self.bottom_width;
591        let _t = self.thickness;
592        let alpha = self.web_angle.to_radians();
593
594        let hh = h / 2.0;
595
596        // Trapezoidal deck profile: outer polygon traces the corrugated
597        // cross-section boundary. The web runs from the bottom flange edge
598        // inward (toward center) to the top flange edge at web_angle
599        // from horizontal. Bottom flange is wider, top flange is narrower.
600        let web_run = h / alpha.tan();
601        let x0 = -w / 2.0;
602        let x1 = x0 + wb;
603        let x2r = x1 - web_run;
604        let x2l = x0 + web_run;
605
606        // Outer polygon: full perimeter of one corrugation wave (CCW)
607        let outer = vec![
608            Point::new(x0, -hh), // bottom flange left
609            Point::new(x1, -hh), // bottom flange right
610            Point::new(x2r, hh), // top flange right (via right web)
611            Point::new(x2l, hh), // top flange left (via left web)
612        ];
613
614        Section::new(Polygon::new(outer), Vec::new())
615    }
616
617    fn designation(&self) -> String {
618        format!(
619            "DECK{:.0}x{:.0}x{:.0}x{:.0}x{:.1}",
620            self.depth * 1000.0,
621            self.pitch * 1000.0,
622            self.top_width * 1000.0,
623            self.bottom_width * 1000.0,
624            self.thickness * 1000.0
625        )
626    }
627}
628
629impl DeckProfile {
630    /// Effective section properties per unit width (for slab design).
631    pub fn effective_properties_per_width(
632        &self,
633        _material: &Material,
634    ) -> crate::section_properties::SectionProperties {
635        // For deck profiles, properties are typically given per meter width
636        let sec = self.build();
637        let props = crate::section_properties::SectionProperties::from_section(&sec);
638
639        // Scale to per meter width
640        let scale = 1.0 / self.pitch;
641        crate::section_properties::SectionProperties {
642            geometric: crate::section_properties::GeometricProperties {
643                area: props.area * scale,
644                centroid: props.centroid,
645                ix: props.ix * scale,
646                iy: props.iy * scale,
647                ixy: props.ixy * scale,
648                max_fiber_distance_y: props.max_fiber_distance_y,
649                max_fiber_distance_x: props.max_fiber_distance_x,
650                zxx_plus: props.zxx_plus * scale,
651                zxx_minus: props.zxx_minus * scale,
652                zyy_plus: props.zyy_plus * scale,
653                zyy_minus: props.zyy_minus * scale,
654                perimeter: props.perimeter * scale,
655                qx: props.qx * scale,
656                qy: props.qy * scale,
657                ixx_g: props.ixx_g * scale,
658                iyy_g: props.iyy_g * scale,
659                ixy_g: props.ixy_g * scale,
660            },
661            principal: crate::section_properties::PrincipalProperties {
662                i11: props.principal.i11 * scale,
663                i22: props.principal.i22 * scale,
664                phi: props.principal.phi,
665                z11_plus: props.principal.z11_plus * scale,
666                z11_minus: props.principal.z11_minus * scale,
667                z22_plus: props.principal.z22_plus * scale,
668                z22_minus: props.principal.z22_minus * scale,
669            },
670            gyration: crate::section_properties::GyrationProperties {
671                rx: props.gyration.rx,
672                ry: props.gyration.ry,
673                r11: props.gyration.r11,
674                r22: props.gyration.r22,
675                polar: props.gyration.polar,
676            },
677        }
678    }
679}
680
681/// Custom cold-formed profile from arbitrary points.
682#[derive(Debug, Clone)]
683pub struct CustomColdFormed {
684    pub vertices: Vec<Point>,
685    pub holes: Vec<Vec<Point>>,
686    pub thickness: f64,
687    pub material: Option<Material>,
688}
689
690impl CustomColdFormed {
691    pub fn new(vertices: Vec<Point>, thickness: f64) -> Self {
692        Self {
693            vertices,
694            holes: Vec::new(),
695            thickness,
696            material: None,
697        }
698    }
699
700    pub fn with_holes(mut self, holes: Vec<Vec<Point>>) -> Self {
701        self.holes = holes;
702        self
703    }
704
705    pub fn with_material(mut self, material: Material) -> Self {
706        self.material = Some(material);
707        self
708    }
709}
710
711impl ParametricSection for CustomColdFormed {
712    fn build(&self) -> Section {
713        let outer = Polygon::new(self.vertices.clone());
714        let holes: Vec<Polygon> = self.holes.iter().map(|h| Polygon::new(h.clone())).collect();
715        Section::new(outer, holes)
716    }
717
718    fn designation(&self) -> String {
719        "CUSTOM".to_string()
720    }
721}
722
723#[cfg(test)]
724mod tests {
725    use super::*;
726    use crate::material::presets::STEEL_S355;
727
728    #[test]
729    fn lipped_channel_basic() {
730        let lc = LippedChannel::new(0.2, 0.07, 0.015, 0.002, 0.003);
731        let sec = lc.build();
732        assert!(sec.area() > 0.0);
733
734        let props = crate::section_properties::SectionProperties::from_section(&sec);
735        assert!(props.ix > 0.0);
736        assert!(props.iy > 0.0);
737    }
738
739    #[test]
740    fn lipped_channel_area() {
741        let h = 0.2;
742        let b = 0.07;
743        let c = 0.015;
744        let t = 0.002;
745        let lc = LippedChannel::new(h, b, c, t, 0.003);
746        let sec = lc.build();
747        let area = sec.area();
748        let expected = t * (h + 2.0 * b + 2.0 * c - 2.0 * t);
749        assert!(
750            (area - expected).abs() / expected < 1e-6,
751            "LippedChannel area: got {}, expected {}",
752            area,
753            expected
754        );
755    }
756
757    #[test]
758    fn lipped_channel_gb() {
759        let lc = LippedChannel::from_designation("LC200X70X25X3.0").unwrap();
760        assert!((lc.depth - 0.2).abs() < 1e-6);
761        assert!((lc.flange_width - 0.07).abs() < 1e-6);
762        assert!((lc.lip_length - 0.025).abs() < 1e-6);
763        assert!((lc.thickness - 0.003).abs() < 1e-6);
764    }
765
766    #[test]
767    fn lipped_channel_aisi() {
768        let lc = LippedChannel::from_designation("LC550S162-54").unwrap();
769        assert!((lc.depth - 0.1397).abs() < 1e-4);
770        assert!((lc.thickness - 0.00137).abs() < 1e-5);
771    }
772
773    #[test]
774    fn z_section_basic() {
775        let z = ZSection::new(0.2, 0.07, 0.015, 0.002, 0.003);
776        let sec = z.build();
777        assert!(sec.area() > 0.0);
778
779        // Z-section should have Ix > Iy typically
780        let props = crate::section_properties::SectionProperties::from_section(&sec);
781        assert!(props.ix > 0.0);
782    }
783
784    #[test]
785    fn z_section_area_check() {
786        let h = 0.2;
787        let b = 0.07;
788        let c = 0.015;
789        let t = 0.002;
790        let z = ZSection::new(h, b, c, t, 0.003);
791        let sec = z.build();
792        let area = sec.area();
793        let expected = t * (h + 2.0 * b + 2.0 * c);
794        assert!(
795            (area - expected).abs() / expected < 1e-6,
796            "Cold-formed Z area: got {}, expected {}",
797            area,
798            expected
799        );
800    }
801
802    #[test]
803    fn z_section_gb() {
804        let z = ZSection::from_designation("Z200X75X25X3.0").unwrap();
805        assert!((z.depth - 0.2).abs() < 1e-6);
806    }
807
808    #[test]
809    fn hat_section() {
810        let hat = HatSection::new(0.15, 0.05, 0.08, 0.015, 0.002, 0.003);
811        let sec = hat.build();
812        assert!(sec.area() > 0.0);
813    }
814
815    #[test]
816    fn hat_section_area() {
817        let h = 0.15;
818        let bt = 0.05;
819        let bb = 0.08;
820        let c = 0.015;
821        let t = 0.002;
822        let hat = HatSection::new(h, bt, bb, c, t, 0.003);
823        let sec = hat.build();
824        let area = sec.area();
825        let expected = bb * t + 2.0 * t * (h - 2.0 * t) + bt * t + 2.0 * c * t;
826        assert!(
827            (area - expected).abs() / expected < 1e-6,
828            "HatSection area: got {}, expected {}",
829            area,
830            expected
831        );
832    }
833
834    #[test]
835    fn sigma_section() {
836        let sigma = SigmaSection::new(0.2, 0.06, 0.08, 0.02, 0.02, 0.002, 0.003);
837        let sec = sigma.build();
838        assert!(sec.area() > 0.0);
839    }
840
841    #[test]
842    fn sigma_section_area() {
843        let h = 0.2;
844        let bt = 0.06;
845        let bb = 0.08;
846        let ct = 0.02;
847        let cb = 0.02;
848        let t = 0.002;
849        let sigma = SigmaSection::new(h, bt, bb, ct, cb, t, 0.003);
850        let sec = sigma.build();
851        let area = sec.area();
852
853        // `build()` constructs a SOLID section: a single outer polygon with the
854        // enclosed region between the webs carved out as one hole. The material
855        // area must therefore equal outer area minus the hole(s).
856        let outer: f64 = sec.outer.area();
857        let holes: f64 = sec.holes.iter().map(|h| h.area()).sum();
858        assert!(
859            (area - (outer - holes)).abs() < 1e-9,
860            "area {} should equal outer {} minus holes {}",
861            area,
862            outer,
863            holes
864        );
865        assert!(area > 0.0);
866
867        // The idealized thin-wall (centerline) area is a lower bound on the
868        // material enclosed by the solid drawing.
869        let thin_wall = bb * t + 2.0 * t * cb + 2.0 * t * (h - 2.0 * t) + bt * t + 2.0 * ct * t;
870        assert!(
871            area >= thin_wall - 1e-12,
872            "solid area {} must not be less than thin-wall material {}",
873            area,
874            thin_wall
875        );
876    }
877
878    #[test]
879    fn deck_profile() {
880        let deck = DeckProfile::new(0.05, 0.3, 0.1, 0.15, 0.001, 45.0);
881        let sec = deck.build();
882        assert!(sec.area() > 0.0);
883
884        let props = deck.effective_properties_per_width(&STEEL_S355);
885        assert!(props.area > 0.0);
886        assert!(props.ix > 0.0);
887    }
888
889    #[test]
890    fn deck_profile_area() {
891        let h = 0.05;
892        let wt = 0.1;
893        let wb = 0.15;
894        let t = 0.001;
895        let web_angle = 45.0_f64;
896        let deck = DeckProfile::new(h, 0.3, wt, wb, t, web_angle);
897        let sec = deck.build();
898        let area = sec.area();
899        // Trapezoidal polygon area: (bottom_width + top_width) / 2 * height
900        // top_width = wb - 2 * web_run, web_run = h / tan(angle)
901        let alpha = web_angle.to_radians();
902        let web_run = h / alpha.tan();
903        let top_w = wb - 2.0 * web_run;
904        let expected = 0.5 * (wb + top_w) * h;
905        assert!(
906            (area - expected).abs() / expected < 1e-6,
907            "DeckProfile area: got {}, expected {}",
908            area,
909            expected
910        );
911    }
912
913    #[test]
914    fn custom_cold_formed() {
915        let vertices = vec![
916            Point::new(0.0, 0.0),
917            Point::new(0.1, 0.0),
918            Point::new(0.1, 0.1),
919            Point::new(0.0, 0.1),
920        ];
921        let custom = CustomColdFormed::new(vertices, 0.002);
922        let sec = custom.build();
923        assert!((sec.area() - 0.01).abs() < 1e-10);
924    }
925}