Example #1
0
        private void Draw(ZedGraphControl zgc, string expression, double from, double to, double step = 0.01f)
        {
            // Obtain GraphPane from ZedGraphControl
            GraphPane pane = zgc.GraphPane;

            int compileResult = LibraryBridge.CompileExpression(expression);

            if (0 != compileResult)
            {
                MessageBox.Show(string.Format(@"Expression error on col {0}", compileResult), @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                tbExpression.Focus();

                return;
            }

            // from MUST be less than to, ensure that
            if (from.CompareTo(to) > 1)
            {
                double temp = from;
                from = to;
                to   = temp;
            }

            double startValue = from,
                   endValue   = to;

            // Go to the library and get points
            int pointsCount = LibraryBridge.CalculatePointsCount(startValue, endValue, step);

            double[] points    = new double[pointsCount];
            IntPtr   pointsPtr = LibraryBridge.GetFunctionPoints(startValue, endValue, step);

            Marshal.Copy(pointsPtr, points, 0, pointsCount);

            // Create the list...
            PointPairList list1 = new PointPairList();
            // ... and add points to the list.
            // ReSharper disable once TooWideLocalVariableScope
            double thePoint;

            for (int i = 0; i < pointsCount; i++)
            {
                thePoint = startValue + (step * i);

                if (thePoint > endValue)
                {
                    thePoint = endValue;
                }

                list1.Add(thePoint, points[i]);
            }

            // Add the list to GraphPane
            pane.AddCurve(expression, list1, Color.Blue, SymbolType.None);

            // Finally make ZedGraphControl to re-draw itself
            zgc.AxisChange();
            zgc.Invalidate();
        }
Example #2
0
        private void Draw2(ZedGraphControl zgc, string expression, double from, double to, double step = 0.1f)
        {
            // Obtain GraphPane from ZedGraphControl
            GraphPane pane = zgc.GraphPane;

            _theExpression = expression;

            // from MUST be less than to, ensure that
            if (from.CompareTo(to) > 1)
            {
                double temp = from;
                from = to;
                to   = temp;
            }

            // Create the list...
            PointPairList list1 = new PointPairList();

            // ... and add points to the list.
            for (double i = from; i < to; i += step)
            {
                list1.Add(i, LibraryBridge.F(i));
            }

            // Add the list to GraphPane
            pane.AddCurve(_theExpression, list1, Color.Blue, SymbolType.Square);

            // Finally make ZedGraphControl to re-draw itself
            zgc.AxisChange();
            zgc.Invalidate();
        }
Example #3
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());

            return;

            // TODO Get expression from user
            string expression    = @"x^2-3";
            int    compileResult = LibraryBridge.CompileExpression(expression);

            if (0 == compileResult)
            {
                //Console.WriteLine(LibraryBridge.F(4));

                // TODO Get these values from user
                double startValue = 1f,
                       endValue   = 6.4f,
                       step       = 0.5f;

                int      pointsCount = LibraryBridge.CalculatePointsCount(startValue, endValue, step);
                double[] points      = new double[pointsCount];
                IntPtr   pointsPtr   = LibraryBridge.GetFunctionPoints(startValue, endValue, step);
                Marshal.Copy(pointsPtr, points, 0, pointsCount);

                foreach (double point in points)
                {
                    Console.WriteLine(point);
                }

                LibraryBridge.FreeCompiledExpression();
            }
            else
            {
                Console.WriteLine(@"Error occured on col {0} while compiling expression.", compileResult);
            }

            //LibraryBridge.SomeFunction(@"Hello World!");


            /*int arraySize = LibraryBridge.GetArraySize();
             * double[] theArray = new double[arraySize];
             *
             * LibraryBridge.GetArray(theArray);
             *
             * Console.WriteLine(@"Array Size: {0}", arraySize);
             *
             * for (int i = 0; i < arraySize; i++) {
             *  Console.WriteLine(@"#{0} {1}", i, theArray[i]);
             * }
             */

            /*int arraySize = LibraryBridge.GetArraySize();
             * StepOutput[] theArray = new StepOutput[arraySize];
             *
             * LibraryBridge.GetStepOutputs(theArray);
             *
             * Console.WriteLine(@"Array Size: {0}", arraySize);
             *
             * for (int i = 0; i < arraySize; i++) {
             *  Console.WriteLine(
             *      @"#{0}{1}{2}{1}{3}{1}{4}{1}",
             *      i,
             *      Environment.NewLine,
             *      theArray[i].a,
             *      theArray[i].b,
             *      theArray[i].root
             *      );
             * }
             */
        }