[genius] Wed Feb 03 00:10:42 2010 Jiri (George) Lebl <jirka 5z com>



commit aec7ebd5cd96ef03077d2340870e981cf6588e99
Author: Jiri (George) Lebl <jirka 5z com>
Date:   Wed Feb 3 00:11:59 2010 -0600

    Wed Feb 03 00:10:42 2010  Jiri (George) Lebl <jirka 5z com>
    
    	* src/graphing.c: when drawing slopefield solutions, allow the graph
    	  to leave window by a small fudge factor of 1/100 of the window size
    
    	* gtkextra/gtkplot.c, gtkextra/gtkplot3d.c: add some sanity fixes to
    	  fix crashes on tick calculations when the supplied data is less
    	  than sane.  The tick calculation stuff is very evil and there are
    	  still some crashes around when doing insensible things with
    	  graphs.

 ChangeLog              |   11 +++++++++++
 NEWS                   |    2 ++
 gtkextra/gtkplot.c     |    7 +++++++
 gtkextra/gtkplot3d.c   |   13 ++++++++++++-
 gtkextra/gtkplotdata.c |    1 +
 src/graphing.c         |   15 +++++++++------
 6 files changed, 42 insertions(+), 7 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c11318e..bf06431 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Wed Feb 03 00:10:42 2010  Jiri (George) Lebl <jirka 5z com>
+
+	* src/graphing.c: when drawing slopefield solutions, allow the graph
+	  to leave window by a small fudge factor of 1/100 of the window size
+
+	* gtkextra/gtkplot.c, gtkextra/gtkplot3d.c: add some sanity fixes to
+	  fix crashes on tick calculations when the supplied data is less
+	  than sane.  The tick calculation stuff is very evil and there are
+	  still some crashes around when doing insensible things with 
+	  graphs.
+
 Tue Feb 02 21:42:42 2010  Jiri (George) Lebl <jirka 5z com>
 
 	* src/gnome-genius.c: fix compilation when gtksourceview is disabled
diff --git a/NEWS b/NEWS
index 7852ec8..4fbb6c3 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,8 @@ Changes to 1.0.10
 * Allow comparisons (== and !=) with null, treating it as an empty matrix
 * Fix compilation without gtksourceview (thanks to Joe Sapp for pointing this
   out)
+* Fix some crashes in plotting code
+* Allow slopefield solutions to leave plot window by a small fudge factor.
 
 * For some of the changes the author (Jiri) was partially supported by
   NSF grant DMS 0900885 and the University of Illinois at Urbana-Champaign
diff --git a/gtkextra/gtkplot.c b/gtkextra/gtkplot.c
index 735e075..c6fbb27 100644
--- a/gtkextra/gtkplot.c
+++ b/gtkextra/gtkplot.c
@@ -1439,6 +1439,7 @@ gtk_plot_axis_init (GtkPlotAxis *axis)
   axis->ticks.nmajorticks = 0;
   axis->ticks.nminorticks = 0;
   axis->ticks.values = NULL;
+  axis->ticks.nticks = 0;
   axis->ticks.set_limits = FALSE;
   axis->ticks.begin = 0;
   axis->ticks.end = 0;
@@ -1893,6 +1894,7 @@ gtk_plot_axis_destroy (GtkObject *object)
   if(axis->ticks.values){
     g_free (axis->ticks.values);
     axis->ticks.values = NULL;
+    axis->ticks.nticks = 0;
   }
 
   if(axis->tick_labels) g_object_unref(G_OBJECT(axis->tick_labels));
@@ -2181,6 +2183,7 @@ gtk_plot_axis_construct(GtkPlotAxis *axis, GtkPlotOrientation orientation)
   axis->title.border_space = 2;
   axis->title.shadow_width = 3;
   axis->ticks.values = NULL;
+  axis->ticks.nticks = 0;
 
   axis->ticks_transform = gtk_plot_ticks_transform;
   axis->ticks_inverse = gtk_plot_ticks_inverse;
