diff -Nru graphmonkey-1.6/About_Form.cs graphmonkey-1.7/About_Form.cs --- graphmonkey-1.6/About_Form.cs 2006-03-04 16:49:04.000000000 +0000 +++ graphmonkey-1.7/About_Form.cs 2006-12-05 19:34:24.000000000 +0000 @@ -1,8 +1,8 @@ /* -* 21/08/2004 - 19:29 +* 26/11/2006 - 17:02 * * GraphMonkey - mono based graphing calculator -* Copyright (C) 2004 Bellabes Lounis +* Copyright (C) 2006 Lounis Bellabes * nolius@users.sourceforge.net * * This program is free software; you can redistribute it and/or @@ -27,98 +27,47 @@ public class About_Form : Window { - public About_Form () : base ("Help") + public About_Form () : base ("About") { + this.Move(200,200); this.SetDefaultSize (100, 300); this.Resizable = false; - Table tableLayout = new Table(1, 3, false); + Gdk.Pixbuf icon = new Gdk.Pixbuf(null, "gm.png"); + this.Icon = icon; + + Table tableLayout = new Table(3, 1, false); + //Logo + Gtk.Image im_graphmonkey = new Gtk.Image(new Gdk.Pixbuf(null,"graphmonkey.png")); + //Button button_logo = new Button (im_graphmonkey); + //button_logo.Relief = Gtk.ReliefStyle.None; + //button_logo.Clicked += new EventHandler (button_logo_click); + tableLayout.Attach(im_graphmonkey, 0, 1, 0, 1); //blank - Label label_blank4 = new Label(""); - tableLayout.Attach(label_blank4, 0, 1, 0, 1); - - //GraphMonkey - Label label_monkey = new Label("GraphMonkey 1.6"); - tableLayout.Attach(label_monkey, 0, 1, 1, 2); + //Label label_blank4 = new Label(""); + //tableLayout.Attach(label_blank4, 0, 1, 1, 2); //blank Label label_blank = new Label(""); tableLayout.Attach(label_blank, 0, 1, 2, 3); + //GraphMonkey + Label label_monkey = new Label("GraphMonkey 1.7"); + tableLayout.Attach(label_monkey, 0, 1, 3, 4); + //name Label label_name = new Label(" By Lounis Bellabes "); - tableLayout.Attach(label_name, 0, 1, 3, 4); + tableLayout.Attach(label_name, 0, 1, 4, 5); //email Label label_email = new Label(" nolius@users.sourceforge.net "); - tableLayout.Attach(label_email, 0, 1, 4, 5); + tableLayout.Attach(label_email, 0, 1, 6, 7); //GPL Label label_gpl = new Label("GPL license"); - tableLayout.Attach(label_gpl, 0, 1, 5, 6); - - //blank2 - Label label_blank2 = new Label("-----------------------------"); - tableLayout.Attach(label_blank2, 0, 1, 6, 7); - - //squareroots - Label label_squareroots = new Label("square roots : sqrt()"); - tableLayout.Attach(label_squareroots, 0, 1, 8, 9); - - //powers square - Label label_powerssquare = new Label("powers square : ^"); - tableLayout.Attach(label_powerssquare , 0, 1, 9, 10); - - //sine - Label label_sine = new Label("sine : sin()"); - tableLayout.Attach(label_sine, 0, 1, 10, 11); - - //cosine - Label label_cosine = new Label("cosine : cos()"); - tableLayout.Attach(label_cosine, 0, 1, 11, 12); - - //tangent - Label label_tangent = new Label("tangent : tan()"); - tableLayout.Attach(label_tangent, 0, 1, 12, 13); - - //arcsine - Label label_arcsine = new Label("arcsine : asin()"); - tableLayout.Attach(label_arcsine, 0, 1, 13, 14); - - //arccosine - Label label_arccosine = new Label("arccosine : acos()"); - tableLayout.Attach(label_arccosine, 0, 1, 14, 15); - - //arctangent - Label label_arctangent = new Label("arctangent : atan()"); - tableLayout.Attach(label_arctangent, 0, 1, 15, 16); - - //hyperbolic sine : sinh() - Label label_hyperbolicsine = new Label("hyperbolic sine : sinh()"); - tableLayout.Attach(label_hyperbolicsine, 0, 1, 16, 17); - - //hyperbolic cosine : cosh() - Label label_hyperboliccosine = new Label("hyperbolic cosine : cosh()"); - tableLayout.Attach(label_hyperboliccosine, 0, 1, 17, 18); - - //hyperbolic tangent - Label label_hyperbolictangent = new Label("hyperbolic tangent : tanh()"); - tableLayout.Attach(label_hyperbolictangent, 0, 1, 18, 19); - - //logarithm - Label label_logarithm = new Label("logarithm : log()"); - tableLayout.Attach(label_logarithm, 0, 1, 19, 20); - - //exponential - Label label_exponential = new Label("exponential : exp()"); - tableLayout.Attach(label_exponential, 0, 1, 20, 21); - - //blank3 - Label label_blank3 = new Label(""); - tableLayout.Attach(label_blank3, 0, 1, 21, 22); - + tableLayout.Attach(label_gpl, 0, 1, 7, 8); tableLayout.ShowAll(); this.Add (tableLayout); @@ -127,5 +76,12 @@ } + + /* + void button_logo_click (object o, EventArgs args) + { + + } + */ } diff -Nru /tmp/t3D0teSbmK/graphmonkey-1.6/Calculus.cs /tmp/sm4dSF6ZwX/graphmonkey-1.7/Calculus.cs --- graphmonkey-1.6/Calculus.cs 1970-01-01 01:00:00.000000000 +0100 +++ graphmonkey-1.7/Calculus.cs 2006-12-05 19:34:29.000000000 +0000 @@ -0,0 +1,93 @@ +/* +* 26/11/2006 - 17:02 +* +* GraphMonkey - mono based graphing calculator +* Copyright (C) 2006 Lounis Bellabes +* nolius@users.sourceforge.net +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +using System; + +public class Calculus { + + public string phrase; + public operation op; + + public Calculus(string phrase) + { + this.phrase = phrase; + this.op = new operation(this.phrase); + this.op.corrige(); + } + + // numerical derivative at the point x + public double ndfdx(double x) + { + double h = x + 0.000001d; + double top = op.calculer(h)-op.calculer(x); + double bottom = h-x; + return Math.Round(top/bottom, 4); + } + + // numerical second derivative at the point x + public double n2dfdx(double x) + { + double h = x + 0.0001d; + double h2 = x + 0.0002d; + double top = op.calculer(h2) - op.calculer(h) - op.calculer(h) + op.calculer(x); + double bottom = (h-x)*(h-x); + return Math.Round(top/bottom, 4); + } + + // numerical integral of a function on the interval [a,b] using Simpson's Rule. + public double simpsonsrule(double a, double b) + { + double n = 100.0d; + double total = 0; + double h = Math.Abs(b-a)/n; + double[] l = new double[120]; + double x = a; + l[0] = op.calculer(x); + + int count = 1; + while (count < n) { + x = (double)a + count*h; + + if (count%2 == 0) { + l[count] = 2*op.calculer(x); + } + else { + l[count] = 4*op.calculer(x); + } + count++; + } + + x = (double)b; + l[count] = op.calculer(x); + + for (int i = 0; i <=count; i++) { + total = total + l[i]; + } + return Math.Round((total*h)/3d, 4); + } + + public double averagevalue(double a, double b) + { + return Math.Round((simpsonsrule(a,b))/(b-a), 4); + } + +} diff -Nru /tmp/t3D0teSbmK/graphmonkey-1.6/debian/changelog /tmp/sm4dSF6ZwX/graphmonkey-1.7/debian/changelog --- graphmonkey-1.6/debian/changelog 2008-02-25 21:23:27.000000000 +0000 +++ graphmonkey-1.7/debian/changelog 2008-02-25 21:23:27.000000000 +0000 @@ -1,3 +1,12 @@ +graphmonkey (1.7-1) unstable; urgency=low + + * New upstream release + * debian/control: + - Bump Debian standards version + - Add Homepage field + + -- David Futcher Mon, 25 Feb 2008 20:11:39 +0000 + graphmonkey (1.6-1) unstable; urgency=low * New upstream release diff -Nru /tmp/t3D0teSbmK/graphmonkey-1.6/debian/control /tmp/sm4dSF6ZwX/graphmonkey-1.7/debian/control --- graphmonkey-1.6/debian/control 2008-02-25 21:23:27.000000000 +0000 +++ graphmonkey-1.7/debian/control 2008-02-25 21:23:27.000000000 +0000 @@ -4,7 +4,8 @@ Maintainer: Benjamin Seidenberg Build-Depends: debhelper (>= 4.0.0) Build-Depends-Indep: cli-common-dev, mono-mcs, libglade2.0-cil, libgtk2.0-cil, pkg-config -Standards-Version: 3.7.2 +Standards-Version: 3.7.3 +Homepage: http://graphmonkey.sourceforge.net/ Package: graphmonkey Architecture: all diff -Nru /tmp/t3D0teSbmK/graphmonkey-1.6/description-pak /tmp/sm4dSF6ZwX/graphmonkey-1.7/description-pak --- graphmonkey-1.6/description-pak 1970-01-01 01:00:00.000000000 +0100 +++ graphmonkey-1.7/description-pak 2008-02-25 21:23:27.000000000 +0000 @@ -0,0 +1,2 @@ +graphmonkey +EOF diff -Nru /tmp/t3D0teSbmK/graphmonkey-1.6/Ecran_Form.cs /tmp/sm4dSF6ZwX/graphmonkey-1.7/Ecran_Form.cs --- graphmonkey-1.6/Ecran_Form.cs 2006-03-02 21:33:20.000000000 +0000 +++ graphmonkey-1.7/Ecran_Form.cs 2006-12-05 20:05:49.000000000 +0000 @@ -1,8 +1,8 @@ /* -* 21/08/2004 - 19:29 +* 26/11/2006 - 17:02 * * GraphMonkey - mono based graphing calculator -* Copyright (C) 2004 Bellabes Lounis +* Copyright (C) 2006 Lounis Bellabes * nolius@users.sourceforge.net * * This program is free software; you can redistribute it and/or @@ -26,61 +26,213 @@ class Ecran_Form : DrawingArea { - Pango.Layout layout; + private Gtk.Window win; + + private HBox hbox; + private VBox vbox; + + //Pango.Layout layout; public string equation; public string equation2; public string equation3; - - public float x_min; - public float x_max; - public float y_min; - public float y_max; - public float graduation; + public double x_min; + public double x_max; + public double y_min; + public double y_max; + public double graduation; //for color - public Gdk.GC gc_red; - public Gdk.GC gc_green; - public Gdk.GC gc_blue; - public Gdk.GC gc_a; - public Gdk.GC gc_black; + private Gdk.GC gc_red; + private Gdk.GC gc_green; + private Gdk.GC gc_blue; + private Gdk.GC gc_a; + private Gdk.GC gc_black; + private Gdk.GC gc_white; + private Gdk.GC gc_gray; + private Gdk.GC gc_cyan; + private Gdk.GC gc_orange; - // pour la sauvegarde des resultats + // for saving results public bool first_draw = true; - float[] tab_result1_x = new float[501]; - float[] tab_result1_y = new float[501]; + private double[] tab_result1_x = new double[501]; + private double[] tab_result1_y = new double[501]; + private double[] tab_result2_x = new double[501]; + private double[] tab_result2_y = new double[501]; + private double[] tab_result3_x = new double[501]; + private double[] tab_result3_y = new double[501]; + private double[] tab_result_derivative_x = new double[501]; + private double[] tab_result_derivative_y = new double[501]; + private double[] tab_result_secondderivative_x = new double[501]; + private double[] tab_result_secondderivative_y = new double[501]; - float[] tab_result2_x = new float[501]; - float[] tab_result2_y = new float[501]; + public Label label_coord; - float[] tab_result3_x = new float[501]; - float[] tab_result3_y = new float[501]; + //status of options + private bool black_screen; + private bool grid; - - /* - static void Main () - { - Application.Init (); - new LayoutSample (); - Application.Run (); - } - */ - - public Ecran_Form (string equation1, string equation21, string equation31, float x_min1, float x_max1, float y_min1, float y_max1, float graduation1) + // status of calculus + private bool simpson; + private bool derivative; + private bool secondderivative; + + private bool extension_exist; + private bool extension_show; + private Statusbar statusbar; + + public Ecran_Form (string equation1, string equation21, string equation31, double x_min1, double x_max1, double y_min1, double y_max1, double graduation1) { - Gtk.Window win = new Gtk.Window ("Screen"); - //win.Resizable = false; - + /* + Table tableLayout = new Table(10, 3, false); + tableLayout.Attach(this, 0, 9, 0, 3); + tableLayout.Attach(new Entry(), 9, 10, 0, 3); + tableLayout.ShowAll(); + */ + + this.WidthRequest = 501; + this.HeightRequest = 501; + vbox = new VBox(false,3); + + MenuBar bar = new MenuBar (); + + Menu calculus_menu = new Menu (); + MenuItem calculus_menu_item = new MenuItem ("_Calculus"); + calculus_menu_item.Submenu = calculus_menu; + + ImageMenuItem simpson_item = new ImageMenuItem("_Net Area Under Fn 1 [Xmin, Xmax]"); + simpson_item.Image = new Gtk.Image(Gtk.Stock.GoDown, Gtk.IconSize.Menu); + simpson_item.Activated += new EventHandler(simpson_cb); + calculus_menu.Append(simpson_item); + + ImageMenuItem averagevalue_item = new ImageMenuItem("A_verage Value of Fn 1 [Xmin, Xmax]"); + averagevalue_item.Image = new Gtk.Image(Gtk.Stock.Index, Gtk.IconSize.Menu); + averagevalue_item.Activated += new EventHandler(averagevalue_cb); + calculus_menu.Append(averagevalue_item); + + ImageMenuItem derivative_item = new ImageMenuItem("Graph _Derivative of Fn 1"); + derivative_item.Image = new Gtk.Image(Gtk.Stock.Execute,Gtk.IconSize.Menu); + derivative_item.Activated += new EventHandler(derivative_cb); + calculus_menu.Append(derivative_item); + + ImageMenuItem secondderivative_item = new ImageMenuItem("Graph _Second Derivative of Fn 1"); + secondderivative_item.Image = new Gtk.Image(Gtk.Stock.Execute,Gtk.IconSize.Menu); + secondderivative_item.Activated += new EventHandler(secondderivative_cb); + calculus_menu.Append(secondderivative_item); + + /* + ImageMenuItem slopefield_item = new ImageMenuItem("Slope _Field of Fn 1 [f(x,y)]"); + slopefield_item.Image = new Gtk.Image(Gtk.Stock.Execute,Gtk.IconSize.Menu); + //slopefield_item.Activated += new EventHandler(slopefield_cb); + calculus_menu.Append(slopefield_item); + */ + + ImageMenuItem clear_item = new ImageMenuItem("_Clear"); + clear_item.Image = new Gtk.Image(Gtk.Stock.Clear,Gtk.IconSize.Menu); + clear_item.Activated += new EventHandler(clear_cb); + calculus_menu.Append(clear_item); + + bar.Append (calculus_menu_item); + + Menu option_menu = new Menu (); + MenuItem option_menu_item = new MenuItem ("_Options"); + option_menu_item.Submenu = option_menu; + + + ImageMenuItem wbscreen_item = new ImageMenuItem("White/Black _screen"); + wbscreen_item.Image = new Gtk.Image(Gtk.Stock.Preferences, Gtk.IconSize.Menu); + wbscreen_item.Activated += new EventHandler (wbscreen_cb); + option_menu.Append (wbscreen_item); + + ImageMenuItem grid_item = new ImageMenuItem("On/Off _grid"); + grid_item.Image = new Gtk.Image(Gtk.Stock.Preferences, Gtk.IconSize.Menu); + grid_item.Activated += new EventHandler (grid_cb); + option_menu.Append (grid_item); + + /* + ImageMenuItem info_item = new ImageMenuItem("Curves _informations"); + info_item.Image = new Gtk.Image(Gtk.Stock.DialogInfo, Gtk.IconSize.Menu); + info_item.Activated += new EventHandler (info_cb); + option_menu.Append (info_item); + */ + + bar.Append (option_menu_item); + + bar.ShowAll (); + vbox.PackStart(bar,true,true,0); + + + vbox.PackStart(this,true,true,0); + //vbox.PackStart(new Entry(),true,true,0); + + hbox = new HBox(false,5); + + Image image_GoUp = new Gtk.Image(Gtk.Stock.GoUp , Gtk.IconSize.Button); + Button button_zoom_up = new Button (image_GoUp); + button_zoom_up.Clicked += new EventHandler (button_zoom_up_click); + hbox.PackStart(button_zoom_up,false,false,0); + + Image image_GoDown = new Gtk.Image(Gtk.Stock.GoDown, Gtk.IconSize.Button); + Button button_zoom_down = new Button (image_GoDown); + button_zoom_down.Clicked += new EventHandler (button_zoom_down_click); + hbox.PackStart(button_zoom_down,false,false,0); + + Image image_GoBack = new Gtk.Image(Gtk.Stock.GoBack , Gtk.IconSize.Button); + Button button_zoom_left = new Button (image_GoBack ); + button_zoom_left.Clicked += new EventHandler (button_zoom_left_click); + hbox.PackStart(button_zoom_left,false,false,0); + + Image image_GoForward = new Gtk.Image(Gtk.Stock.GoForward, Gtk.IconSize.Button); + Button button_zoom_right = new Button (image_GoForward); + button_zoom_right.Clicked += new EventHandler (button_zoom_right_click); + hbox.PackStart(button_zoom_right,false,false,0); + + Image image_ZoomIn = new Gtk.Image(Gtk.Stock.ZoomIn, Gtk.IconSize.Button); + Button button_zoom_in = new Button (image_ZoomIn); + button_zoom_in.Clicked += new EventHandler (button_zoom_in_click); + hbox.PackStart(button_zoom_in,false,false,0); + + Image image_ZoomOut = new Gtk.Image(Gtk.Stock.ZoomOut, Gtk.IconSize.Button); + Button button_zoom_out = new Button (image_ZoomOut); + button_zoom_out.Clicked += new EventHandler (button_zoom_out_click); + hbox.PackStart(button_zoom_out,false,false,0); + + Image image_Zoom100 = new Gtk.Image(Gtk.Stock.Zoom100, Gtk.IconSize.Button); + Button button_zoom_100 = new Button (image_Zoom100); + button_zoom_100.Clicked += new EventHandler (button_zoom_100_click); + hbox.PackStart(button_zoom_100,false,false,0); + + Image image_Save = new Gtk.Image(Gtk.Stock.Save, Gtk.IconSize.Button); + Button button_save = new Button (image_Save); + button_save.Clicked += new EventHandler (button_save_click); + hbox.PackStart(button_save,false,false,0); + + label_coord = new Label ("( x ; y)"); + hbox.PackEnd(label_coord,false,false,0); + + + this.MotionNotifyEvent += new MotionNotifyEventHandler(on_mouse_move_graph); + this.LeaveNotifyEvent += new LeaveNotifyEventHandler(on_mouse_leave_graph); + this.Events = Gdk.EventMask.ExposureMask | Gdk.EventMask.LeaveNotifyMask | Gdk.EventMask.ButtonPressMask | Gdk.EventMask.PointerMotionMask | Gdk.EventMask.PointerMotionHintMask; + + vbox.PackStart(hbox,true,true,0); + + win = new Gtk.Window ("Screen"); + + Gdk.Pixbuf icon = new Gdk.Pixbuf(null, "gm.png"); + win.Icon = icon; + //Gdk.GC gc = new Gdk.GC (win); //Gdk.Color red_color = new Gdk.Color (0xff, 0, 0); //gc.Foreground = red_color; win.SetDefaultSize (501, 501); + win.Resizable = false; this.ExposeEvent += OnExposed; - win.Add (this); + win.Add (vbox); win.ShowAll (); this.equation = equation1; @@ -91,25 +243,36 @@ this.y_min = y_min1; this.y_max = y_max1; this.graduation = graduation1; - - - - } - - void OnExposed (object o, ExposeEventArgs args) - { - + + this.black_screen = true; + this.grid = false; + + this.simpson = false; + this.derivative = false; + this.secondderivative = false; + + this.extension_exist = false; + this.extension_show = false; + // color gc_red = new Gdk.GC (this.GdkWindow); gc_green = new Gdk.GC (this.GdkWindow); gc_blue = new Gdk.GC (this.GdkWindow); gc_a = new Gdk.GC (this.GdkWindow); gc_black = new Gdk.GC (this.GdkWindow); + gc_white = new Gdk.GC (this.GdkWindow); + gc_gray = new Gdk.GC (this.GdkWindow); + gc_cyan = new Gdk.GC (this.GdkWindow); + gc_orange = new Gdk.GC (this.GdkWindow); Gdk.Color red_color = new Gdk.Color (0xff, 0, 0); Gdk.Color green_color = new Gdk.Color (0 , 0xff, 0); Gdk.Color blue_color = new Gdk.Color (0 , 0, 0xff); Gdk.Color black_color = new Gdk.Color (0 , 0, 0); Gdk.Color a_color = new Gdk.Color (0xff, 0, 0xff); + Gdk.Color white_color = new Gdk.Color (0xff, 0xff, 0xff); + Gdk.Color gray_color = new Gdk.Color (195, 195, 195); + Gdk.Color cyan_color = new Gdk.Color (0, 0xff, 0xff); + Gdk.Color orange_color = new Gdk.Color (0xff, 140, 0); Gdk.Colormap colormap = Gdk.Colormap.System; Gdk.Color[] tab_color = new Gdk.Color[100]; tab_color[0] = red_color; @@ -117,71 +280,122 @@ tab_color[2] = blue_color; tab_color[3] = a_color; tab_color[4] = black_color; + tab_color[5] = white_color; + tab_color[6] = gray_color; + tab_color[7] = cyan_color; + tab_color[8] = orange_color; bool[] tab_bool = new bool[100]; - colormap.AllocColors(tab_color, 5, true, true, tab_bool); + colormap.AllocColors(tab_color, 9, true, true, tab_bool); gc_red.Foreground = tab_color[0]; gc_green.Foreground = tab_color[1]; gc_blue.Foreground = tab_color[2]; gc_a.Foreground = tab_color[3]; gc_black.Foreground = tab_color[4]; - - Gdk.Rectangle rec_screen = new Gdk.Rectangle(0, 500, 0, 500); - - - //Gtk.StateType a = new Gtk.StateType(); - //this.Style.SetForegroundGC(a, gc_blue); - - - trace_axe(); - + gc_white.Foreground = tab_color[5]; + gc_gray.Foreground = tab_color[6]; + gc_cyan.Foreground = tab_color[7]; + gc_orange.Foreground = tab_color[8]; + } + + void OnExposed (object o, ExposeEventArgs args) + { + trace_all(); + } + + void trace_all() + { if(first_draw){ + clear_graph(); + if(simpson) + trace_simpson(); + + trace_axe(); + + if(derivative) + trace_derivative(); + if(secondderivative) + trace_secondderivative(); trace_equation(); first_draw = false; } else{ - trace_equation2(); + clear_graph(); + if(simpson) + trace_simpson(); + + trace_axe(); + + if(derivative) + trace_derivative(); + if(secondderivative) + trace_secondderivative(); + trace_equation_buffer(); } - } + void clear_graph() + { + if (this.black_screen) + this.GdkWindow.DrawRectangle(gc_black, true, -10, -10, 520, 520); + else + this.GdkWindow.DrawRectangle(gc_white, true, -10, -10, 520, 520); + } + // draw axes void trace_axe() { - // ecran noir - this.GdkWindow.DrawRectangle(gc_black, true, -10, -10, 520, 520); - - this.GdkWindow.DrawLine(gc_blue, (int) trans_x(x_min), (int) trans_y(0f), (int) trans_x(x_max), (int) trans_y(0f)); - this.GdkWindow.DrawLine(gc_blue, (int) trans_x(0f), (int) trans_y(y_min), (int) trans_x(0f), (int) trans_y(y_max)); - + int x0 = (int) Math.Round(trans_x(0f)); + int y0 = (int) Math.Round(trans_y(0f)); + int xmax = (int) Math.Round(trans_x(x_max)); + int xmin = (int) Math.Round(trans_x(x_min)); + int ymax = (int) Math.Round(trans_y(y_max)); + int ymin = (int) Math.Round(trans_y(y_min)); - // graduation sur x - //0 au max - for(float i2=trans_x(0f); i2<=trans_x(x_max); i2=i2+ graduation*500/(x_max - x_min) ){ - this.GdkWindow.DrawLine(gc_blue, (int) i2, (int) trans_y(0f), (int) i2, (int) (trans_y(0f)-5) ); //vertical - } - //0 au min - for(float i2=trans_x(0f); i2>=trans_x(x_min); i2=i2-graduation*500/(x_max - x_min) ){ - this.GdkWindow.DrawLine(gc_blue, (int) i2, (int) trans_y(0f), (int) i2, (int) (trans_y(0f)-5) ); //vertical + // graduation for x + if (x_max>0){ + //0 to max + for(double i2=trans_x(0f); i2<=trans_x(x_max); i2=i2+ graduation*500/(x_max - x_min) ){ + if (this.grid) + this.GdkWindow.DrawLine(gc_gray, (int) Math.Round(i2), ymin, (int) Math.Round(i2), ymax ); + this.GdkWindow.DrawLine(gc_blue, (int) Math.Round(i2), y0, (int) Math.Round(i2), y0-5 ); + } + } + if (x_min<0){ + //0 to min + for(double i2=trans_x(0f); i2>=trans_x(x_min); i2=i2-graduation*500/(x_max - x_min) ){ + if (this.grid) + this.GdkWindow.DrawLine(gc_gray, (int) Math.Round(i2), ymin, (int) Math.Round(i2), ymax ); + this.GdkWindow.DrawLine(gc_blue, (int) Math.Round(i2), y0, (int) Math.Round(i2), y0-5 ); + } } - // graduation sur y - //0 au max - for(float i2=trans_y(0f); i2<=trans_y(y_min); i2=i2+graduation*500/(y_max - y_min) ){ - this.GdkWindow.DrawLine(gc_blue, (int) trans_x(0f), (int) i2, (int) (trans_x(0f)+5), (int) i2); //vertical - } - //0 au max - for(float i2=trans_y(0f); i2>=trans_y(y_max); i2=i2-graduation*500/(y_max - y_min) ){ - this.GdkWindow.DrawLine(gc_blue, (int) trans_x(0f), (int) i2, (int) (trans_x(0f)+5),(int) i2); //vertical - } - - + // graduation for y + if (y_min<0){ + //0 to min + for(double i2=trans_y(0f); i2<=trans_y(y_min); i2=i2+graduation*500/(y_max - y_min) ){ + if (this.grid) + this.GdkWindow.DrawLine(gc_gray, xmin, (int) Math.Round(i2), xmax, (int) Math.Round(i2)); + this.GdkWindow.DrawLine(gc_blue, x0, (int) Math.Round(i2), x0+5, (int) Math.Round(i2)); + } + } + if (y_max>0){ + //0 to max + for(double i2=trans_y(0f); i2>=trans_y(y_max); i2=i2-graduation*500/(y_max - y_min) ){ + if (this.grid) + this.GdkWindow.DrawLine(gc_gray, xmin, (int) Math.Round(i2), xmax,(int) Math.Round(i2)); + this.GdkWindow.DrawLine(gc_blue, x0, (int) Math.Round(i2), x0+5,(int) Math.Round(i2)); + } + } + + //axe + this.GdkWindow.DrawLine(gc_blue, xmin, y0, xmax, y0); + this.GdkWindow.DrawLine(gc_blue, x0, ymin, x0, ymax); } - + + // draw 3 functions void trace_equation() { - - Gdk.GC gc_eq; - + Gdk.GC gc_eq; for(int i_eq=0; i_eq <3; i_eq++){ operation op = new operation(equation); @@ -197,24 +411,20 @@ } op.corrige(); - //op.decouper(); try{ - //operation op = new operation(equation); - //float res=op.calculer(1); - - float xc_1 = x_min; - float yc_1 = op.calculer(x_min); - float xc_2; - float yc_2; + double xc_1 = x_min; + double yc_1 = op.calculer(x_min); + double xc_2; + double yc_2; - float pitch=(x_max-x_min)/500; - float x_1; - float y_1; - float x_2; - float y_2; + double pitch=(x_max-x_min)/500; + double x_1; + double y_1; + double x_2; + double y_2; - // sauvegarde des résultats + // save results int i_save = 0; if(i_eq ==0){ tab_result1_x[i_save] = trans_x(xc_1); @@ -227,121 +437,517 @@ else if(i_eq ==2){ tab_result3_x[i_save] = trans_x(xc_1); tab_result3_y[i_save] = trans_y(yc_1); - } - + } - for(float i_graph=x_min; i_graph<=x_max; i_graph=i_graph+pitch){ + for(double i_graph=x_min; i_graph<=x_max; i_graph=i_graph+pitch){ xc_2 = xc_1+pitch; yc_2 = op.calculer(xc_2); - // transformation dans mon repere x_1 = trans_x(xc_1); y_1 = trans_y(yc_1); x_2 = trans_x(xc_2); y_2 = trans_y(yc_2); - - // sauvegarde des résultats + // save results i_save++; - if(i_eq ==0){ - tab_result1_x[i_save] = x_2; - tab_result1_y[i_save] = y_2; - } - else if(i_eq ==1){ - tab_result2_x[i_save] = x_2; - tab_result2_y[i_save] = y_2; - } - else if(i_eq ==2){ - tab_result3_x[i_save] = x_2; - tab_result3_y[i_save] = y_2; - } - - double yc_1_verif = (double) yc_1; - double yc_2_verif = (double) yc_2; - if(!Double.IsNaN(yc_1_verif) && !Double.IsNaN(yc_2_verif)){ - - if((yc_1>y_min && yc_1y_min && yc_2y_min && yc_1y_min && yc_20 && yc_1_verif<500) || (yc_2_verif>0 && yc_2_verif<500)){ - this.GdkWindow.DrawLine(gc_red, (int) tab_result1_x[i], (int) tab_result1_y[i], (int) tab_result1_x[i+1], (int) tab_result1_y[i+1]); - } + if(!Double.IsNaN(tab_result1_y[i]) && !Double.IsNaN(tab_result1_y[i+1])){ + if((tab_result1_y[i]>0 && tab_result1_y[i]<500) || (tab_result1_y[i+1]>0 && tab_result1_y[i+1]<500)){ + this.GdkWindow.DrawLine(gc_red, (int) Math.Round(tab_result1_x[i]), (int) Math.Round(tab_result1_y[i]), (int) Math.Round(tab_result1_x[i+1]), (int) Math.Round(tab_result1_y[i+1])); } + } } for(int i =0; i<500; i++){ - - double yc_1_verif = (double) tab_result2_y[i]; - double yc_2_verif = (double) tab_result2_y[i+1]; - if(!Double.IsNaN(yc_1_verif) && !Double.IsNaN(yc_2_verif)){ - - if((yc_1_verif>0 && yc_1_verif<500) || (yc_2_verif>0 && yc_2_verif<500)){ - this.GdkWindow.DrawLine(gc_a, (int) tab_result2_x[i], (int) tab_result2_y[i], (int) tab_result2_x[i+1], (int) tab_result2_y[i+1]); - } - + if(!Double.IsNaN(tab_result2_y[i]) && !Double.IsNaN(tab_result2_y[i+1])){ + if((tab_result2_y[i]>0 && tab_result2_y[i]<500) || (tab_result2_y[i+1]>0 && tab_result2_y[i+1]<500)){ + this.GdkWindow.DrawLine(gc_a, (int) Math.Round(tab_result2_x[i]), (int) Math.Round(tab_result2_y[i]), (int) Math.Round(tab_result2_x[i+1]), (int) Math.Round(tab_result2_y[i+1])); } + } } for(int i =0; i<500; i++){ - - double yc_1_verif = (double) tab_result3_y[i]; - double yc_2_verif = (double) tab_result3_y[i+1]; - if(!Double.IsNaN(yc_1_verif) && !Double.IsNaN(yc_2_verif)){ + if(!Double.IsNaN(tab_result3_y[i]) && !Double.IsNaN(tab_result3_y[i+1])){ + if((tab_result3_y[i]>0 && tab_result3_y[i]<500) || (tab_result3_y[i+1]>0 && tab_result3_y[i+1]<500)){ + this.GdkWindow.DrawLine(gc_green, (int) Math.Round(tab_result3_x[i]), (int) Math.Round(tab_result3_y[i]), (int) Math.Round(tab_result3_x[i+1]), (int) Math.Round(tab_result3_y[i+1])); + } + } + } + } + + // drawing net aera + void trace_simpson() + { + try{ + if (first_draw){ + operation op = new operation(equation); + + double xc_1 = x_min; + double yc_1 = op.calculer(x_min); + double xc_2; + double yc_2; + + double pitch=(x_max-x_min)/500; + double x_1; + double y_1; + double x_2; + double y_2; + + for(double i_graph=x_min; i_graph<=x_max; i_graph=i_graph+pitch){ + xc_2 = xc_1+pitch; + yc_2 = op.calculer(xc_2); + + x_1 = trans_x(xc_1); + y_1 = trans_y(yc_1); + x_2 = trans_x(xc_2); + y_2 = trans_y(yc_2); + + if(!Double.IsNaN(yc_1) && !Double.IsNaN(yc_2)){ + this.GdkWindow.DrawLine(gc_red, (int) Math.Round(x_1), (int) Math.Round(trans_y(0f)), (int) Math.Round(x_1), (int) Math.Round(y_1)); + this.GdkWindow.DrawLine(gc_red, (int) Math.Round(x_2), (int) Math.Round(trans_y(0f)), (int) Math.Round(x_2), (int) Math.Round(y_2)); + } + // next point + xc_1=xc_2; + yc_1=yc_2; + } + } + else { // using buffer of Fn 1 + for(int i =0; i<500; i++){ + if(!Double.IsNaN(tab_result1_y[i]) && !Double.IsNaN(tab_result1_y[i+1])){ + this.GdkWindow.DrawLine(gc_red, (int) Math.Round(tab_result1_x[i]), (int) Math.Round(trans_y(0f)), (int) Math.Round(tab_result1_x[i]), (int) Math.Round(tab_result1_y[i])); + this.GdkWindow.DrawLine(gc_red, (int) Math.Round(tab_result1_x[i+1]), (int) Math.Round(trans_y(0f)), (int) Math.Round(tab_result1_x[i+1]), (int) Math.Round(tab_result1_y[i+1])); + } + } + } + } + catch(Exception ex) + { + } + } + + void trace_derivative() + { + try{ + if (first_draw){ + Calculus c = new Calculus(equation); + + double xc_1 = x_min; + double yc_1 = c.ndfdx(this.x_min); + double xc_2; + double yc_2; + + double pitch=(x_max-x_min)/500; + double x_1; + double y_1; + double x_2; + double y_2; + + // save results + int i_save = 0; + + tab_result_derivative_x[i_save] = trans_x(xc_1); + tab_result_derivative_y[i_save] = trans_y(yc_1); + + for(double i_graph=x_min; i_graph<=x_max; i_graph=i_graph+pitch){ + xc_2 = xc_1+pitch; + yc_2 = c.ndfdx(xc_2); + + x_1 = trans_x(xc_1); + y_1 = trans_y(yc_1); + x_2 = trans_x(xc_2); + y_2 = trans_y(yc_2); - if((yc_1_verif>0 && yc_1_verif<500) || (yc_2_verif>0 && yc_2_verif<500)){ - this.GdkWindow.DrawLine(gc_green, (int) tab_result3_x[i], (int) tab_result3_y[i], (int) tab_result3_x[i+1], (int) tab_result3_y[i+1]); + // save results + i_save++; + tab_result_derivative_x[i_save] = x_2; + tab_result_derivative_y[i_save] = y_2; + + if(!Double.IsNaN(yc_1) && !Double.IsNaN(yc_2)){ + if((yc_1>y_min && yc_1y_min && yc_20 && tab_result_derivative_y[i]<500) || (tab_result_derivative_y[i+1]>0 && tab_result_derivative_y[i+1]<500)){ + this.GdkWindow.DrawLine(gc_cyan, (int) Math.Round(tab_result_derivative_x[i]), (int) Math.Round(tab_result_derivative_y[i]), (int) Math.Round(tab_result_derivative_x[i+1]), (int) Math.Round(tab_result_derivative_y[i+1])); + } } + } + } + } + catch(Exception ex) + { + } + } + + void trace_secondderivative() + { + try{ + if (first_draw){ + Calculus c = new Calculus(equation); + + double xc_1 = x_min; + double yc_1 = c.n2dfdx(this.x_min); + double xc_2; + double yc_2; + + double pitch=(x_max-x_min)/500; + double x_1; + double y_1; + double x_2; + double y_2; + + // save results + int i_save = 0; + + tab_result_secondderivative_x[i_save] = trans_x(xc_1); + tab_result_secondderivative_y[i_save] = trans_y(yc_1); + + for(double i_graph=x_min; i_graph<=x_max; i_graph=i_graph+pitch){ + xc_2 = xc_1+pitch; + yc_2 = c.n2dfdx(xc_2); + + x_1 = trans_x(xc_1); + y_1 = trans_y(yc_1); + x_2 = trans_x(xc_2); + y_2 = trans_y(yc_2); + // save results + i_save++; + tab_result_secondderivative_x[i_save] = x_2; + tab_result_secondderivative_y[i_save] = y_2; + + if(!Double.IsNaN(yc_1) && !Double.IsNaN(yc_2)){ + if((yc_1>y_min && yc_1y_min && yc_20 && tab_result_secondderivative_y[i]<500) || (tab_result_secondderivative_y[i+1]>0 && tab_result_secondderivative_y[i+1]<500)){ + this.GdkWindow.DrawLine(gc_orange, (int) Math.Round(tab_result_secondderivative_x[i]), (int) Math.Round(tab_result_secondderivative_y[i]), (int) Math.Round(tab_result_secondderivative_x[i+1]), (int) Math.Round(tab_result_secondderivative_y[i+1])); + } + } + } + } + } + catch(Exception ex) + { } - } - - - // pour la transformation sur x - float trans_x(float x){ + // transformation on x + double trans_x(double x){ + return (500/(x_max - x_min) * (x - x_min) ); + } - return (500/(x_max - x_min) * (x - x_min) ); - + // transformation on y + double trans_y(double y){ + return ( -500/(y_max - y_min) * (y - y_max) ); + } + + void button_zoom_up_click (object o, EventArgs args) + { + first_draw = true; + double diff = (y_max-y_min)/10; + y_min = y_min+diff; + y_max = y_max+diff; + this.simpson = false; + trace_all(); + } + + void button_zoom_down_click (object o, EventArgs args) + { + first_draw = true; + double diff = (y_max-y_min)/10; + y_min = y_min-diff; + y_max = y_max-diff; + this.simpson = false; + trace_all(); + } + + void button_zoom_right_click (object o, EventArgs args) + { + first_draw = true; + double diff = (x_max-x_min)/10; + x_min = x_min+diff; + x_max = x_max+diff; + this.simpson = false; + trace_all(); + } + + void button_zoom_left_click (object o, EventArgs args) + { + first_draw = true; + double diff = (x_max-x_min)/10; + x_min = x_min-diff; + x_max = x_max-diff; + this.simpson = false; + trace_all(); + } + + void button_zoom_in_click (object o, EventArgs args) + { + first_draw = true; + double diff = (y_max-y_min)/10; + y_min = y_min+diff; + y_max = y_max-diff; + x_min = x_min+diff; + x_max = x_max-diff; + this.simpson = false; + trace_all(); + + } + + void button_zoom_out_click (object o, EventArgs args) + { + first_draw = true; + double diff = (y_max-y_min)/10; + y_min = y_min-diff; + y_max = y_max+diff; + x_min = x_min-diff; + x_max = x_max+diff; + this.simpson = false; + trace_all(); + } + + void button_zoom_100_click (object o, EventArgs args) + { + first_draw = true; + y_min = -10; + y_max = 10; + x_min = -10; + x_max = 10; + this.simpson = false; + trace_all(); + } + + // save graph on PNG file + void button_save_click (object o, EventArgs args) + { + + Gdk.Pixbuf dbuf = new Gdk.Pixbuf(Gdk.Colorspace.Rgb,false,8,500,500); + dbuf.GetFromImage(this.GdkWindow.GetImage(0,0,500,500), this.Colormap,0,0,0,0,500,500); + + FileChooserDialog fc = new FileChooserDialog("Save Graph As...", null, FileChooserAction.Save); + + fc.LocalOnly = false; + fc.AddButton (Stock.Cancel, ResponseType.Cancel); + fc.AddButton (Stock.Save, ResponseType.Ok); + + FileFilter fil = new FileFilter(); + fil.Name = "PNG Files"; + fil.AddPattern("*.png"); + fc.AddFilter(fil); + fc.DefaultResponse = ResponseType.Ok; + int resp = fc.Run(); + fc.Hide(); + + if (resp == (int)ResponseType.Ok) + dbuf.Save(fc.Filename,"png"); + + } + + void on_mouse_leave_graph(object o, LeaveNotifyEventArgs args) { + label_coord.Text = "( x ; y )"; } + + // display (X,Y) of the mouse point + void on_mouse_move_graph(object o, MotionNotifyEventArgs args) + { + int x=0; + int y=0; + Gdk.Window window = args.Event.Window; + + if (args.Event.IsHint) { + Gdk.ModifierType s; + window.GetPointer (out x, out y, out s); + } + else { + x = (int) args.Event.X; + y = (int) args.Event.Y; + } - // pour la transformation sur y - float trans_y(float y){ + label_coord.Text= "( "+Math.Round(x_min+x*((x_max-x_min)/500), 2).ToString() + " ; "+Math.Round((y_max+y*((y_max-y_min)/(-500))), 2).ToString()+" )"; + args.RetVal = true; + } + + // change color of screen + void wbscreen_cb (object o, EventArgs args) + { + this.black_screen = !this.black_screen; + trace_all(); + } + + // display or not the grid + void grid_cb (object o, EventArgs args) + { + this.grid = !this.grid; + trace_all(); + } + + /* + void info_cb (object o, EventArgs args) + { + InfoCurve_Form ic = new InfoCurve_Form(); + ic.Show(); + } + */ + + // Net Area + void simpson_cb (object o, EventArgs args) + { + if(!extension_exist){ + statusbar = new Statusbar(); + statusbar.HeightRequest = 25; + vbox.PackStart(statusbar,true,true,0); + //statusbar.Push(0,"test"); + win.ShowAll (); + extension_exist = true; + extension_show = true; - return ( -500/(y_max - y_min) * (y - y_max) ); + } + else if(!extension_show){ + statusbar.Show(); + extension_show = true; + } + first_draw = true; + this.simpson = true; + trace_all(); + + if(extension_exist){ + if (this.equation != ""){ + try { + Calculus c = new Calculus(this.equation); + double s = c.simpsonsrule(x_min, x_max); + statusbar.Push(0,"Net Area Under Fn 1 = " + s.ToString()); + } + catch (Exception ex) { + statusbar.Push(0,"Could not calculate area under curve!"); + + } + } + else + statusbar.Push(0,"Fn 1 does not exist!"); + } } - - - + + // average value + void averagevalue_cb (object o, EventArgs args) + { + if(!extension_exist){ + statusbar = new Statusbar(); + statusbar.HeightRequest = 25; + vbox.PackStart(statusbar,true,true,0); + //statusbar.Push(0,"test"); + win.ShowAll (); + extension_exist = true; + extension_show = true; + } + else if(!extension_show){ + statusbar.Show(); + extension_show = true; + } + + if(extension_exist) + { + if (this.equation != ""){ + try { + Calculus c = new Calculus(this.equation); + double s = c.averagevalue(x_min, x_max); + statusbar.Push(0,"Average Value of Eq 1 = " + s.ToString()); + } + catch (Exception ex) { + statusbar.Push(0,"Could not calculate the average value!"); + } + } + else + statusbar.Push(0,"Fn 1 does not exist!"); + } + } + + // draw derivative + void derivative_cb (object o, EventArgs args) + { + first_draw = true; + this.derivative = true; + trace_all(); + } + // draw second derivative + void secondderivative_cb (object o, EventArgs args) + { + first_draw = true; + this.secondderivative = true; + trace_all(); + } + + // clear all calculus + void clear_cb (object o, EventArgs args) + { + if (extension_show) + { + statusbar.Hide(); + extension_show = false; + } + + first_draw = true; + this.simpson = false; + this.derivative = false; + this.secondderivative = false; + trace_all(); + } + } + diff -Nru /tmp/t3D0teSbmK/graphmonkey-1.6/GraphMonkey.cs /tmp/sm4dSF6ZwX/graphmonkey-1.7/GraphMonkey.cs --- graphmonkey-1.6/GraphMonkey.cs 1970-01-01 01:00:00.000000000 +0100 +++ graphmonkey-1.7/GraphMonkey.cs 2006-12-05 19:34:39.000000000 +0000 @@ -0,0 +1,404 @@ +/* +* 26/11/2006 - 17:02 +* +* GraphMonkey - mono based graphing calculator +* Copyright (C) 2006 Lounis Bellabes +* nolius@users.sourceforge.net +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +using System; +using Gtk; +using Pango; + + +public class GraphMonkey : Window { + public Entry entry_eq1; + public Entry entry_eq2; + public Entry entry_eq3; + + public Entry entry_x_value; + public Entry entry_result; + + public Entry entry_xmin; + public Entry entry_xmax; + public Entry entry_ymin; + public Entry entry_ymax; + public Entry entry_graduation; + + + public double x_min; + public double x_max; + public double y_min; + public double y_max; + public double graduation; + + public Label label_info; + + public GraphMonkey () : base ("GraphMonkey") + { + this.Move(100,100); + this.SetDefaultSize (400, 300); + this.DeleteEvent += new DeleteEventHandler (OnMyWindowDelete); + this.Resizable = false; + //this.ShowAll (); + + Gdk.Pixbuf icon = new Gdk.Pixbuf(null, "gm.png"); + this.Icon = icon; + + VBox vbox = new VBox(false,2); + + // menu + /* + MenuBar menu = new MenuBar(); + Menu file_menu = new Menu(); + + MenuItem file_item = new MenuItem("_File"); + file_item.Submenu = file_menu; + menu.Append (file_item); + + ImageMenuItem exit = new ImageMenuItem("_Quit"); + exit.Image = new Gtk.Image(Gtk.Stock.Quit, Gtk.IconSize.Menu); + exit_item.Activated += new EventHandler(on_exit); + file_menu.Append(exit_item); + */ + + MenuBar bar = new MenuBar (); + + Menu file_menu = new Menu (); + MenuItem file_menu_item = new MenuItem ("_File"); + file_menu_item.Submenu = file_menu; + + ImageMenuItem file_exit = new ImageMenuItem("_Quit"); + file_exit.Image = new Gtk.Image(Gtk.Stock.Quit, Gtk.IconSize.Menu); + file_exit.Activated += new EventHandler (exit_cb); + file_menu.Append (file_exit); + bar.Append (file_menu_item); + + Menu help_menu = new Menu (); + MenuItem help_menu_item = new MenuItem ("_Help"); + help_menu_item.Submenu = help_menu; + + ImageMenuItem help_help = new ImageMenuItem("_Help"); + help_help.Image = new Gtk.Image(Gtk.Stock.Help, Gtk.IconSize.Menu); + help_help.Activated += new EventHandler (help_cb); + help_menu.Append (help_help); + + ImageMenuItem help_about = new ImageMenuItem("_About"); + help_about.Image = new Gtk.Image(Gtk.Stock.DialogInfo, Gtk.IconSize.Menu); + help_about.Activated += new EventHandler (about_cb); + help_menu.Append (help_about); + + bar.Append (help_menu_item); + bar.ShowAll (); + + vbox.PackStart(bar, true, true, 0); + + + // create a table 6 on 10 + Table tableLayout = new Table(6, 10, false); + /* + Label label_titre = new Label("equations :"); + //label_titre.Justify = Gtk.Justification.Left; + tableLayout.Attach(label_titre, 0, 6, 0, 1); + */ + + //equation 1 + Label label_y1 = new Label("Function 1 : y ="); + tableLayout.Attach(label_y1, 0, 1, 0, 1); + + entry_eq1 = new Entry (""); + tableLayout.Attach(entry_eq1, 1, 2, 0, 1); + entry_eq1.Activated += new EventHandler(button_trace_click); + + //equation 2 + Label label_y2 = new Label("Function 2 : y ="); + tableLayout.Attach(label_y2, 0, 1, 1, 2); + + entry_eq2 = new Entry (""); + tableLayout.Attach(entry_eq2, 1, 2, 1, 2); + entry_eq2.Activated += new EventHandler(button_trace_click); + + //equation 3 + Label label_y3 = new Label("Function 3 : y ="); + tableLayout.Attach(label_y3, 0, 1, 2, 3); + + entry_eq3 = new Entry (""); + tableLayout.Attach(entry_eq3, 1, 2, 2, 3); + entry_eq3.Activated += new EventHandler(button_trace_click); + + Button button_trace = new Button (" Trace ! "); + button_trace.Clicked += new EventHandler (button_trace_click); + tableLayout.Attach(button_trace, 3, 4, 0, 3); + + //------------------------------------------------ + + // f(x) + Label label_x_value = new Label(" x value for Fn 1 : "); + tableLayout.Attach(label_x_value, 0, 1, 3, 4); + + entry_x_value = new Entry (""); + tableLayout.Attach(entry_x_value, 1, 2, 3, 4); + entry_x_value.Activated += new EventHandler(button_result_click); + + //Label label_egal = new Label("="); + //tableLayout.Attach(label_egal, 3, 4, 1, 2); + + Button button_result = new Button (" f(x) = "); + button_result.Clicked += new EventHandler (button_result_click); + tableLayout.Attach(button_result, 2, 3, 3, 4); + + entry_result = new Entry (""); + entry_result.IsEditable = false; + tableLayout.Attach(entry_result, 3, 4, 3, 4); + + //------------------------------------------------ + + // range + Label label_range = new Label(""); + tableLayout.Attach(label_range, 0, 1, 4, 5); + + //xmin + Label label_xmin = new Label("Xmin ="); + tableLayout.Attach(label_xmin, 0, 1, 5, 6); + + entry_xmin = new Entry ("-10"); + tableLayout.Attach(entry_xmin, 1, 2, 5, 6); + entry_xmin.Activated += new EventHandler(button_trace_click); + + //xmax + Label label_xmax = new Label("Xmax ="); + tableLayout.Attach(label_xmax, 0, 1, 6, 7); + + entry_xmax = new Entry ("10"); + tableLayout.Attach(entry_xmax, 1, 2, 6, 7); + entry_xmax.Activated += new EventHandler(button_trace_click); + + //ymin + Label label_ymin = new Label("Ymin ="); + tableLayout.Attach(label_ymin, 0, 1, 7, 8); + + entry_ymin = new Entry ("-10"); + tableLayout.Attach(entry_ymin, 1, 2, 7, 8); + entry_ymin.Activated += new EventHandler(button_trace_click); + + //ymax + Label label_ymax = new Label("Ymax ="); + tableLayout.Attach(label_ymax, 0, 1, 8, 9); + + entry_ymax = new Entry ("10"); + tableLayout.Attach(entry_ymax, 1, 2, 8, 9); + entry_ymax.Activated += new EventHandler(button_trace_click); + + //graduation + Label label_graduation = new Label("Scale ="); + tableLayout.Attach(label_graduation, 0, 1, 9, 10); + + entry_graduation = new Entry ("1"); + tableLayout.Attach(entry_graduation, 1, 2, 9, 10); + entry_graduation.Activated += new EventHandler(button_trace_click); + + //initialize range + Button button_initialize_range = new Button ("Initialize Range"); + button_initialize_range.Clicked += new EventHandler (button_initialize_range_click); + tableLayout.Attach(button_initialize_range, 3, 4, 8, 9); + + //initialize + Button button_initialize_all = new Button ("Initialize All"); + button_initialize_all.Clicked += new EventHandler (button_initialize_all_click); + tableLayout.Attach(button_initialize_all, 3, 4, 7, 8); + + //help + Button button_about = new Button ("Help"); + button_about.Clicked += new EventHandler (button_about_click); + tableLayout.Attach(button_about, 3, 4, 9, 10); + + // info + label_info = new Label("Ready!"); + tableLayout.Attach(label_info, 3, 4, 5, 6); + + vbox.PackStart(tableLayout,true,true,0); + + tableLayout.ShowAll(); + //this.Add (tableLayout); + this.Add(vbox); + + this.ShowAll (); + + // range initialization + x_min = -10f; + x_max = 10f; + y_min = -10f; + y_max = 10f; + graduation = 1f; + + //Ecran_Form ecran = new Ecran_Form(" ", x_min, x_max, y_min, y_max, graduation); + + //ecran.equation = "test"; + //f.Show(); + /* + Pango.Layout layout; + layout = new Pango.Layout (this.PangoContext); + layout.Wrap = Pango.WrapMode.Word; + layout.FontDescription = FontDescription.FromString ("Tahoma 16"); + layout.SetMarkup ("test"); + this.GdkWindow.DrawLayout (this.Style.TextGC (StateType.Normal), 100, 150, layout); + this.GdkWindow.DrawLine (this.Style.TextGC (StateType.Normal), 0, 0, 100, 100); + //f.GdkWindow.DrawLayout (this.Style.TextGC (StateType.Normal), 100, 150, layout); + */ + //f.GdkWindow.DrawLine (this.Style.TextGC (StateType.Normal), 0, 0, 500, 500); + + } + + void button_result_click (object o, EventArgs args) + { + try{ + string equation = this.entry_eq1.Text; + string string_x = entry_x_value.Text; + //string_x = string_x.Replace(".", "."); + + double x; + + if (equation != ""){ + if (string_x != ""){ + decimal decimal_x = Convert.ToDecimal(string_x); + x = (double) decimal_x; + } + else{ + x = 0f; + } + + operation op =new operation(equation); + + op.corrige(); + //op.decouper(); + double res =op.calculer(x); + this.entry_result.Text=Convert.ToString(res); + + double res_verif = res; + if(Double.IsNaN(res_verif)){ + this.entry_result.Text = "NaN"; + label_info.Text = "Error!"; + } + else{ + label_info.Text = "Ready!"; + } + } + } + catch(Exception ex) + { + label_info.Text = "Error!"; + this.entry_result.Text = ""; + } + } + + void button_trace_click (object o, EventArgs args) + { + try{ + if( ( this.entry_eq1.Text != "" || this.entry_eq2.Text != "" || this.entry_eq3.Text != "") && entry_xmin.Text != "" && entry_xmax.Text != "" && entry_ymin.Text != "" && entry_ymax.Text != "" && entry_graduation.Text != "" ){ + + decimal decimal_xmin = Convert.ToDecimal(entry_xmin.Text); + x_min = (double) decimal_xmin; + decimal decimal_xmax = Convert.ToDecimal(entry_xmax.Text); + x_max = (double) decimal_xmax; + decimal decimal_ymin = Convert.ToDecimal(entry_ymin.Text); + y_min = (double) decimal_ymin; + decimal decimal_ymax = Convert.ToDecimal(entry_ymax.Text); + y_max = (double) decimal_ymax; + decimal decimal_graduation = Convert.ToDecimal(entry_graduation.Text); + graduation = (double) decimal_graduation; + + if( x_min < x_max && y_min < y_max && graduation >0){ + + Ecran_Form ecran = new Ecran_Form(entry_eq1.Text, entry_eq2.Text, entry_eq3.Text, x_min, x_max, y_min, y_max, graduation); + label_info.Text = "Ready!"; + } + else{ + label_info.Text = "Range error!"; + } + + } + else{ + if(this.entry_eq1.Text == "" && this.entry_eq2.Text == "" && this.entry_eq3.Text == ""){ + label_info.Text = "No equation!"; + } + else{ + label_info.Text = "Range error!"; + } + } + } + catch(Exception ex) + { + label_info.Text = "Range error!"; + } + + } + + void button_initialize_range_click (object o, EventArgs args) + { + entry_xmin.Text = "-10"; + entry_xmax.Text = "10"; + entry_ymin.Text = "-10"; + entry_ymax.Text = "10"; + entry_graduation.Text = "1"; + } + + void button_initialize_all_click (object o, EventArgs args) + { + entry_eq1.Text = ""; + entry_eq2.Text = ""; + entry_eq3.Text = ""; + + entry_x_value.Text = ""; + entry_result.Text = ""; + + entry_xmin.Text = "-10"; + entry_xmax.Text = "10"; + entry_ymin.Text = "-10"; + entry_ymax.Text = "10"; + entry_graduation.Text = "1"; + } + + void button_about_click (object o, EventArgs args) + { + Help_Form help = new Help_Form(); + help.Show(); + } + + void OnMyWindowDelete (object o, DeleteEventArgs args) + { + Application.Quit (); + } + + void exit_cb (object o, EventArgs args) + { + Application.Quit (); + } + + void help_cb (object o, EventArgs args) + { + Help_Form help = new Help_Form(); + help.Show(); + } + + void about_cb (object o, EventArgs args) + { + About_Form about = new About_Form(); + about.Show(); + } + + +} diff -Nru /tmp/t3D0teSbmK/graphmonkey-1.6/HELP /tmp/sm4dSF6ZwX/graphmonkey-1.7/HELP --- graphmonkey-1.6/HELP 2006-10-10 19:08:44.000000000 +0100 +++ graphmonkey-1.7/HELP 2006-12-05 19:33:26.000000000 +0000 @@ -1,5 +1,5 @@ GraphMonkey - mono based graphing calculator -Copyright (C) 2004 Bellabes Lounis +Copyright (C) 2006 Lounis Bellabes nolius@users.sourceforge.net GPL license. @@ -8,8 +8,8 @@ you can use: + , -, *, / -square roots : sqrt() -powers square : ^ +square root : sqrt() +powers : ^ brackets sine : sin() cosine : cos() @@ -20,14 +20,16 @@ hyperbolic sine : sinh() hyperbolic cosine : cosh() hyperbolic tangent : tan() -logarithm : log() +natural logarithm: ln() +base 10 logarithm: log() exponential : exp() +absolute value: abs() +greatest integer: int() -it's also possible to modify the range. +It is also possible to modify the range and to do some calculations. -you can try: +for exemple, you can try: sin(x)*x (sqrt(x)+5)*3 2.3233^5*(x/cos(x)) - -NOTE: replace "." by "," if you you use "," for decimal values (in France for exemple) +NOTE: replace "." by "," if you use "," for decimal values in your country diff -Nru /tmp/t3D0teSbmK/graphmonkey-1.6/Help_Form.cs /tmp/sm4dSF6ZwX/graphmonkey-1.7/Help_Form.cs --- graphmonkey-1.6/Help_Form.cs 1970-01-01 01:00:00.000000000 +0100 +++ graphmonkey-1.7/Help_Form.cs 2006-12-05 19:34:50.000000000 +0000 @@ -0,0 +1,145 @@ +/* +* 26/11/2006 - 17:02 +* +* GraphMonkey - mono based graphing calculator +* Copyright (C) 2006 Lounis Bellabes +* nolius@users.sourceforge.net +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +using System; +using Gtk; +using GtkSharp; + + +public class Help_Form : Window +{ + public Help_Form () : base ("Help") + { + this.Move(300,100); + this.SetDefaultSize (100, 300); + this.Resizable = false; + + Gdk.Pixbuf icon = new Gdk.Pixbuf(null, "gm.png"); + this.Icon = icon; + + Table tableLayout = new Table(1, 3, false); + + //blank + Label label_blank4 = new Label(""); + tableLayout.Attach(label_blank4, 0, 1, 0, 1); + + //GraphMonkey + Label label_monkey = new Label("GraphMonkey 1.7"); + tableLayout.Attach(label_monkey, 0, 1, 1, 2); + + //blank + Label label_blank = new Label(""); + tableLayout.Attach(label_blank, 0, 1, 2, 3); + + //name + Label label_name = new Label(" By Lounis Bellabes "); + tableLayout.Attach(label_name, 0, 1, 3, 4); + + //email + Label label_email = new Label(" nolius@users.sourceforge.net "); + tableLayout.Attach(label_email, 0, 1, 4, 5); + + //GPL + Label label_gpl = new Label("GPL license"); + tableLayout.Attach(label_gpl, 0, 1, 5, 6); + + //blank2 + Label label_blank2 = new Label("-----------------------------"); + tableLayout.Attach(label_blank2, 0, 1, 6, 7); + + //squareroots + Label label_squareroots = new Label("square root : sqrt()"); + tableLayout.Attach(label_squareroots, 0, 1, 8, 9); + + //powers square + Label label_powerssquare = new Label("powers : ^"); + tableLayout.Attach(label_powerssquare , 0, 1, 9, 10); + + //sine + Label label_sine = new Label("sine : sin()"); + tableLayout.Attach(label_sine, 0, 1, 10, 11); + + //cosine + Label label_cosine = new Label("cosine : cos()"); + tableLayout.Attach(label_cosine, 0, 1, 11, 12); + + //tangent + Label label_tangent = new Label("tangent : tan()"); + tableLayout.Attach(label_tangent, 0, 1, 12, 13); + + //arcsine + Label label_arcsine = new Label("arcsine : asin()"); + tableLayout.Attach(label_arcsine, 0, 1, 13, 14); + + //arccosine + Label label_arccosine = new Label("arccosine : acos()"); + tableLayout.Attach(label_arccosine, 0, 1, 14, 15); + + //arctangent + Label label_arctangent = new Label("arctangent : atan()"); + tableLayout.Attach(label_arctangent, 0, 1, 15, 16); + + //hyperbolic sine + Label label_hyperbolicsine = new Label("hyperbolic sine : sinh()"); + tableLayout.Attach(label_hyperbolicsine, 0, 1, 16, 17); + + //hyperbolic cosine + Label label_hyperboliccosine = new Label("hyperbolic cosine : cosh()"); + tableLayout.Attach(label_hyperboliccosine, 0, 1, 17, 18); + + //hyperbolic tangent + Label label_hyperbolictangent = new Label("hyperbolic tangent : tanh()"); + tableLayout.Attach(label_hyperbolictangent, 0, 1, 18, 19); + + //natural logarithm + Label label_logarithm = new Label("natural logarithm: ln()"); + tableLayout.Attach(label_logarithm, 0, 1, 19, 20); + + //base 10 logarithm + Label label_logarithm10 = new Label("base 10 logarithm: log()"); + tableLayout.Attach(label_logarithm10, 0, 1, 20, 21); + + //exponential + Label label_exponential = new Label("exponential : exp()"); + tableLayout.Attach(label_exponential, 0, 1, 21, 22); + + //absolute value + Label label_absolutevalue = new Label("absolute value: abs()"); + tableLayout.Attach(label_absolutevalue, 0, 1, 22, 23); + + //greatest integer + Label label_greatestinteger = new Label("greatest integer: int()"); + tableLayout.Attach(label_greatestinteger, 0, 1, 23, 24); + + //blank3 + Label label_blank3 = new Label(""); + tableLayout.Attach(label_blank3, 0, 1, 24, 25); + + tableLayout.ShowAll(); + this.Add (tableLayout); + + this.ShowAll (); + + + } +} + diff -Nru /tmp/t3D0teSbmK/graphmonkey-1.6/Main.cs /tmp/sm4dSF6ZwX/graphmonkey-1.7/Main.cs --- graphmonkey-1.6/Main.cs 2005-10-29 17:43:53.000000000 +0100 +++ graphmonkey-1.7/Main.cs 2006-12-05 19:34:47.000000000 +0000 @@ -1,8 +1,8 @@ /* -* 21/08/2004 - 19:29 +* 26/11/2006 - 17:02 * * GraphMonkey - mono based graphing calculator -* Copyright (C) 2004 Bellabes Lounis +* Copyright (C) 2006 Lounis Bellabes * nolius@users.sourceforge.net * * This program is free software; you can redistribute it and/or @@ -27,7 +27,7 @@ public static void Main(string[] args) { Application.Init (); - new MyWindow (); + new GraphMonkey (); Application.Run (); } } diff -Nru /tmp/t3D0teSbmK/graphmonkey-1.6/Makefile /tmp/sm4dSF6ZwX/graphmonkey-1.7/Makefile --- graphmonkey-1.6/Makefile 2008-02-25 21:23:27.000000000 +0000 +++ graphmonkey-1.7/Makefile 2008-02-25 21:23:27.000000000 +0000 @@ -1,8 +1,10 @@ CC=mcs EXEC=GraphMonkey.exe +SHARE=/usr/local/share +BIN=/usr/local/bin all: - $(CC) -target:exe -out:"$(EXEC)" -pkg:gtk-sharp-2.0 ./Main.cs ./MyWindow.cs ./Ecran_Form.cs ./operation.cs ./About_Form.cs + $(CC) -target:exe -out:"$(EXEC)" -resource:./pixmaps/graphmonkey.png -resource:./pixmaps/gm.png -pkg:gtk-sharp-2.0 ./Main.cs ./GraphMonkey.cs ./Ecran_Form.cs ./operation.cs ./Help_Form.cs ./About_Form.cs ./Calculus.cs clean: rm -rf $(EXEC) diff -Nru /tmp/t3D0teSbmK/graphmonkey-1.6/operation.cs /tmp/sm4dSF6ZwX/graphmonkey-1.7/operation.cs --- graphmonkey-1.6/operation.cs 2006-10-08 20:56:25.000000000 +0100 +++ graphmonkey-1.7/operation.cs 2006-12-05 19:35:13.000000000 +0000 @@ -1,8 +1,8 @@ /* -* 21/08/2004 - 19:29 +* 26/11/2006 - 17:02 * * GraphMonkey - mono based graphing calculator -* Copyright (C) 2004 Bellabes Lounis +* Copyright (C) 2006 Lounis Bellabes * nolius@users.sourceforge.net * * This program is free software; you can redistribute it and/or @@ -23,22 +23,18 @@ using System; - - -public class operation : object { +public class operation : object{ public string phrase; public string operateur; public operation droite; public operation gauche; - public operation(string phrase) { - this.phrase=phrase; - + this.phrase=phrase; } public void decouper(){ - //on recherche un + (le plus a droite possible) qui n'est pas dans une parenthese + //search a + (the more at rigth) not in Bracket int position_plus=this.phrase.LastIndexOf("+"); bool trouver_bon_plus = false; while (position_plus != -1 && trouver_bon_plus==false ){ @@ -53,7 +49,7 @@ position_plus = -1; } - //on recherche un - (le plus a droite possible) qui n'est pas dans une parenthese + //search a - (the more at rigth) not in Bracket int position_moin=this.phrase.LastIndexOf("-"); bool trouver_bon_moin = false; while (position_moin != -1 && trouver_bon_moin==false ){ @@ -68,9 +64,9 @@ position_moin = -1; } - // priorité au + et - + // priority for + and - - // il y a d'abord un + + // initially a + if ( (position_plus!=-1 && position_moin==-1) || (position_plus!=-1 && position_moin!=-1 && position_plus>position_moin) ){ this.operateur = "+"; @@ -82,7 +78,7 @@ phrase_droite = phrase_droite.Remove(0,position_plus+1); this.droite = new operation(phrase_droite); } - // il y a d'abord un - + // initially a - else if ( (position_plus==-1 && position_moin!=-1) || (position_plus!=-1 && position_moin!=-1 && position_moin>position_plus) ){ this.operateur = "-"; @@ -95,13 +91,10 @@ this.droite = new operation(phrase_droite); } - - - - // maintenant * et / + // now * et / else { - //on recherche un * (le plus a doite possible) qui n'est pas dans une parenthese + //search a * (the more at rigth) not in Bracket int position_multiplier=this.phrase.LastIndexOf("*"); bool trouver_bon_multiplier = false; while (position_multiplier != -1 && trouver_bon_multiplier==false ){ @@ -116,7 +109,7 @@ position_multiplier= -1; } - //on recherche un / (le plus a doite possible) qui n'est pas dans une parenthese + //search a / (the more at rigth) not in Bracket int position_diviser=this.phrase.LastIndexOf("/"); bool trouver_bon_diviser = false; while (position_diviser != -1 && trouver_bon_diviser==false ){ @@ -132,10 +125,8 @@ } - - - // il ya a d'abord un * - if ( (position_multiplier!=-1 && position_diviser==-1) || (position_multiplier!=-1 && position_diviser!=-1 && position_multiplier>position_diviser) ){ // il ya a d'abord un * + // initially a * + if ( (position_multiplier!=-1 && position_diviser==-1) || (position_multiplier!=-1 && position_diviser!=-1 && position_multiplier>position_diviser) ){ // initially a * this.operateur = "*"; string phrase_gauche=this.phrase; @@ -146,8 +137,8 @@ phrase_droite = phrase_droite.Remove(0,position_multiplier+1); this.droite = new operation(phrase_droite); } - // il y a d'abord un / - else if ( (position_multiplier==-1 && position_diviser!=-1) || (position_multiplier!=-1 && position_diviser!=-1 && position_diviser>position_multiplier) ){ // il ya a d'abord un / + // initially a / + else if ( (position_multiplier==-1 && position_diviser!=-1) || (position_multiplier!=-1 && position_diviser!=-1 && position_diviser>position_multiplier) ){ // initially a / this.operateur = "/"; string phrase_gauche=this.phrase; @@ -160,10 +151,9 @@ } - // maintenant ^ (puissance) - + // now ^ else{ - //on recherche un ^ (le plus a gauche possible) qui n'est pas dans une parenthese + //search a ^ (the more at rigth) not in Bracket int position_puissance=this.phrase.IndexOf("^"); bool trouver_bon_puissance = false; while (position_puissance != -1 && trouver_bon_puissance==false ){ @@ -178,7 +168,7 @@ position_puissance= -1; } - if ( (position_puissance!=-1) ){ // il y a un ^ + if ( (position_puissance!=-1) ){ // there is a ^ this.operateur = "^"; string phrase_gauche=this.phrase; @@ -189,86 +179,86 @@ phrase_droite = phrase_droite.Remove(0,position_puissance+1); this.droite = new operation(phrase_droite); } - else{ // si il n'y a pas de + - / * ou ^ c'est que la phrase ressemble a "(2+x-3)" ou "2" ou "x" ou r(2*x)... - - //si phrase par une parenthese ex: (2+x-3) on supprime les parentheses pour pouvoir continuer le calcule + else{ // there is no + - / * or ^ so phrase is like "(2+x-3)" or "2" or "x" or r(2*x)... + + //if phrase is in bracket (2+x-3), delete bracket if (this.phrase.StartsWith("(")){ this.operateur="()"; string phrase_gauche=this.phrase; - phrase_gauche = phrase_gauche.Remove(0,1); //on supprime le "(" du debut - phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //on supprime le ")" de la fin + phrase_gauche = phrase_gauche.Remove(0,1); //delete "(" in beginning + phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //delete ")" in end this.gauche = new operation(phrase_gauche); } - else if (this.phrase.StartsWith("sqrt(")){ // racine + else if (this.phrase.StartsWith("sqrt(")){ // root square this.operateur = "sqrt()"; string phrase_gauche = this.phrase; - phrase_gauche = phrase_gauche.Remove(0,5); //on supprime le "r(" du debut - phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //on supprime le ")" de la fin + phrase_gauche = phrase_gauche.Remove(0,5); //delete "sqrt(" in beginning + phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //delete ")" in end this.gauche = new operation(phrase_gauche); } else if (this.phrase.StartsWith("cos(")){ // cos this.operateur = "cos()"; string phrase_gauche = this.phrase; - phrase_gauche = phrase_gauche.Remove(0,4); //on supprime le "cos(" du debut - phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //on supprime le ")" de la fin + phrase_gauche = phrase_gauche.Remove(0,4); //delete "cos(" in beginning + phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //delete ")" in end this.gauche = new operation(phrase_gauche); } else if (this.phrase.StartsWith("sin(")){ // sin this.operateur = "sin()"; string phrase_gauche = this.phrase; - phrase_gauche = phrase_gauche.Remove(0,4); //on supprime le "sin(" du debut - phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //on supprime le ")" de la fin + phrase_gauche = phrase_gauche.Remove(0,4); //delete "sin(" in beginning + phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //delete ")" in end this.gauche = new operation(phrase_gauche); } - else if (this.phrase.StartsWith("tan(")){ // sin + else if (this.phrase.StartsWith("tan(")){ // tan this.operateur = "tan()"; string phrase_gauche = this.phrase; - phrase_gauche = phrase_gauche.Remove(0,4); //on supprime le "tan(" du debut - phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //on supprime le ")" de la fin + phrase_gauche = phrase_gauche.Remove(0,4); //delete "tan(" in beginning + phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //delete ")" in end this.gauche = new operation(phrase_gauche); } - else if (this.phrase.StartsWith("n(")){ // n - this.operateur = "n()"; + else if (this.phrase.StartsWith("ln(")){ // ln + this.operateur = "ln()"; string phrase_gauche = this.phrase; - phrase_gauche = phrase_gauche.Remove(0,2); //on supprime le "n(" du debut - phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //on supprime le ")" de la fin + phrase_gauche = phrase_gauche.Remove(0,3); //delete "ln(" in beginning + phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //delete ")" in end this.gauche = new operation(phrase_gauche); } else if (this.phrase.StartsWith("log(")){ // log this.operateur = "log()"; string phrase_gauche = this.phrase; - phrase_gauche = phrase_gauche.Remove(0,4); //on supprime le "log(" du debut - phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //on supprime le ")" de la fin + phrase_gauche = phrase_gauche.Remove(0,4); //delete "log(" in beginning + phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //delete ")" in end this.gauche = new operation(phrase_gauche); } else if (this.phrase.StartsWith("acos(")){ // acos this.operateur = "acos()"; string phrase_gauche = this.phrase; - phrase_gauche = phrase_gauche.Remove(0,5); //on supprime le "acos(" du debut - phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //on supprime le ")" de la fin + phrase_gauche = phrase_gauche.Remove(0,5); //delete "acos(" in beginningt + phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //delete ")" in end this.gauche = new operation(phrase_gauche); } else if (this.phrase.StartsWith("asin(")){ // asin this.operateur = "asin()"; string phrase_gauche = this.phrase; - phrase_gauche = phrase_gauche.Remove(0,5); //on supprime le "asin(" du debut - phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //on supprime le ")" de la fin + phrase_gauche = phrase_gauche.Remove(0,5); //delete "asin(" in beginning + phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //delete ")" in end this.gauche = new operation(phrase_gauche); } else if (this.phrase.StartsWith("atan(")){ // atan this.operateur = "atan()"; string phrase_gauche = this.phrase; - phrase_gauche = phrase_gauche.Remove(0,5); //on supprime le "atan(" du debut + phrase_gauche = phrase_gauche.Remove(0,5); //delete "atan(" in beginning phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //on supprime le ")" de la fin this.gauche = new operation(phrase_gauche); } @@ -276,40 +266,53 @@ this.operateur = "cosh()"; string phrase_gauche = this.phrase; - phrase_gauche = phrase_gauche.Remove(0,5); //on supprime le "cosh(" du debut - phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //on supprime le ")" de la fin + phrase_gauche = phrase_gauche.Remove(0,5); //delete "cosh(" in beginning + phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //delete ")" in end this.gauche = new operation(phrase_gauche); } else if (this.phrase.StartsWith("sinh(")){ // sinh this.operateur = "sinh()"; string phrase_gauche = this.phrase; - phrase_gauche = phrase_gauche.Remove(0,5); //on supprime le "sinh(" du debut - phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //on supprime le ")" de la fin + phrase_gauche = phrase_gauche.Remove(0,5); //delete "sinh(" in beginning + phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //delete ")" in end this.gauche = new operation(phrase_gauche); } else if (this.phrase.StartsWith("tanh(")){ // tanh this.operateur = "tanh()"; string phrase_gauche = this.phrase; - phrase_gauche = phrase_gauche.Remove(0,5); //on supprime le "tanh(" du debut - phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //on supprime le ")" de la fin + phrase_gauche = phrase_gauche.Remove(0,5); //delete "tanh(" in beginning + phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //delete ")" in end this.gauche = new operation(phrase_gauche); } - else if (this.phrase.StartsWith("exp(")){ // tanh + else if (this.phrase.StartsWith("exp(")){ // exp this.operateur = "exp()"; string phrase_gauche = this.phrase; - phrase_gauche = phrase_gauche.Remove(0,4); //on supprime le "exp(" du debut - phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //on supprime le ")" de la fin + phrase_gauche = phrase_gauche.Remove(0,4); //delete "exp(" in beginning + phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //delete ")" in end + this.gauche = new operation(phrase_gauche); + } + else if (this.phrase.StartsWith("abs(")){ // abs + this.operateur = "abs()"; + + string phrase_gauche = this.phrase; + phrase_gauche = phrase_gauche.Remove(0,4); //delete "abs(" in beginning + phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //delete ")" in end + this.gauche = new operation(phrase_gauche); + } + else if (this.phrase.StartsWith("int(")){ // int + this.operateur = "int()"; + + string phrase_gauche = this.phrase; + phrase_gauche = phrase_gauche.Remove(0,4); //delete "int(" in beginning + phrase_gauche = phrase_gauche.Remove(phrase_gauche.Length-1,1); //delete ")" in end this.gauche = new operation(phrase_gauche); } - - } } } - } @@ -319,7 +322,6 @@ } this.phrase = this.phrase.Replace("X", "x"); - this.phrase = this.phrase.Replace(".", "."); this.phrase = this.phrase.Replace("(-", "(0-"); @@ -349,16 +351,11 @@ this.phrase = this.phrase.Replace("9x", "9*x"); this.phrase = this.phrase.Replace(")(", ")*("); - - } - - - - public float calculer(float x){ - float resultat=0; + public double calculer(double x){ + double resultat=0; //this.corrige(); this.decouper(); @@ -382,197 +379,130 @@ return resultat; } else if(this.operateur=="^"){ - // il faut faire une conversion - double resultat_double; - double gauche_double = Convert.ToDouble(this.gauche.calculer(x)); - double droite_double = Convert.ToDouble(this.droite.calculer(x)); - resultat_double= Math.Pow(gauche_double,droite_double); - resultat = (float) resultat_double; - + double gauche_double = this.gauche.calculer(x); + double droite_double = this.droite.calculer(x); + resultat = Math.Pow(gauche_double,droite_double); return resultat; - } - - } - // cas: () r() cos() sin() tan() et n() + // case: () r() cos() sin() tan() and n() else if(this.gauche!=null){ if (this.operateur=="()"){ resultat=this.gauche.calculer(x); return resultat; } else if (this.operateur=="sqrt()"){ - // convertion - double resultat_double; - double gauche_double = Convert.ToDouble(this.gauche.calculer(x)); - resultat_double= Math.Sqrt(gauche_double); - resultat = (float) resultat_double; - + double gauche_double = this.gauche.calculer(x); + resultat = Math.Sqrt(gauche_double); return resultat; } else if (this.operateur=="cos()"){ - // convertion - double resultat_double; - double gauche_double = Convert.ToDouble(this.gauche.calculer(x)); - resultat_double= Math.Cos(gauche_double); - resultat = (float) resultat_double; - + double gauche_double = this.gauche.calculer(x); + resultat = Math.Cos(gauche_double); return resultat; } else if (this.operateur=="sin()"){ - // convertion - double resultat_double; - double gauche_double = Convert.ToDouble(this.gauche.calculer(x)); - resultat_double= Math.Sin(gauche_double); - resultat = (float) resultat_double; - + double gauche_double = this.gauche.calculer(x); + resultat = Math.Sin(gauche_double); return resultat; } - else if (this.operateur=="tan()"){ - // convertion - double resultat_double; - double gauche_double = Convert.ToDouble(this.gauche.calculer(x)); - resultat_double= Math.Tan(gauche_double); - resultat = (float) resultat_double; - + else if (this.operateur=="tan()"){ + double gauche_double = this.gauche.calculer(x); + resultat = Math.Tan(gauche_double); return resultat; } - else if (this.operateur=="n()"){ - resultat = 0-this.gauche.calculer(x); + else if (this.operateur=="ln()"){ + double gauche_double = this.gauche.calculer(x); + resultat = Math.Log(gauche_double); return resultat; + } else if (this.operateur=="log()"){ - // convertion - double resultat_double; - double gauche_double = Convert.ToDouble(this.gauche.calculer(x)); - resultat_double= Math.Log(gauche_double); - resultat = (float) resultat_double; - + double gauche_double = this.gauche.calculer(x); + resultat = Math.Log10(gauche_double); return resultat; } else if (this.operateur=="acos()"){ - // convertion - double resultat_double; - double gauche_double = Convert.ToDouble(this.gauche.calculer(x)); - resultat_double= Math.Acos(gauche_double); - resultat = (float) resultat_double; - + double gauche_double = this.gauche.calculer(x); + resultat = Math.Acos(gauche_double); return resultat; } else if (this.operateur=="asin()"){ - // convertion - double resultat_double; - double gauche_double = Convert.ToDouble(this.gauche.calculer(x)); - resultat_double= Math.Asin(gauche_double); - resultat = (float) resultat_double; - + double gauche_double = this.gauche.calculer(x); + resultat = Math.Asin(gauche_double); return resultat; } else if (this.operateur=="atan()"){ - // convertion - double resultat_double; - double gauche_double = Convert.ToDouble(this.gauche.calculer(x)); - resultat_double= Math.Atan(gauche_double); - resultat = (float) resultat_double; - + double gauche_double = this.gauche.calculer(x); + resultat = Math.Atan(gauche_double); return resultat; } else if (this.operateur=="cosh()"){ - // convertion - double resultat_double; - double gauche_double = Convert.ToDouble(this.gauche.calculer(x)); - resultat_double= Math.Cosh(gauche_double); - resultat = (float) resultat_double; - + double gauche_double = this.gauche.calculer(x); + resultat = Math.Cosh(gauche_double); return resultat; } else if (this.operateur=="sinh()"){ - // convertion - double resultat_double; - double gauche_double = Convert.ToDouble(this.gauche.calculer(x)); - resultat_double= Math.Sinh(gauche_double); - resultat = (float) resultat_double; - + double gauche_double = this.gauche.calculer(x); + resultat = Math.Sinh(gauche_double); return resultat; } else if (this.operateur=="tanh()"){ - // convertion - double resultat_double; - double gauche_double = Convert.ToDouble(this.gauche.calculer(x)); - resultat_double= Math.Tanh(gauche_double); - resultat = (float) resultat_double; - + double gauche_double = this.gauche.calculer(x); + resultat = Math.Tanh(gauche_double); return resultat; } else if (this.operateur=="exp()"){ - // convertion - double resultat_double; - double gauche_double = Convert.ToDouble(this.gauche.calculer(x)); - resultat_double= Math.Exp(gauche_double); - resultat = (float) resultat_double; + double gauche_double = this.gauche.calculer(x); + resultat = Math.Exp(gauche_double); + return resultat; + } + else if (this.operateur=="abs()"){ + double gauche_double = this.gauche.calculer(x); + resultat = Math.Abs(gauche_double); return resultat; } + else if (this.operateur=="int()"){ + double gauche_double = this.gauche.calculer(x); + resultat = Math.Floor(gauche_double); + return resultat; + + } + } - else{ // phrase est obligatoirement de la forme "x" ou "2,1213" ou "2" + else{ // phrase is like "x" or "2,1213" or "2" if (this.phrase=="x" || this.phrase=="X"){ return x; } else{ decimal res_d = Convert.ToDecimal(this.phrase); - float res_f = (float) res_d; + double res_f = (double) res_d; resultat=res_f; return resultat; - } } - return resultat; - + return resultat; } - - - - - - // exemple: compte_depuis("a", 3) de "aaaaaa" =>3 - public int compte_depuis(string ch, int debut){ - int pos; - int nb=0; - bool arreter=false; - while( (debut <= this.phrase.Length) && (arreter == false) ){ - pos=phrase.IndexOf(ch,debut); - if(pos != -1){ - nb++; - debut=pos+1; - } - else{ - arreter=true; - } - - } - return nb; - } - - - - // exemple: compte_jusqua("a", 3) de "aaaaaa" =>3 - public int compte_jusqua(string ch, int fin){ + + // exemple: compte_jusqua("a", 3) for "aaaaaa" =>3 + private int compte_jusqua(string ch, int fin){ int pos; int nb=0; bool arreter=false; Binary files /tmp/t3D0teSbmK/graphmonkey-1.6/pixmaps/gm.png and /tmp/sm4dSF6ZwX/graphmonkey-1.7/pixmaps/gm.png differ Binary files /tmp/t3D0teSbmK/graphmonkey-1.6/pixmaps/graphmonkey.png and /tmp/sm4dSF6ZwX/graphmonkey-1.7/pixmaps/graphmonkey.png differ