parry2d/transformation/to_polyline/
round_cuboid_to_polyline.rs

1use crate::math::Real;
2use crate::shape::RoundCuboid;
3use crate::transformation::utils;
4use alloc::{vec, vec::Vec};
5use na::{self, Point2};
6
7impl RoundCuboid {
8    /// Discretize the boundary of this round cuboid as a polygonal line.
9    pub fn to_polyline(&self, border_subdivs: u32) -> Vec<Point2<Real>> {
10        let mut out_vtx = vec![];
11        let he = self.inner_shape.half_extents;
12        let br = self.border_radius;
13
14        let arc_centers = [
15            Point2::new(-he.x, -he.y),
16            Point2::new(he.x, -he.y),
17            Point2::new(he.x, he.y),
18            Point2::new(-he.x, he.y),
19        ];
20        let arc_vertices = [
21            (
22                Point2::new(-he.x - br, -he.y),
23                Point2::new(-he.x, -he.y - br),
24            ),
25            (Point2::new(he.x, -he.y - br), Point2::new(he.x + br, -he.y)),
26            (Point2::new(he.x + br, he.y), Point2::new(he.x, he.y + br)),
27            (Point2::new(-he.x, he.y + br), Point2::new(-he.x - br, he.y)),
28        ];
29
30        for i in 0..4 {
31            out_vtx.push(arc_vertices[i].0);
32            utils::push_arc(
33                arc_centers[i],
34                arc_vertices[i].0,
35                arc_vertices[i].1,
36                border_subdivs,
37                &mut out_vtx,
38            );
39            out_vtx.push(arc_vertices[i].1);
40        }
41
42        out_vtx
43    }
44}