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

◆ drawable_canvas()

MAYAFLUX_API GeometryFn< 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 287 of file Geometry.cpp.

291{
292 return [bounds, color, thickness](
293 const std::vector<float>& v, std::vector<uint8_t>& out, Element& el) {
294 if (v.size() < 2) {
295 out.clear();
296 el.bounds_hint = bounds;
297 el.contains = Kinesis::polygon_bounds(std::span<const glm::vec2> {
298 std::array<glm::vec2, 4> {
299 bounds.min,
300 glm::vec2(bounds.max.x, bounds.min.y),
301 bounds.max,
302 glm::vec2(bounds.min.x, bounds.max.y) } });
303 return;
304 }
305
306 const auto n = v.size();
307 const float x_step = bounds.width() / static_cast<float>(n - 1);
308
309 std::vector<Kakshya::LineVertex> verts;
310 verts.reserve((n - 1) * 2);
311
312 for (size_t i = 0; i + 1 < n; ++i) {
313 const float xa = bounds.min.x + static_cast<float>(i) * x_step;
314 const float xb = bounds.min.x + static_cast<float>(i + 1) * x_step;
315 const float ya = bounds.min.y + std::clamp(v[i], 0.F, 1.F) * bounds.height();
316 const float yb = bounds.min.y + std::clamp(v[i + 1], 0.F, 1.F) * bounds.height();
317
318 verts.push_back({ .position = { xa, ya, 0.F }, .color = color, .thickness = thickness });
319 verts.push_back({ .position = { xb, yb, 0.F }, .color = color, .thickness = thickness });
320 }
321
322 write_verts(out, verts);
323
324 el.bounds_hint = bounds;
325 el.contains = Kinesis::polygon_bounds(std::span<const glm::vec2> {
326 std::array<glm::vec2, 4> {
327 bounds.min,
328 glm::vec2(bounds.max.x, bounds.min.y),
329 bounds.max,
330 glm::vec2(bounds.min.x, bounds.max.y) } });
331 };
332}
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
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::Kinesis::AABB2D::max, MayaFlux::Kinesis::AABB2D::min, MayaFlux::Kinesis::polygon_bounds(), MayaFlux::Kinesis::AABB2D::width(), and write_verts().

+ Here is the call graph for this function: