Fixed logarithmic sliders and HSV conversions on Mac/Linux

Tricky bug, I was calling abs() which resolve to abs(float) under
Windows with the include we have, but abs(int) under Mac/Linux
This commit is contained in:
ocornut 2014-08-13 23:25:42 +01:00
parent 530f103dfe
commit 29863b55ef

View File

@ -439,7 +439,7 @@ static void ImConvertColorRGBtoHSV(float r, float g, float b, float& out_h, floa
} }
const float chroma = r - (g < b ? g : b); const float chroma = r - (g < b ? g : b);
out_h = abs(K + (g - b) / (6.f * chroma + 1e-20f)); out_h = fabsf(K + (g - b) / (6.f * chroma + 1e-20f));
out_s = chroma / (r + 1e-20f); out_s = chroma / (r + 1e-20f);
out_v = r; out_v = r;
} }
@ -2999,8 +2999,8 @@ bool SliderFloat(const char* label, float* v, float v_min, float v_max, const ch
if (v_min * v_max < 0.0f) if (v_min * v_max < 0.0f)
{ {
// Different sign // Different sign
const float linear_dist_min_to_0 = powf(abs(0.0f - v_min), 1.0f/power); const float linear_dist_min_to_0 = powf(fabsf(0.0f - v_min), 1.0f/power);
const float linear_dist_max_to_0 = powf(abs(v_max - 0.0f), 1.0f/power); const float linear_dist_max_to_0 = powf(fabsf(v_max - 0.0f), 1.0f/power);
linear_zero_pos = linear_dist_min_to_0 / (linear_dist_min_to_0+linear_dist_max_to_0); linear_zero_pos = linear_dist_min_to_0 / (linear_dist_min_to_0+linear_dist_max_to_0);
} }
else else
@ -3086,9 +3086,11 @@ bool SliderFloat(const char* label, float* v, float v_min, float v_max, const ch
else else
{ {
// Positive: rescale to the positive range before powering // Positive: rescale to the positive range before powering
float a = normalized_pos; float a;
if (abs(linear_zero_pos - 1.0f) > 1.e-6) if (fabsf(linear_zero_pos - 1.0f) > 1.e-6)
a = (a - linear_zero_pos) / (1.0f - linear_zero_pos); a = (normalized_pos - linear_zero_pos) / (1.0f - linear_zero_pos);
else
a = normalized_pos;
a = powf(a, power); a = powf(a, power);
new_value = ImLerp(ImMax(v_min,0.0f), v_max, a); new_value = ImLerp(ImMax(v_min,0.0f), v_max, a);
} }
@ -4750,10 +4752,10 @@ void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float roun
if ((col >> 24) == 0) if ((col >> 24) == 0)
return; return;
//const float r = ImMin(rounding, ImMin(abs(b.x-a.x), abs(b.y-a.y))*0.5f); //const float r = ImMin(rounding, ImMin(fabsf(b.x-a.x), fabsf(b.y-a.y))*0.5f);
float r = rounding; float r = rounding;
r = ImMin(r, abs(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f )); r = ImMin(r, fabsf(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f ));
r = ImMin(r, abs(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f )); r = ImMin(r, fabsf(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f ));
if (r == 0.0f || rounding_corners == 0) if (r == 0.0f || rounding_corners == 0)
{ {
@ -4783,10 +4785,10 @@ void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, floa
if ((col >> 24) == 0) if ((col >> 24) == 0)
return; return;
//const float r = ImMin(rounding, ImMin(abs(b.x-a.x), abs(b.y-a.y))*0.5f); //const float r = ImMin(rounding, ImMin(fabsf(b.x-a.x), fabsf(b.y-a.y))*0.5f);
float r = rounding; float r = rounding;
r = ImMin(r, abs(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f )); r = ImMin(r, fabsf(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f ));
r = ImMin(r, abs(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f )); r = ImMin(r, fabsf(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f ));
if (r == 0.0f || rounding_corners == 0) if (r == 0.0f || rounding_corners == 0)
{ {