parry2d/transformation/to_polyline/
capsule_to_polyline.rs

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