diff options
author | Sylvain Munaut <tnt@246tNt.com> | 2014-05-07 16:48:28 +0200 |
---|---|---|
committer | Sylvain Munaut <tnt@246tNt.com> | 2014-07-22 10:16:39 +0200 |
commit | 2fa5b6cf672d0d054ea3f4b9959fc2780d9b121e (patch) | |
tree | d3be00f219f7bbbda236708c355ba6cb0dc97164 /lib/fosphor | |
parent | 223968ad8e1de93d957b2bad86bd84a024b6f188 (diff) |
fosphor/gl: Fix the frequency axis when freq_{start,stop} are used
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Diffstat (limited to 'lib/fosphor')
-rw-r--r-- | lib/fosphor/gl.c | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/lib/fosphor/gl.c b/lib/fosphor/gl.c index 8eae878..6857b30 100644 --- a/lib/fosphor/gl.c +++ b/lib/fosphor/gl.c @@ -475,11 +475,34 @@ fosphor_gl_draw(struct fosphor *self, struct fosphor_render *render) } /* Setup frequency axis */ - freq_axis_build(&freq_axis, - self->frequency.center, - self->frequency.span, - render->freq_n_div - ); + if (render->freq_start != 0.0f || render->freq_stop != 1.0f) + { + /* The freq_{start,stop} have some imprecisions due to the floating + * point nature. To avoid this crapping the display of the axis, we + * try to 'round' them */ + + double freq_start = round(1e7 * render->freq_start) / 1e7; + double freq_stop = round(1e7 * render->freq_stop) / 1e7; + + double rel_center = ((freq_stop + freq_start) / 2.0) - 0.5; + double rel_span = (freq_stop - freq_start); + + freq_axis_build(&freq_axis, + self->frequency.center + rel_center * self->frequency.span, + self->frequency.span * rel_span, + render->freq_n_div + ); + } + else + { + /* Use the straight number we were provider without math to + * avoid any imprecisions */ + freq_axis_build(&freq_axis, + self->frequency.center, + self->frequency.span, + render->freq_n_div + ); + } /* Draw grid */ if (render->options & (FRO_LIVE | FRO_MAX_HOLD | FRO_HISTO)) |