parry2d/transformation/to_polyline/
heightfield_to_polyline.rs

1use crate::math::Real;
2use crate::shape::HeightField;
3use alloc::{vec, vec::Vec};
4use na::Point2;
5
6impl HeightField {
7    /// Rasterize this heightfield as a (potentially discontinuous) polyline.
8    pub fn to_polyline(&self) -> (Vec<Point2<Real>>, Vec<[u32; 2]>) {
9        let mut vertices = vec![];
10        let mut indices = vec![];
11
12        for seg in self.segments() {
13            let base_id = vertices.len() as u32;
14            if vertices.last().map(|pt| seg.a != *pt).unwrap_or(true) {
15                indices.push([base_id, base_id + 1]);
16                vertices.push(seg.a);
17            } else {
18                indices.push([base_id - 1, base_id]);
19            }
20
21            vertices.push(seg.b);
22        }
23
24        (vertices, indices)
25    }
26}