parry2d/transformation/to_polyline/
round_cuboid_to_polyline.rs

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