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

◆ polygon_bounds()

std::function< bool(glm::vec2)> MayaFlux::Kinesis::polygon_bounds ( std::span< const glm::vec2 >  vertices)
inline

Containment test for a convex or concave polygon.

Uses the winding number algorithm, which handles both convex and non-convex polygons correctly. Vertices are in NDC, ordered either clockwise or counter-clockwise.

Parameters
verticesPolygon vertices. Copied into the closure.

Definition at line 272 of file Bounds.hpp.

273{
274 std::vector<glm::vec2> verts(vertices.begin(), vertices.end());
275 return [verts = std::move(verts)](glm::vec2 p) {
276 int winding = 0;
277 size_t n = verts.size();
278 for (size_t i = 0; i < n; ++i) {
279 glm::vec2 a = verts[i];
280 glm::vec2 b = verts[(i + 1) % n];
281 if (a.y <= p.y) {
282 if (b.y > p.y) {
283 float cross = (b.x - a.x) * (p.y - a.y)
284 - (b.y - a.y) * (p.x - a.x);
285 if (cross > 0.0F)
286 ++winding;
287 }
288 } else {
289 if (b.y <= p.y) {
290 float cross = (b.x - a.x) * (p.y - a.y)
291 - (b.y - a.y) * (p.x - a.x);
292 if (cross < 0.0F)
293 --winding;
294 }
295 }
296 }
297 return winding != 0;
298 };
299}
size_t a
size_t b

References a, and b.

Referenced by MayaFlux::Portal::Forma::Geometry::drawable_canvas(), and MayaFlux::Portal::Forma::Geometry::position_picker().

+ Here is the caller graph for this function: