parry3d/transformation/to_outline/
cone_to_outline.rs

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