#2d #graphics #tessellation #svg

lyon

2D Graphics rendering on the GPU using tessellation

56 releases (2 stable)

1.0.1 Nov 6, 2022
1.0.0 Jul 11, 2022
0.17.10 Oct 12, 2021
0.17.5 Jan 30, 2021
0.1.1 Jul 14, 2016

#421 in Graphics APIs

Download history 6998/week @ 2023-02-12 8019/week @ 2023-02-19 6299/week @ 2023-02-26 8342/week @ 2023-03-05 6587/week @ 2023-03-12 6902/week @ 2023-03-19 5840/week @ 2023-03-26 6348/week @ 2023-04-02 6690/week @ 2023-04-09 5667/week @ 2023-04-16 5379/week @ 2023-04-23 9616/week @ 2023-04-30 7958/week @ 2023-05-07 6810/week @ 2023-05-14 6943/week @ 2023-05-21 9131/week @ 2023-05-28

31,381 downloads per month
Used in 116 crates (31 directly)

MIT/Apache

1MB
33K SLoC

Lyon

A path tessellation library written in rust for GPU-based 2D graphics rendering.

Project logo

crates.io Build Status documentation Gitter Chat

Example

extern crate lyon;
use lyon::math::point;
use lyon::path::Path;
use lyon::tessellation::*;

fn main() {
    // Build a Path.
    let mut builder = Path::builder();
    builder.begin(point(0.0, 0.0));
    builder.line_to(point(1.0, 0.0));
    builder.quadratic_bezier_to(point(2.0, 0.0), point(2.0, 1.0));
    builder.cubic_bezier_to(point(1.0, 1.0), point(0.0, 1.0), point(0.0, 0.0));
    builder.end(true);
    let path = builder.build();
    // Let's use our own custom vertex type instead of the default one.
    #[derive(Copy, Clone, Debug)]
    struct MyVertex { position: [f32; 2] };
    // Will contain the result of the tessellation.
    let mut geometry: VertexBuffers<MyVertex, u16> = VertexBuffers::new();
    let mut tessellator = FillTessellator::new();
    {
        // Compute the tessellation.
        tessellator.tessellate_path(
            &path,
            &FillOptions::default(),
            &mut BuffersBuilder::new(&mut geometry, |vertex: FillVertex| {
                MyVertex {
                    position: vertex.position().to_array(),
                }
            }),
        ).unwrap();
    }
    // The tessellated geometry is ready to be uploaded to the GPU.
    println!(" -- {} vertices {} indices",
        geometry.vertices.len(),
        geometry.indices.len()
    );
}

Dependencies

~2.5MB
~59K SLoC