From d0d19cff391a3df1bfa8cba6f902aeb1abdb01ab Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Tue, 20 Jun 2023 11:48:51 -0700 Subject: [PATCH] libsysprof-analyze: use doubles for reference data We only want to move to float for the internal 0..1 positions which are used to draw to the screen (to reduce how much data we hold on to). But for the data we need to calculate those 0..1 positions, we want better precision for large numbers. Use double for all of those. --- src/libsysprof-analyze/sysprof-xy-series.c | 39 ++++++++++++---------- src/libsysprof-analyze/sysprof-xy-series.h | 20 +++++------ src/libsysprof-gtk/sysprof-depth-layer.c | 2 +- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/libsysprof-analyze/sysprof-xy-series.c b/src/libsysprof-analyze/sysprof-xy-series.c index 8b42a688..75fcce1c 100644 --- a/src/libsysprof-analyze/sysprof-xy-series.c +++ b/src/libsysprof-analyze/sysprof-xy-series.c @@ -17,8 +17,11 @@ * * SPDX-License-Identifier: GPL-3.0-or-later */ + #include "config.h" +#include + #include "sysprof-xy-series.h" struct _SysprofXYSeries @@ -30,14 +33,14 @@ struct _SysprofXYSeries GArray *values; /* Our bounds for non-normalized values */ - float min_x; - float min_y; - float max_x; - float max_y; + double min_x; + double min_y; + double max_x; + double max_y; /* Pre-calculated distance between min/max */ - float x_distance; - float y_distance; + double x_distance; + double y_distance; /* Used for warning on items-changed */ gulong items_changed_handler; @@ -73,10 +76,10 @@ warn_on_items_changed_cb (GListModel *model, */ SysprofXYSeries * sysprof_xy_series_new (GListModel *model, - float min_x, - float min_y, - float max_x, - float max_y) + double min_x, + double min_y, + double max_x, + double max_y) { SysprofXYSeries *self; @@ -89,6 +92,8 @@ sysprof_xy_series_new (GListModel *model, self->min_y = min_y; self->max_x = max_x; self->max_y = max_y; + self->x_distance = max_x - min_x; + self->y_distance = max_y - min_y; self->items_changed_handler = g_signal_connect (self->model, "items-changed", @@ -121,8 +126,8 @@ sysprof_xy_series_unref (SysprofXYSeries *self) void sysprof_xy_series_add (SysprofXYSeries *self, - float x, - float y, + double x, + double y, guint index) { SysprofXYSeriesValue value; @@ -158,7 +163,7 @@ sysprof_xy_series_get_model (SysprofXYSeries *self) const SysprofXYSeriesValue * sysprof_xy_series_get_values (const SysprofXYSeries *self, - guint *n_values) + guint *n_values) { *n_values = self->values->len; return &g_array_index (self->values, SysprofXYSeriesValue, 0); @@ -195,10 +200,10 @@ sysprof_xy_series_sort (SysprofXYSeries *self) void sysprof_xy_series_get_range (SysprofXYSeries *self, - float *min_x, - float *min_y, - float *max_x, - float *max_y) + double *min_x, + double *min_y, + double *max_x, + double *max_y) { g_return_if_fail (self != NULL); diff --git a/src/libsysprof-analyze/sysprof-xy-series.h b/src/libsysprof-analyze/sysprof-xy-series.h index db61d584..c0f16049 100644 --- a/src/libsysprof-analyze/sysprof-xy-series.h +++ b/src/libsysprof-analyze/sysprof-xy-series.h @@ -42,18 +42,18 @@ SYSPROF_AVAILABLE_IN_ALL GType sysprof_xy_series_get_type (void) G_GNUC_CONST; SYSPROF_AVAILABLE_IN_ALL SysprofXYSeries *sysprof_xy_series_new (GListModel *model, - float min_x, - float min_y, - float max_x, - float max_y); + double min_x, + double min_y, + double max_x, + double max_y); SYSPROF_AVAILABLE_IN_ALL SysprofXYSeries *sysprof_xy_series_ref (SysprofXYSeries *self); SYSPROF_AVAILABLE_IN_ALL void sysprof_xy_series_unref (SysprofXYSeries *self); SYSPROF_AVAILABLE_IN_ALL void sysprof_xy_series_add (SysprofXYSeries *self, - float x, - float y, + double x, + double y, guint index); SYSPROF_AVAILABLE_IN_ALL void sysprof_xy_series_sort (SysprofXYSeries *self); @@ -64,10 +64,10 @@ const SysprofXYSeriesValue *sysprof_xy_series_get_values (const SysprofXYSeries guint *n_values); SYSPROF_AVAILABLE_IN_ALL void sysprof_xy_series_get_range (SysprofXYSeries *self, - float *min_x, - float *min_y, - float *max_x, - float *max_y); + double *min_x, + double *min_y, + double *max_x, + double *max_y); G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofXYSeries, sysprof_xy_series_unref) diff --git a/src/libsysprof-gtk/sysprof-depth-layer.c b/src/libsysprof-gtk/sysprof-depth-layer.c index 5456076d..67829580 100644 --- a/src/libsysprof-gtk/sysprof-depth-layer.c +++ b/src/libsysprof-gtk/sysprof-depth-layer.c @@ -47,7 +47,7 @@ sysprof_depth_layer_snapshot (GtkWidget *widget, SysprofDepthLayer *self = (SysprofDepthLayer *)widget; const SysprofXYSeriesValue *values; guint n_values; - float min_x, max_x; + double min_x, max_x; int line_width; int width; int height;