Crate lyon_tess2[][src]

Alternative fill tessellation implementation using libtess2.

Lyon libtess2 wrapper

This crate provides an alternative path fill tessellator implemented as a wrapper of the libtess2 C library.

The goal of this crate is to provide an alternative tessellator for the potential cases where lyon_tessellation::FillTessellator is lacking in features or robustness, and have something to compare the latter against.

Comparison with lyon_tessellation::FillTessellator

Advantages:

  • Supports the NonZero fill rule.
  • More robust against precision errors when paths have many self intersections very close to each other.

Disdvantages:

  • About twice slower than lyon_tessellation's fill tessellator.
  • Does not support computing vertex normals.
  • Wrapper around a C library (as opposed to pure rust with no unsafe code).

API

In order to avoid any overhead, this crate introduces the FlattenedPath type which stores already-flattened paths in the memory layout expected by libtess2. Instead of working with a GeometryBuilder like the tessellators in lyon_tessellation, this tessellator uses a GeometryReceiver trait that corresponds to the way libtess2 exposes its output.

Example

extern crate lyon_tess2 as tess2;
use tess2::{FillTessellator, FillOptions};
use tess2::math::{Point, point};
use tess2::path::default::Path;
use tess2::path::builder::*;
use tess2::path::iterator::*;
use tess2::flattened_path::FlattenedPath;
use tess2::tessellation::geometry_builder::*;

fn main() {
    // Create a simple path.
    let mut path_builder = Path::builder();
    path_builder.move_to(point(0.0, 0.0));
    path_builder.line_to(point(1.0, 2.0));
    path_builder.line_to(point(2.0, 0.0));
    path_builder.line_to(point(1.0, 1.0));
    path_builder.close();
    let path = path_builder.build();

    // Create the destination vertex and index buffers.
    let mut buffers: VertexBuffers<Point, u16> = VertexBuffers::new();

    {
        // Create the tessellator.
        let mut tessellator = FillTessellator::new();

        // Compute the tessellation.
        let result = tessellator.tessellate_path(
            path.path_iter(),
            &FillOptions::default(),
            &mut simple_builder(&mut buffers)
        );
        assert!(result.is_ok());
    }
    println!("The generated vertices are: {:?}.", &buffers.vertices[..]);
    println!("The generated indices are: {:?}.", &buffers.indices[..]);

}

Re-exports

pub extern crate tess2_sys;
pub extern crate lyon_tessellation as tessellation;

Modules

flattened_path
geom

Simple 2D geometric primitives on top of euclid.

math

Basic types that are used everywhere. Most other lyon crates reexport them.

path

Data structures and traits to work with paths (vector graphics).

Structs

FillOptions

Parameters for the fill tessellator.

FillTessellator

A fill tessellator implemented on top of libtess2.