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

◆ stroke_bounds()

std::function< bool(glm::vec2)> MayaFlux::Kinesis::stroke_bounds ( std::span< const glm::vec2 >  points,
float  half_thickness 
)
inline

Containment test for a polyline with a uniform half-thickness.

Covers open and closed curves equally. A point is inside if its perpendicular distance to any segment is within half_thickness. Suitable for stroke-based interactive regions and cable hit testing.

Parameters
pointsOrdered polyline vertices in NDC.
half_thicknessDistance threshold in NDC units.

Definition at line 312 of file Bounds.hpp.

313{
314 std::vector<glm::vec2> pts(points.begin(), points.end());
315 float t2 = half_thickness * half_thickness;
316 return [pts = std::move(pts), t2](glm::vec2 p) {
317 for (size_t i = 0; i + 1 < pts.size(); ++i) {
318 glm::vec2 a = pts[i];
319 glm::vec2 b = pts[i + 1];
320 glm::vec2 ab = b - a;
321 float len2 = glm::dot(ab, ab);
322 float d2 = 0.0F;
323 if (len2 < 1e-12F) {
324 glm::vec2 ap = p - a;
325 d2 = glm::dot(ap, ap);
326 } else {
327 float t = glm::clamp(glm::dot(p - a, ab) / len2, 0.0F, 1.0F);
328 glm::vec2 proj = a + t * ab;
329 glm::vec2 diff = p - proj;
330 d2 = glm::dot(diff, diff);
331 }
332 if (d2 <= t2)
333 return true;
334 }
335 return false;
336 };
337}
std::vector< glm::vec2 > * points
size_t a
size_t b

References a, b, and points.

Referenced by MayaFlux::Portal::Forma::Geometry::stroke_slider().

+ Here is the caller graph for this function: