MayaFlux 1.0.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 399 of file Bounds.hpp.

403{
404 std::vector<glm::vec2> verts(footprint.begin(), footprint.end());
405 return [verts = std::move(verts), y_min, y_max](const glm::vec3& p) {
406 if (p.y < y_min || p.y > y_max)
407 return false;
408 glm::vec2 q { p.x, p.z };
409 int winding = 0;
410 const size_t n = verts.size();
411 for (size_t i = 0; i < n; ++i) {
412 glm::vec2 a = verts[i];
413 glm::vec2 b = verts[(i + 1) % n];
414 if (a.y <= q.y) {
415 if (b.y > q.y) {
416 float cross = (b.x - a.x) * (q.y - a.y)
417 - (b.y - a.y) * (q.x - a.x);
418 if (cross > 0.0F)
419 ++winding;
420 }
421 } else {
422 if (b.y <= q.y) {
423 float cross = (b.x - a.x) * (q.y - a.y)
424 - (b.y - a.y) * (q.x - a.x);
425 if (cross < 0.0F)
426 --winding;
427 }
428 }
429 }
430 return winding != 0;
431 };
432}
size_t a
size_t b
double q

References a, b, and q.