parry2d/transformation/to_polyline/cuboid_to_polyline.rs
1use crate::math::Vector2;
2use crate::shape::Cuboid;
3use crate::transformation::utils;
4use alloc::{vec, vec::Vec};
5
6impl Cuboid {
7 /// Discretize the boundary of this cuboid as a polygonal line.
8 pub fn to_polyline(&self) -> Vec<Vector2> {
9 utils::scaled(unit_rectangle(), self.half_extents * 2.0)
10 }
11}
12
13/// The contour of a unit cuboid lying on the x-y plane.
14fn unit_rectangle() -> Vec<Vector2> {
15 vec![
16 Vector2::new(-0.5, -0.5),
17 Vector2::new(0.5, -0.5),
18 Vector2::new(0.5, 0.5),
19 Vector2::new(-0.5, 0.5),
20 ]
21}