Struct lyon_tessellation::StrokeTessellator [−][src]
pub struct StrokeTessellator { /* fields omitted */ }
A Context object that can tessellate stroke operations for complex paths.
Overview
The stroke tessellation algorithm simply generates a strip of triangles along the path. This method is fast and simple to implement, however it means that if the path overlap with itself (for example in the case of a self-intersecting path), some triangles will overlap in the intersecting region, which may not be the desired behavior. This needs to be kept in mind when rendering transparent SVG strokes since the spec mandates that each point along a semi-transparent path is shaded once no matter how many times the path overlaps with itself at this location.
StrokeTessellator
exposes a similar interface to its
fill equivalent.
This stroke tessellator takes an iterator of path events as inputs as well as
a StrokeOption
, and produces its outputs using
a StrokeGeometryBuilder
.
See the geometry_builder
module documentation
for more details about how to output custom vertex layouts.
See https://github.com/nical/lyon/wiki/Stroke-tessellation for some notes about how the path stroke tessellator is implemented.
Examples
// Create a simple path. let mut path_builder = Path::builder(); path_builder.begin(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.end(true); let path = path_builder.build(); // Create the destination vertex and index buffers. let mut buffers: VertexBuffers<Point, u16> = VertexBuffers::new(); { // Create the destination vertex and index buffers. let mut vertex_builder = simple_builder(&mut buffers); // Create the tessellator. let mut tessellator = StrokeTessellator::new(); // Compute the tessellation. tessellator.tessellate( &path, &StrokeOptions::default(), &mut vertex_builder ); } println!("The generated vertices are: {:?}.", &buffers.vertices[..]); println!("The generated indices are: {:?}.", &buffers.indices[..]);
Implementations
impl StrokeTessellator
[src]
pub fn new() -> Self
[src]
pub fn tessellate(
&mut self,
input: impl IntoIterator<Item = PathEvent>,
options: &StrokeOptions,
builder: &mut dyn StrokeGeometryBuilder
) -> TessellationResult
[src]
&mut self,
input: impl IntoIterator<Item = PathEvent>,
options: &StrokeOptions,
builder: &mut dyn StrokeGeometryBuilder
) -> TessellationResult
Compute the tessellation from a path iterator.
pub fn tessellate_with_ids(
&mut self,
path: impl IntoIterator<Item = IdEvent>,
positions: &impl PositionStore,
custom_attributes: Option<&dyn AttributeStore>,
options: &StrokeOptions,
builder: &mut dyn StrokeGeometryBuilder
) -> TessellationResult
[src]
&mut self,
path: impl IntoIterator<Item = IdEvent>,
positions: &impl PositionStore,
custom_attributes: Option<&dyn AttributeStore>,
options: &StrokeOptions,
builder: &mut dyn StrokeGeometryBuilder
) -> TessellationResult
Compute the tessellation from a path iterator.
pub fn tessellate_path<'l>(
&'l mut self,
path: impl Into<PathSlice<'l>>,
options: &'l StrokeOptions,
builder: &'l mut dyn StrokeGeometryBuilder
) -> TessellationResult
[src]
&'l mut self,
path: impl Into<PathSlice<'l>>,
options: &'l StrokeOptions,
builder: &'l mut dyn StrokeGeometryBuilder
) -> TessellationResult
Compute the tessellation from a path slice.
The tessellator will internally only track vertex sources and interpolated attributes if the path has interpolated attributes.
pub fn builder<'l>(
&'l mut self,
options: &'l StrokeOptions,
output: &'l mut dyn StrokeGeometryBuilder
) -> StrokeBuilder<'l>
[src]
&'l mut self,
options: &'l StrokeOptions,
output: &'l mut dyn StrokeGeometryBuilder
) -> StrokeBuilder<'l>
Tessellate directly from a sequence of PathBuilder
commands, without
creating an intermediate path data structure.
The returned builder implements the lyon_path::traits::PathBuilder
trait,
is compatible with the all PathBuilder
adapters.
It also has all requirements documented in PathBuilder
(All sub-paths must be
wrapped in a begin
/end
pair).
Example
use lyon_tessellation::{StrokeTessellator, StrokeOptions}; use lyon_tessellation::geometry_builder::{simple_builder, VertexBuffers}; use lyon_tessellation::path::traits::*; use lyon_tessellation::math::{Point, point}; let mut buffers: VertexBuffers<Point, u16> = VertexBuffers::new(); let mut vertex_builder = simple_builder(&mut buffers); let mut tessellator = StrokeTessellator::new(); let options = StrokeOptions::default(); // Create a temporary builder (borrows the tessellator). let mut builder = tessellator.builder(&options, &mut vertex_builder); // Build the path directly in the tessellator, skipping an intermediate data // structure. builder.begin(point(0.0, 0.0)); builder.line_to(point(10.0, 0.0)); builder.line_to(point(10.0, 10.0)); builder.line_to(point(0.0, 10.0)); builder.end(true); // Finish the tessellation and get the result. let result = builder.build();
pub fn tessellate_polygon(
&mut self,
polygon: Polygon<'_, Point>,
options: &StrokeOptions,
output: &mut dyn StrokeGeometryBuilder
) -> TessellationResult
[src]
&mut self,
polygon: Polygon<'_, Point>,
options: &StrokeOptions,
output: &mut dyn StrokeGeometryBuilder
) -> TessellationResult
Tessellate the stroke for a Polygon
.
pub fn tessellate_rectangle(
&mut self,
rect: &Rect,
options: &StrokeOptions,
output: &mut dyn StrokeGeometryBuilder
) -> TessellationResult
[src]
&mut self,
rect: &Rect,
options: &StrokeOptions,
output: &mut dyn StrokeGeometryBuilder
) -> TessellationResult
Tessellate the stroke for an axis-aligned rectangle.
pub fn tessellate_circle(
&mut self,
center: Point,
radius: f32,
options: &StrokeOptions,
output: &mut dyn StrokeGeometryBuilder
) -> TessellationResult
[src]
&mut self,
center: Point,
radius: f32,
options: &StrokeOptions,
output: &mut dyn StrokeGeometryBuilder
) -> TessellationResult
Tessellate the stroke for a circle.
pub fn tessellate_ellipse(
&mut self,
center: Point,
radii: Vector,
x_rotation: Angle,
winding: Winding,
options: &StrokeOptions,
output: &mut dyn StrokeGeometryBuilder
) -> TessellationResult
[src]
&mut self,
center: Point,
radii: Vector,
x_rotation: Angle,
winding: Winding,
options: &StrokeOptions,
output: &mut dyn StrokeGeometryBuilder
) -> TessellationResult
Tessellate the stroke for an ellipse.
Trait Implementations
impl Default for StrokeTessellator
[src]
fn default() -> StrokeTessellator
[src]
Auto Trait Implementations
impl RefUnwindSafe for StrokeTessellator
impl Send for StrokeTessellator
impl Sync for StrokeTessellator
impl Unpin for StrokeTessellator
impl UnwindSafe for StrokeTessellator
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,