1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use super::EdgeIndex;

pub fn mesh(polygons: &[Vec<usize>]) -> Vec<EdgeIndex> {
    // Provide an underestimate for capacity
    // For large polygons this will provide some relief
    // from constant reallocation.
    let mut mesh = Vec::with_capacity(polygons.len());
    for poly in polygons {
        if poly.is_empty() {
            return Vec::new();
        }
        let mut p: usize = *poly.last().unwrap();
        for q in poly {
            if q > &p {
                mesh.push((p, *q));
            }
            p = *q;
        }
    }

    mesh
}