@@ -4965,6 +4968,7 @@ printf("%f %f\n",max/ticks->step,ceil(max/ticks->step));
   if(ticks->values){
      g_free(ticks->values);
      ticks->values = NULL;
+     ticks->nticks = 0;
   }
 
   ticks->nmajorticks = 0; 
@@ -5099,6 +5103,7 @@ gtk_plot_ticks_recalc(GtkPlotAxis *axis)
     a1.min = ticks->min;
     a1.max = ticks->break_min;
     a1.values = NULL;
+    a1.nticks = 0;
     gtk_plot_real_ticks_recalc(&a1);
 
     a2.scale = ticks->break_scale;
@@ -5110,11 +5115,13 @@ gtk_plot_ticks_recalc(GtkPlotAxis *axis)
     a2.min = ticks->break_max;
     a2.max = ticks->max;
     a2.values = NULL;
+    a2.nticks = 0;
     gtk_plot_real_ticks_recalc(&a2);
 
     if(ticks->values){
       g_free(ticks->values);
       ticks->values = NULL;
+      ticks->nticks = 0;
     }
     ticks->nmajorticks = a1.nmajorticks+a2.nmajorticks;
     ticks->nminorticks = a1.nminorticks+a2.nminorticks;
diff --git a/gtkextra/gtkplot3d.c b/gtkextra/gtkplot3d.c
index a50247a..8b4c954 100644
--- a/gtkextra/gtkplot3d.c
+++ b/gtkextra/gtkplot3d.c
@@ -574,6 +574,7 @@ gtk_plot3d_init (GtkPlot3D *plot)
   plot->ax->ticks.nmajorticks = 0;
   plot->ax->ticks.nminorticks = 0;
   plot->ax->ticks.values = NULL;
+  plot->ax->ticks.nticks = 0;
   plot->ax->ticks.set_limits = FALSE;
   plot->ax->ticks.begin = 0;
   plot->ax->ticks.end = 0;
@@ -583,6 +584,7 @@ gtk_plot3d_init (GtkPlot3D *plot)
   plot->ay->ticks.nmajorticks = 0;
   plot->ay->ticks.nminorticks = 0;
   plot->ay->ticks.values = NULL;
+  plot->ay->ticks.nticks = 0;
   plot->ay->ticks.set_limits = FALSE;
   plot->ay->ticks.begin = 0;
   plot->ay->ticks.end = 0;
@@ -592,6 +594,7 @@ gtk_plot3d_init (GtkPlot3D *plot)
   plot->az->ticks.nmajorticks = 0;
   plot->az->ticks.nminorticks = 0;
   plot->az->ticks.values = NULL;
+  plot->az->ticks.nticks = 0;
   plot->az->ticks.set_limits = FALSE;
   plot->az->ticks.begin = 0;
   plot->az->ticks.end = 0;
@@ -1550,6 +1553,9 @@ gtk_plot3d_draw_grids(GtkPlot3D *plot, GtkPlotAxis *axis, GtkPlotVector delta)
 
   widget = GTK_WIDGET(plot);
 
+  /* no values! */
+  if (axis->ticks.values == NULL) return;
+
   xp = GTK_PLOT(plot)->internal_allocation.x;
   yp = GTK_PLOT(plot)->internal_allocation.y;
   width = GTK_PLOT(plot)->internal_allocation.width;
