From: Scott Worley Date: Thu, 23 Feb 2023 06:33:28 +0000 (-0800) Subject: Track min & max coordinates X-Git-Url: http://git.scottworley.com/batteryviewer/commitdiff_plain/148e0e28dd0fe98dd9892f598e74851304105748 Track min & max coordinates --- diff --git a/chart.c b/chart.c index 8b05d33..2705783 100644 --- a/chart.c +++ b/chart.c @@ -4,6 +4,7 @@ */ #include "chart.h" +#include #include #define BV_CHART_PRIVATE(obj) \ @@ -13,6 +14,7 @@ typedef struct _BVChartPrivate BVChartPrivate; struct _BVChartPrivate { GArray *points; + float minx, miny, maxx, maxy; }; struct BVChartPoint { @@ -31,6 +33,10 @@ static void bv_chart_init(BVChart *chart) { gboolean clear_ = FALSE; priv->points = g_array_new(zero_terminated, clear_, sizeof(struct BVChartPoint)); + priv->minx = FLT_MAX; + priv->miny = FLT_MAX; + priv->maxx = FLT_MIN; + priv->maxy = FLT_MIN; } GtkWidget *bv_chart_new() { @@ -39,6 +45,14 @@ GtkWidget *bv_chart_new() { void bv_chart_add_point(BVChart *chart, float x, float y) { BVChartPrivate *priv = bv_chart_get_instance_private(chart); + if (x < priv->minx) + priv->minx = x; + if (y < priv->miny) + priv->miny = y; + if (x > priv->maxx) + priv->maxx = x; + if (y > priv->maxy) + priv->maxy = y; struct BVChartPoint p = {.x = x, .y = y}; g_array_append_val(priv->points, p); }