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

268{
269 std::vector<glm::vec2> pts(points.begin(), points.end());
270 float t2 = half_thickness * half_thickness;
271 return [pts = std::move(pts), t2](glm::vec2 p) {
272 for (size_t i = 0; i + 1 < pts.size(); ++i) {
273 glm::vec2 a = pts[i];
274 glm::vec2 b = pts[i + 1];
275 glm::vec2 ab = b - a;
276 float len2 = glm::dot(ab, ab);
277 float d2 = 0.0F;
278 if (len2 < 1e-12F) {
279 glm::vec2 ap = p - a;
280 d2 = glm::dot(ap, ap);
281 } else {
282 float t = glm::clamp(glm::dot(p - a, ab) / len2, 0.0F, 1.0F);
283 glm::vec2 proj = a + t * ab;
284 glm::vec2 diff = p - proj;
285 d2 = glm::dot(diff, diff);
286 }
287 if (d2 <= t2)
288 return true;
289 }
290 return false;
291 };
292}
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: