MayaFlux 1.0.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,
const std::function< glm::vec2()> &  live_offset = {} 
)
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.

Angles outside the sweep fall in a dead zone and snap to whichever end is nearer, so a knob dragged past its minimum stays at 0 instead of jumping to 1.

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.
live_offsetOptional. Current translation of the drawn control.
Returns
Callable producing a value in [0, 1].

Definition at line 111 of file Projection.hpp.

112 {}) noexcept
113{
114 const float delta = angle_end - angle_start;
115
116 return [center, angle_start, delta, live_offset](glm::vec2 p) -> float {
117 constexpr float k_two_pi = 6.283185307179586F;
118
119 if (std::abs(delta) < 1e-6F)
120 return 0.F;
121
122 const glm::vec2 shift = live_offset ? live_offset() : glm::vec2(0.F);
123 const glm::vec2 d = (p - shift) - center;
124 if (glm::dot(d, d) < 1e-12F)
125 return 0.F;
126
127 float rel = std::fmod(std::atan2(d.y, d.x) - angle_start, k_two_pi);
128 if (delta > 0.F && rel < 0.F) {
129 rel += k_two_pi;
130 } else if (delta < 0.F && rel > 0.F) {
131 rel -= k_two_pi;
132 }
133
134 const float travelled = std::abs(rel);
135 const float sweep = std::abs(delta);
136 const float gap = k_two_pi - sweep;
137 if (travelled <= sweep || gap <= 0.F)
138 return std::clamp(travelled / sweep, 0.F, 1.F);
139
140 return (travelled - sweep) < gap * 0.5F ? 1.F : 0.F;
141 };
142}

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

+ Here is the caller graph for this function: