parry3d/transformation/to_outline/
cone_to_outline.rs

1use crate::math::Vector;
2use crate::shape::Cone;
3use crate::transformation::utils;
4use alloc::{vec, vec::Vec};
5
6impl Cone {
7    /// Outlines this cone’s shape using polylines.
8    pub fn to_outline(&self, nsubdiv: u32) -> (Vec<Vector>, Vec<[u32; 2]>) {
9        let diameter = self.radius * 2.0;
10        let height = self.half_height * 2.0;
11        let scale = Vector::new(diameter, height, diameter);
12        let (vtx, idx) = unit_cone_outline(nsubdiv);
13        (utils::scaled(vtx, scale), idx)
14    }
15}
16
17/// Generates a cone with unit height and diameter.
18fn unit_cone_outline(nsubdiv: u32) -> (Vec<Vector>, Vec<[u32; 2]>) {
19    let mut out_vtx = vec![Vector::new(-0.5, -0.5, 0.0), Vector::new(0.0, 0.5, 0.0)];
20    let mut out_ptx = vec![];
21    #[allow(clippy::single_range_in_vec_init)] // The single range is on purpose.
22    utils::apply_revolution(false, true, &[0..1], nsubdiv, &mut out_vtx, &mut out_ptx);
23    (out_vtx, out_ptx)
24}