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 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];
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 {
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}
References a, b, and q.