1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use lyon_tessellation::{
FillGeometryBuilder, FillVertex, FillVertexConstructor, GeometryBuilder, GeometryBuilderError,
StrokeGeometryBuilder, StrokeVertex, StrokeVertexConstructor, VertexId,
};
use crate::{builder::ShapeBuilder, shape::Vertex};
impl FillVertexConstructor<Vertex> for ShapeBuilder {
fn new_vertex(&mut self, mut vertex: FillVertex) -> Vertex {
let position = vertex.position();
let attributes = vertex.interpolated_attributes();
self.new_vertex(position, attributes)
}
}
impl StrokeVertexConstructor<Vertex> for ShapeBuilder {
fn new_vertex(&mut self, mut vertex: StrokeVertex) -> Vertex {
let position = vertex.position();
let attributes = vertex.interpolated_attributes();
self.new_vertex(position, attributes)
}
}
impl FillGeometryBuilder for ShapeBuilder {
fn add_fill_vertex(
&mut self,
mut vertex: FillVertex,
) -> Result<VertexId, GeometryBuilderError> {
let position = vertex.position();
let attributes = vertex.interpolated_attributes();
self.add_vertex(position, attributes)
}
}
impl StrokeGeometryBuilder for ShapeBuilder {
fn add_stroke_vertex(
&mut self,
mut vertex: StrokeVertex,
) -> Result<VertexId, GeometryBuilderError> {
let position = vertex.position();
let attributes = vertex.interpolated_attributes();
self.add_vertex(position, attributes)
}
}
impl GeometryBuilder for ShapeBuilder {
fn begin_geometry(&mut self) {}
fn end_geometry(&mut self) -> lyon_tessellation::Count {
lyon_tessellation::Count {
vertices: self.vertices.len() as u32,
indices: self.indicies.len() as u32,
}
}
fn add_triangle(&mut self, a: VertexId, b: VertexId, c: VertexId) {
self.indicies.push(a.0 as u16);
self.indicies.push(b.0 as u16);
self.indicies.push(c.0 as u16);
}
fn abort_geometry(&mut self) {
self.vertices.clear();
self.indicies.clear();
}
}