MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ drawable_canvas()

MAYAFLUX_API Form< std::vector< float > > MayaFlux::Portal::Forma::Geometry::drawable_canvas ( Kinesis::AABB2D  bounds,
glm::vec3  color = glm::vec3(0.8F),
float  thickness = 1.5F 
)

Geometry function for a drawable curve canvas in NDC space.

Renders the sample vector as a LINE_LIST polyline. Each adjacent sample pair becomes one segment. The hit region covers the full canvas bounds.

Parameters
boundsCanvas extent in NDC.
colorLine color.
thicknessLineVertex thickness value.

Definition at line 335 of file FormFactory.cpp.

339{
340 GeometryFn<std::vector<float>> fn = [bounds, color, thickness](
341 const std::vector<float>& v, std::vector<uint8_t>& out, Element& el) {
342 if (v.size() < 2) {
343 out.clear();
344 el.bounds_hint = bounds;
345 el.contains = Kinesis::polygon_bounds(std::span<const glm::vec2> {
346 std::array<glm::vec2, 4> {
347 bounds.min,
348 glm::vec2(bounds.max.x, bounds.min.y),
349 bounds.max,
350 glm::vec2(bounds.min.x, bounds.max.y) } });
351 return;
352 }
353
354 const auto n = v.size();
355 const float x_step = bounds.width() / static_cast<float>(n - 1);
356
357 std::vector<Kakshya::LineVertex> verts;
358 verts.reserve((n - 1) * 2);
359
360 for (size_t i = 0; i + 1 < n; ++i) {
361 const float xa = bounds.min.x + static_cast<float>(i) * x_step;
362 const float xb = bounds.min.x + static_cast<float>(i + 1) * x_step;
363 const float ya = bounds.min.y + std::clamp(v[i], 0.F, 1.F) * bounds.height();
364 const float yb = bounds.min.y + std::clamp(v[i + 1], 0.F, 1.F) * bounds.height();
365
366 verts.push_back({ .position = { xa, ya, 0.F }, .color = color, .thickness = thickness });
367 verts.push_back({ .position = { xb, yb, 0.F }, .color = color, .thickness = thickness });
368 }
369
370 write_verts(out, verts);
371
372 el.bounds_hint = bounds;
373 el.contains = Kinesis::polygon_bounds(std::span<const glm::vec2> {
374 std::array<glm::vec2, 4> {
375 bounds.min,
376 glm::vec2(bounds.max.x, bounds.min.y),
377 bounds.max,
378 glm::vec2(bounds.min.x, bounds.max.y) } });
379 };
380
381 Form<std::vector<float>> form { std::move(fn) };
382 form.topology = Graphics::PrimitiveTopology::LINE_LIST;
383 form.wire = paint_over(bounds);
384 return form;
385}
auto paint_over(Kinesis::AABB2D bounds)
Produce a Form::wire that registers canvas painting over bounds.
void write_verts(std::vector< uint8_t > &out, const std::vector< V > &verts)
Write a vertex array into a GeometryFn output buffer.
Definition Geometry.hpp:35
std::function< void(T value, std::vector< uint8_t > &out_bytes, Element &element)> GeometryFn
Geometry function signature.
Definition Mapped.hpp:64
float height() const noexcept
Definition Bounds.hpp:38
bool contains(glm::vec2 p) const noexcept
Definition Bounds.hpp:25
float width() const noexcept
Definition Bounds.hpp:37
A bounded, renderable region on a window surface.
Definition Element.hpp:58

References MayaFlux::Kinesis::AABB2D::contains(), MayaFlux::Kinesis::AABB2D::height(), MayaFlux::Portal::Graphics::LINE_LIST, MayaFlux::Kinesis::AABB2D::max, MayaFlux::Kinesis::AABB2D::min, paint_over(), MayaFlux::Kinesis::polygon_bounds(), MayaFlux::Portal::Forma::Geometry::Form< T >::topology, MayaFlux::Kinesis::AABB2D::width(), and write_verts().

+ Here is the call graph for this function: