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

◆ angle_fraction() [2/2]

std::function< float(glm::vec2)> MayaFlux::Kinesis::angle_fraction ( glm::vec2  center,
float  angle_start,
float  angle_end 
)
inlinenoexcept

Fraction along an angular sweep about center.

Inverse to radial, which places the indicator at angle_start + value * (angle_end - angle_start). Handles sweeps in either direction and sweeps crossing the atan2 discontinuity. The cursor's distance from the centre is ignored, so the control remains responsive outside the drawn radius, which is what a knob gesture expects.

Points at the exact centre return zero rather than an undefined angle.

Parameters
centerSweep centre in NDC.
angle_startAngle in radians corresponding to value 0.
angle_endAngle in radians corresponding to value 1.
Returns
Callable producing a value in [0, 1].

Definition at line 90 of file Projection.hpp.

91{
92 const float delta = angle_end - angle_start;
93
94 return [center, angle_start, delta](glm::vec2 p) -> float {
95 constexpr float k_two_pi = 6.283185307179586F;
96
97 if (std::abs(delta) < 1e-6F)
98 return 0.F;
99
100 const glm::vec2 d = p - center;
101 if (glm::dot(d, d) < 1e-12F)
102 return 0.F;
103
104 float rel = std::fmod(std::atan2(d.y, d.x) - angle_start, k_two_pi);
105 if (delta > 0.F && rel < 0.F) {
106 rel += k_two_pi;
107 } else if (delta < 0.F && rel > 0.F) {
108 rel -= k_two_pi;
109 }
110
111 return std::clamp(rel / delta, 0.F, 1.F);
112 };
113}

Referenced by angle_fraction(), and MayaFlux::Portal::Forma::Geometry::radial().

+ Here is the caller graph for this function: