Skip to main content

Tessellator

Struct Tessellator 

Source
pub struct Tessellator { /* private fields */ }
Expand description

Turns paths into GPU-ready triangle meshes.

The tessellator owns the scratch buffers it needs, so filling a chart with many series does not allocate once per shape: the buffers are reused across calls and only grow when a larger shape shows up.

A tessellator is not thread-safe; each renderer owns one.

Implementations§

Source§

impl Tessellator

Inherent implementation of Tessellator.

Source

pub fn new() -> Self

Returns a tessellator with the default flattening tolerance.

Source

pub fn with_tolerance(tolerance: f64) -> Self

Returns a tessellator with the given flattening tolerance, in pixels.

A smaller tolerance produces smoother curves at the cost of more vertices.

§Arguments
  • f64 - A 64-bit float (f64).
Source

pub fn tolerance(&self) -> f64

Returns the flattening tolerance, in pixels.

§Returns
  • f64 - A 64-bit float.
Source

pub fn flatten(&mut self, path: &Path) -> &FlatPath

Flattens the path into contours and returns them.

The returned reference borrows the tessellator’s scratch storage and stays valid until the next call to Tessellator::flatten.

§Arguments
  • &Path - Shared reference to a Path.
§Returns
  • &FlatPath - A FlatPath value.
Source

pub fn fill(&mut self, path: &Path, color: u32) -> SolidMesh

Triangulates the path and returns the resulting mesh.

The path is filled according to its FillRule. Holes are detected automatically: a contour nested inside another contour with the opposite winding direction is treated as a hole, which is what makes a doughnut chart’s inner ring disappear.

§Arguments
  • &Path - Shared reference to a Path.
  • u32 - A 32-bit unsigned integer (u32).
§Returns
  • SolidMesh - A SolidMesh value.
Source

pub fn fill_flattened( &mut self, path: &Path, color: u32, rule: FillRule, ) -> SolidMesh

Triangulates the path and returns the resulting mesh, using the given fill rule.

§Arguments
  • &Path - Shared reference to a Path.
  • u32 - A 32-bit unsigned integer (u32).
  • FillRule - A FillRule parameter.
§Returns
  • SolidMesh - A SolidMesh value.
Source

pub fn fill_contours( &mut self, contours: &[Contour], color: u32, rule: FillRule, ) -> SolidMesh

Triangulates a set of contours and returns the resulting mesh.

§Arguments
  • &[Contour] - Shared reference to a [Contour].
  • u32 - A 32-bit unsigned integer (u32).
  • FillRule - A FillRule parameter.
§Returns
  • SolidMesh - A SolidMesh value.
Source

pub fn fill_strip( &mut self, points: &[Point], baseline: f32, color: u32, ) -> SolidMesh

Builds a triangle strip for the region between a polyline and a straight baseline.

This is the hot path for area charts: the shape is a strip by construction, so it needs no triangulation at all, and the whole series becomes a single indexed draw call.

points are the polyline vertices in order; baseline is the vertical coordinate the area is closed against.

§Arguments
  • &[Point] - Shared reference to a [Point].
  • f32 - A 32-bit float (f32).
  • u32 - A 32-bit unsigned integer (u32).
§Returns
  • SolidMesh - A SolidMesh value.
Source

pub fn stroke( &mut self, path: &Path, style: &StrokeStyle, color: u32, ) -> SolidMesh

Expands the path into stroke geometry and returns the mesh.

Every segment becomes a quad, and every join becomes a wedge, so the whole stroke is a single indexed draw call regardless of how many segments it has.

§Arguments
  • &Path - Shared reference to a Path.
  • &StrokeStyle - Shared reference to a StrokeStyle.
  • u32 - A 32-bit unsigned integer (u32).
§Returns
  • SolidMesh - A SolidMesh value.
Source

pub fn stroke_contours( &mut self, contours: &[Contour], style: &StrokeStyle, color: u32, ) -> SolidMesh

Expands a set of contours into stroke geometry.

§Arguments
  • &[Contour] - Shared reference to a [Contour].
  • &StrokeStyle - Shared reference to a StrokeStyle.
  • u32 - A 32-bit unsigned integer (u32).
§Returns
  • SolidMesh - A SolidMesh value.

Trait Implementations§

Source§

impl Clone for Tessellator

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tessellator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Tessellator

Default construction for Tessellator.

Source§

fn default() -> Self

Constructs a default Tessellator value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more