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

◆ extruded_polygon_region()

std::function< bool(glm::vec3)> MayaFlux::Kinesis::extruded_polygon_region ( std::span< const glm::vec2 >  footprint,
float  y_min,
float  y_max 
)
inline

Containment test for a vertically extruded 2D polygon.

The footprint is tested with the winding number algorithm in the XZ plane. The Y axis is the vertical: the point must satisfy y_min <= p.y <= y_max. Covers authored rooms, columns, corridors where the cross-section is constant along Y.

Parameters
footprintPolygon vertices in XZ. Copied into closure.
y_minLower Y bound (inclusive).
y_maxUpper Y bound (inclusive).

Definition at line 354 of file Bounds.hpp.

358{
359 std::vector<glm::vec2> verts(footprint.begin(), footprint.end());
360 return [verts = std::move(verts), y_min, y_max](const glm::vec3& p) {
361 if (p.y < y_min || p.y > y_max)
362 return false;
363 glm::vec2 q { p.x, p.z };
364 int winding = 0;
365 const size_t n = verts.size();
366 for (size_t i = 0; i < n; ++i) {
367 glm::vec2 a = verts[i];
368 glm::vec2 b = verts[(i + 1) % n];
369 if (a.y <= q.y) {
370 if (b.y > q.y) {
371 float cross = (b.x - a.x) * (q.y - a.y)
372 - (b.y - a.y) * (q.x - a.x);
373 if (cross > 0.0F)
374 ++winding;
375 }
376 } else {
377 if (b.y <= q.y) {
378 float cross = (b.x - a.x) * (q.y - a.y)
379 - (b.y - a.y) * (q.x - a.x);
380 if (cross < 0.0F)
381 --winding;
382 }
383 }
384 }
385 return winding != 0;
386 };
387}
size_t a
size_t b
double q

References a, b, and q.