parry3d/transformation/to_outline/
round_cylinder_to_outline.rs

1use crate::math::Vector;
2use crate::shape::RoundCylinder;
3use crate::transformation::utils;
4use alloc::{vec, vec::Vec};
5
6impl RoundCylinder {
7    /// Outlines this round cylinder’s shape using polylines.
8    pub fn to_outline(&self, nsubdiv: u32, border_nsubdiv: u32) -> (Vec<Vector>, Vec<[u32; 2]>) {
9        let r = self.inner_shape.radius;
10        let br = self.border_radius;
11        let he = self.inner_shape.half_height;
12
13        let mut out_vtx = vec![];
14        let mut out_idx = vec![];
15
16        // Compute the profile.
17        let center_ab = Vector::new(-r, -he, 0.0);
18        let center_cd = Vector::new(-r, he, 0.0);
19        let a = Vector::new(-r, -he - br, 0.0);
20        let b = Vector::new(-r - br, -he, 0.0);
21        let c = Vector::new(-r - br, he, 0.0);
22        let d = Vector::new(-r, he + br, 0.0);
23
24        out_vtx.push(a);
25        utils::push_arc(center_ab, a, b, border_nsubdiv, &mut out_vtx);
26        out_vtx.push(b);
27        out_vtx.push(c);
28        utils::push_arc(center_cd, c, d, border_nsubdiv, &mut out_vtx);
29        out_vtx.push(d);
30
31        let circles = [
32            0..1,
33            border_nsubdiv..border_nsubdiv + 2,
34            border_nsubdiv * 2 + 1..border_nsubdiv * 2 + 2,
35        ];
36        utils::apply_revolution(false, false, &circles, nsubdiv, &mut out_vtx, &mut out_idx);
37        (out_vtx, out_idx)
38    }
39}