[goffice] Fixed rounding errors in limits displayed in contour plot legend. [#666292]
- From: Jean BrÃfort <jbrefort src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Fixed rounding errors in limits displayed in contour plot legend. [#666292]
- Date: Sat, 17 Dec 2011 17:04:18 +0000 (UTC)
commit ee9e91185c98b8382b95dc91dc8195389de371d8
Author: Jean Brefort <jean brefort normalesup org>
Date: Sat Dec 17 18:03:43 2011 +0100
Fixed rounding errors in limits displayed in contour plot legend. [#666292]
ChangeLog | 6 ++++++
NEWS | 4 ++++
plugins/plot_surface/gog-contour.c | 13 +++++++------
3 files changed, 17 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e0291f9..cf0a7b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-12-17 Jean Brefort <jean brefort normalesup org>
+
+ * plugins/plot_surface/gog-contour.c
+ (gog_contour_plot_foreach_elem): fixed rounding errors in limits displayed
+ in the legend. [#666292]
+
2011-12-08 Jean Brefort <jean brefort normalesup org>
* configure.in: remove pixmaps/Makefile.
diff --git a/NEWS b/NEWS
index 2246b32..5cbff5d 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,10 @@ Andreas:
* Fix recognition of formats with SI prefix by format selector.
[#665303]
+Jean:
+ * Fixed rounding errors in limits displayed in contour plot legend.
+ [#666292]
+
Morten:
* Embed library ui files into library.
* Embed svg-patterns.xml and error bar image files too.
diff --git a/plugins/plot_surface/gog-contour.c b/plugins/plot_surface/gog-contour.c
index 8a1a3bd..472f890 100644
--- a/plugins/plot_surface/gog-contour.c
+++ b/plugins/plot_surface/gog-contour.c
@@ -140,16 +140,17 @@ gog_contour_plot_foreach_elem (GogPlot *plot, gboolean only_visible,
GOColor *color;
GogAxisTick *zticks;
double *limits;
- double minimum, maximum;
+ double minimum, maximum, epsilon;
char const *separator = go_locale_get_decimal ()->str;
gog_axis_get_bounds (axis, &minimum, &maximum);
nticks = gog_axis_get_ticks (axis, &zticks);
i = j = 0;
+ epsilon = (maximum - minimum) / nticks * 1e-10; /* should avoid rounding errors */
while (zticks[i].type != GOG_AXIS_TICK_MAJOR)
i++;
- if (minimum < zticks[i].position) {
+ if (zticks[i].position - minimum > epsilon) {
limits = g_new (double, nticks + 2);
limits[j++] = minimum;
} else
@@ -157,7 +158,7 @@ gog_contour_plot_foreach_elem (GogPlot *plot, gboolean only_visible,
for (; i < nticks; i++)
if (zticks[i].type == GOG_AXIS_TICK_MAJOR)
limits[j++] = zticks[i].position;
- if (j == 0 || maximum > limits[j - 1])
+ if (j == 0 || maximum - limits[j - 1] > epsilon)
limits[j] = maximum;
else
j--;
@@ -181,11 +182,11 @@ gog_contour_plot_foreach_elem (GogPlot *plot, gboolean only_visible,
for (i = 0; i < j; i++) {
style->fill.pattern.back = color[i];
label = g_strdup_printf ("[%g%s %g%c", limits[j - i - 1], separator,
- limits[j - i], (limits[i - j] > minimum)? '[':']');
+ limits[j - i], (limits[i - j] - minimum > epsilon)? '[':']');
(func) (i, style, label, NULL, data);
g_free (label);
}
- if (limits[i - j] > minimum) {
+ if (limits[i - j] - minimum > epsilon) {
gog_theme_fillin_style (theme, style, GOG_OBJECT (plot->series->data), i, style->interesting_fields);
label = g_strdup_printf ("[%g%s %g]", minimum, separator,
limits[i - j]);
@@ -193,7 +194,7 @@ gog_contour_plot_foreach_elem (GogPlot *plot, gboolean only_visible,
g_free (label);
}
} else {
- if (minimum < limits[0]) {
+ if (epsilon < limits[0] - minimum) {
style->fill.pattern.back = color[0];
label = g_strdup_printf ("[%g%s %g]", minimum, separator,
limits[0]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]