@@ -1639,6 +1645,9 @@ gtk_plot3d_draw_axis(GtkPlot3D *plot,
   gint size;
   gint ticks_length;
 
+  if (axis->ticks.values == NULL)
+    return;
+
   widget = GTK_WIDGET(plot); 
   pc = GTK_PLOT(plot)->pc;
 
@@ -1784,7 +1793,9 @@ gtk_plot3d_draw_labels(GtkPlot3D *plot,
   ticks_direction.y = aux.x*plot->e1.y + aux.y*plot->e2.y + aux.z*plot->e3.y; 
   ticks_direction.z = aux.x*plot->e1.z + aux.y*plot->e2.z + aux.z*plot->e3.z; 
 
-  for(ntick = 0; ntick < axis->ticks.nticks; ntick++){
+  for(ntick = 0;
+      axis->ticks.values != NULL &&
+      ntick < axis->ticks.nticks; ntick++){
     if(axis->ticks.values[ntick].minor) continue;
     xx = axis->ticks.values[ntick].value;
     gtk_plot3d_get_pixel(plot, 
diff --git a/gtkextra/gtkplotdata.c b/gtkextra/gtkplotdata.c
index 86a2237..a0ed325 100644
--- a/gtkextra/gtkplotdata.c
+++ b/gtkextra/gtkplotdata.c
@@ -987,6 +987,7 @@ gtk_plot_data_init (GtkPlotData *dataset)
   dataset->gradient->ticks.nminorticks = 0;
   dataset->gradient->ticks.nminor = 0;
   dataset->gradient->ticks.values = NULL;
+  dataset->gradient->ticks.nticks = 0;
   dataset->gradient->ticks.scale = GTK_PLOT_SCALE_LINEAR;
   dataset->gradient->ticks.apply_break = FALSE;
   dataset->gradient->ticks_length = 4;
diff --git a/src/graphing.c b/src/graphing.c
index 46784ce..a727f78 100644
--- a/src/graphing.c
+++ b/src/graphing.c
@@ -1245,7 +1245,7 @@ plot_zoomfit_cb (void)
 			ploty2 = plot_maxy + size * 0.05;
 
 			/* sanity */
-			if (ploty2 < ploty1)
+			if (ploty2 <= ploty1)
 				ploty2 = ploty1 + 0.1;
 
 			/* sanity */
@@ -1264,7 +1264,7 @@ plot_zoomfit_cb (void)
 			plotx2 = plot_maxx + sizex * 0.05;
 
 			/* sanity */
-			if (plotx2 < plotx1)
+			if (plotx2 <= plotx1)
 				plotx2 = plotx1 + 0.1;
 
 			/* sanity */
@@ -1277,7 +1277,7 @@ plot_zoomfit_cb (void)
 			ploty2 = plot_maxy + size * 0.05;
 
 			/* sanity */
-			if (ploty2 < ploty1)
+			if (ploty2 <= ploty1)
 				ploty2 = ploty1 + 0.1;
 
 			/* sanity */
@@ -1291,7 +1291,7 @@ plot_zoomfit_cb (void)
 			surfacez2 = plot_maxy + size * 0.05;
 
 			/* sanity */
-			if (surfacez2 < surfacez1)
+			if (surfacez2 <= surfacez1)
 				surfacez2 = surfacez1 + 0.1;
 
 			/* sanity */
@@ -3328,16 +3328,19 @@ slopefield_draw_solution (double x, double y, double dx)
 	GSList *points2 = NULL;
 	GSList *li;
 	GtkPlotData *data;
+	double fudgey;
 
 	if (slopefield_func == NULL)
 		return;
 
 	gdk_color_parse ("red", &color);
 
+	fudgey = (ploty2-ploty1)/100;
+
 	len1 = 0;
 	cx = x;
 	cy = y;
-	while (cx < plotx2 && cy > ploty1 && cy < ploty2) {
+	while (cx < plotx2 && cy > ploty1-fudgey && cy < ploty2+fudgey) {
 		double *pt;
 		gboolean ex = FALSE;
 		double k1, k2, k3, k4, sl;
@@ -3375,7 +3378,7 @@ slopefield_draw_solution (double x, double y, double dx)
 	len2 = 0;
 	cx = x;
 	cy = y;
-	while (cx > plotx1 && cy > ploty1 && cy < ploty2) {
+	while (cx > plotx1 && cy > ploty1-fudgey && cy < ploty2+fudgey) {
 		double *pt;
 		gboolean ex = FALSE;
 		double k1, k2, k3, k4, sl;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]