MayaFlux 0.4.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 227 of file Bounds.hpp.

228{
229 std::vector<glm::vec2> verts(vertices.begin(), vertices.end());
230 return [verts = std::move(verts)](glm::vec2 p) {
231 int winding = 0;
232 size_t n = verts.size();
233 for (size_t i = 0; i < n; ++i) {
234 glm::vec2 a = verts[i];
235 glm::vec2 b = verts[(i + 1) % n];
236 if (a.y <= p.y) {
237 if (b.y > p.y) {
238 float cross = (b.x - a.x) * (p.y - a.y)
239 - (b.y - a.y) * (p.x - a.x);
240 if (cross > 0.0F)
241 ++winding;
242 }
243 } else {
244 if (b.y <= p.y) {
245 float cross = (b.x - a.x) * (p.y - a.y)
246 - (b.y - a.y) * (p.x - a.x);
247 if (cross < 0.0F)
248 --winding;
249 }
250 }
251 }
252 return winding != 0;
253 };
254}
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: