From afcbeb2a796dca2bc889014dbb589b4f7bceb3ea Mon Sep 17 00:00:00 2001
From: Carl Worth <cworth@cworth.org>
Date: Wed, 6 Nov 2013 19:30:28 -0800
Subject: [PATCH] Use cairo_clip to trim out any out-of-view data

Previously, we were simply not drawing line segments where one
endpoint of the segment was outside the bounds of the chart. This had
the problem of omitting a (potentially large) portion of the line
segment that should be visible.

We get the correct result, and more easily, by simply calling
cairo_clip.
---
 acre.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/acre.c b/acre.c
index e3604dc..290bb12 100644
--- a/acre.c
+++ b/acre.c
@@ -848,10 +848,14 @@ _draw_data (acre_t *acre)
     cairo_t *cr = acre->cr;
     unsigned int d, i;
     acre_data_t *data;
-    bool pen_up;
 
     cairo_save (cr);
 
+    cairo_rectangle (cr,
+		     acre->chart.x, acre->chart.y,
+		     acre->chart.width, acre->chart.height);
+    cairo_clip (cr);
+
     cairo_set_source_rgb (cr, 0, 0, 0);
 
     _set_transform_to_data_space (acre);
@@ -864,28 +868,12 @@ _draw_data (acre_t *acre)
 			      acre->colors[color].blue);
 	data = acre->data[d];
 
-	pen_up = true;
 	cairo_new_path (cr);
 
 	for (i = 0; i < data->num_points; i++) {
-	    if (data->points[i].x >= acre->x_axis.view_min &&
-		data->points[i].x <= acre->x_axis.view_max &&
-		data->points[i].y >= acre->y_axis.view_min &&
-		data->points[i].y <= acre->y_axis.view_max)
-	    {
-		if (pen_up)
-		    cairo_move_to (cr,
-				   data->points[i].x,
-				   data->points[i].y);
-		else
-		    cairo_line_to (cr,
-				   data->points[i].x,
-				   data->points[i].y);
-
-		pen_up = false;
-	    } else {
-		pen_up = true;
-	    }
+	    cairo_line_to (cr,
+			   data->points[i].x,
+			   data->points[i].y);
 	}
 	cairo_save (cr);
 	{
-- 
2.45.2