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
-
| footprint | Polygon vertices in XZ. Copied into closure. |
| y_min | Lower Y bound (inclusive). |
| y_max | Upper 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];
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 {
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}
References a, b, and q.