9 std::vector<uint8_t> polygon_bytes(std::span<const glm::vec2> ndc,
10 std::span<const uint32_t> starts,
11 std::span<
const std::array<uint32_t, 3>> triangles,
12 std::span<const glm::vec4> colors,
float thickness)
14 std::vector<uint8_t> out;
16 if (thickness > 0.F) {
17 std::vector<size_t> bounds { 0 };
18 bounds.insert(bounds.end(), starts.begin(), starts.end());
19 bounds.push_back(ndc.size());
21 std::vector<Kakshya::LineVertex> verts;
22 verts.reserve(ndc.size() * 2);
23 for (
size_t ring = 0; ring + 1 < bounds.size(); ++ring) {
24 const size_t begin = bounds[ring];
25 const size_t count = bounds[ring + 1] - begin;
26 for (
size_t k = 0; k <
count; ++k) {
27 const size_t from = begin + k;
28 const size_t to = begin + (k + 1) % count;
29 verts.push_back(Kakshya::LineVertex {
30 .position = { ndc[from].x, ndc[from].y, 0.F },
31 .color = colors[from],
32 .thickness = thickness,
34 verts.push_back(Kakshya::LineVertex {
35 .position = { ndc[to].x, ndc[to].y, 0.F },
37 .thickness = thickness,
45 std::vector<Kakshya::Vertex> verts;
46 verts.reserve(triangles.size() * 3);
47 for (
const auto& triangle : triangles) {
48 for (
const uint32_t k : triangle) {
49 verts.push_back(Kakshya::Vertex {
50 .position = { ndc[k].x, ndc[k].y, 0.F },
63 std::vector<glm::vec2> positions;
64 positions.reserve(input.
vertices.size());
71 [vertices = input.
vertices](
const std::monostate&, std::vector<uint8_t>& out) {
72 Geometry::write_verts(out, vertices);
81 const auto region =
region_of(placement, error);
87 const glm::vec2 ndc = region->point_at({ vertex.
position.x, vertex.
position.y });
96 const bool per_vertex = !input.
colors.empty();
97 if (input.
points.size() < 3) {
98 error =
"points needs at least three x y pairs";
101 if (per_vertex && input.
colors.size() != input.
points.size()) {
102 error =
"colors needs one r g b a per point";
106 error =
"thickness may not be negative";
110 std::vector<glm::vec2> unit = input.
points;
111 std::vector<glm::vec4> vertex_colors = input.
colors;
112 std::vector<uint32_t> starts;
114 if (hole.
points.size() < 3) {
115 error =
"a hole needs at least three x y pairs";
119 error =
"a hole needs one r g b a per point exactly when the outline has colors";
122 starts.push_back(
static_cast<uint32_t
>(unit.size()));
123 unit.insert(unit.end(), hole.
points.begin(), hole.
points.end());
124 vertex_colors.insert(vertex_colors.end(), hole.
colors.begin(), hole.
colors.end());
127 vertex_colors.assign(unit.size(), input.
color);
129 const auto region =
region_of(placement, error);
133 std::vector<glm::vec2> ndc;
134 ndc.reserve(unit.size());
135 for (
const glm::vec2 point : unit)
136 ndc.push_back(region->point_at(point));
138 const bool stroke = input.
thickness > 0.F;
139 std::vector<std::array<uint32_t, 3>> triangles;
142 if (triangles.empty()) {
143 error =
"the outline and holes do not form a valid region";
148 const std::vector<uint8_t> base = polygon_bytes(ndc, starts, triangles, vertex_colors, input.
thickness);
149 std::vector<uint8_t> active = base;
151 const std::vector<glm::vec4> active_colors(unit.size(), *input.
active);
152 active = polygon_bytes(ndc, starts, triangles, active_colors, input.
thickness);
156 const Topology topology = stroke ? Topology::LINE_LIST : Topology::TRIANGLE_LIST;
157 std::vector<glm::vec2> drawn;
161 drawn.reserve(triangles.size() * 3);
162 for (
const auto& triangle : triangles) {
163 for (
const uint32_t k : triangle)
164 drawn.push_back(ndc[k]);
169 ContainmentSource { .positions = drawn, .topology = topology, .placement = region },
174 const size_t capacity = stroke
178 [base, active](
const bool& on, std::vector<uint8_t>& out) { out = on ? active : base; },
std::vector< MeshVertex > to_mesh_vertices(std::span< const Vertex > vertices, glm::vec2 weight_range)
Batch-project raw Vertex vector to MeshVertex.
std::vector< double > count(std::span< const double > data, size_t n_windows, uint32_t hop_size, uint32_t window_size)
Sample count per window (as double for pipeline uniformity).
std::vector< std::array< uint32_t, 3 > > triangulate_polygon(std::span< const glm::vec2 > pts, std::span< const uint32_t > hole_starts)
Ear-clipping triangulation of a polygon with optional holes, as index triples.
PrimitiveTopology
Vertex assembly primitive topology.
Vertex type for line primitives (LINE_LIST / LINE_STRIP topology).
Vertex type for indexed triangle mesh primitives (TRIANGLE_LIST topology).
Type-neutral vertex carrying the universal 68-byte attribute layout.