pittore 0.2.4

Simple toolkit for 2D visualization based on wgpu.
Documentation
use super::BufferItem;

pub struct Mesh<V: BufferItem> {
    pub vertices: Vec<V>,
    pub indices: Vec<u32>,
}

impl<V: BufferItem> Mesh<V> {
    pub fn new_triangle_list(vertices: Vec<V>) -> Self {
        let indices = (0..vertices.len() as u32).collect();
        Mesh { vertices, indices }
    }

    pub fn new_triangle_strip(vertices: Vec<V>) -> Self {
        let indices = (0..(vertices.len() - 2) as u32)
            .flat_map(|i| {
                if i % 2 == 0 {
                    [i, i + 1, i + 2]
                } else {
                    [i + 1, i, i + 2]
                }
            })
            .collect();

        Mesh { vertices, indices }
    }

    pub fn new_triangle_fan(vertices: Vec<V>, close: bool) -> Self {
        let mut indices: Vec<_> = (0..(vertices.len() - 2) as u32)
            .flat_map(|i| [0, i + 1, i + 2])
            .collect();
        if close {
            indices.append(&mut vec![0, vertices.len() as u32 - 1, 1]);
        }
        Mesh { vertices, indices }
    }
}