parry2d/transformation/to_polyline/
capsule_to_polyline.rs

1use crate::math::{Real, RealField, Vector, Vector2};
2use crate::shape::Capsule;
3use crate::transformation::utils;
4use alloc::vec::Vec;
5
6impl Capsule {
7    /// Discretize the boundary of this capsule as a polygonal line.
8    pub fn to_polyline(&self, nsubdiv: u32) -> Vec<Vector2> {
9        let pi = Real::pi();
10        let dtheta = pi / (nsubdiv as Real);
11
12        let mut points: Vec<Vector2> = Vec::with_capacity(nsubdiv as usize);
13
14        utils::push_xy_arc(self.radius, nsubdiv, dtheta, &mut points);
15
16        let npoints = points.len();
17
18        for i in 0..npoints {
19            let new_point = points[i] + Vector::new(0.0, self.half_height());
20
21            points.push(-new_point);
22            points[i] = new_point;
23        }
24
25        utils::transformed(points, self.canonical_transform())
26    }
27}