Esempio n. 1
0
        public bool FromString(string s)
        {
            double xcenter = 0;
            double ycenter = 0;
            double radius  = 0;

            xmin     = -2;
            xmax     = 2;
            ymin     = -2;
            ymax     = 2;
            max_iter = 100;
            name     = null;
            bool bxmin = false, bxmax = false, bymin = false, bymax = false;

            int index = 0;

            string []       ss;
            int             n_range = 0;
            StringArgParser p       = new StringArgParser();

            ss = p.ParseStrings(s);
            if (ss != null && ss.Length > 0)
            {
                while (index < ss.Length)
                {
                    string str;
                    str = ss[index];
                    str.Trim();
                    index++;
                    if (str.Length > 1 && str[0] == '(' && str[str.Length - 1] == ')')
                    {
                        double x, y;
                        string inside = str.Substring(1, str.Length - 2);
                        if (inside != null && inside.Length > 0)
                        {
                            string [] range_strings;
                            range_strings = inside.Split(',');
                            if (range_strings != null && range_strings.Length == 2)
                            {
                                x = Convert.ToDouble(range_strings[0]);
                                y = Convert.ToDouble(range_strings[1]);
                                if (n_range == 0)
                                {
                                    xmin  = x;
                                    ymin  = y;
                                    bxmin = bymin = true;
                                }
                                else if (n_range == 1)
                                {
                                    xmax  = x;
                                    ymax  = y;
                                    bxmax = bymax = true;
                                }
                                n_range++;
                            }
                        }
                    }
                    else if (str == "-rmin")
                    {
                        if (index < ss.Length)
                        {
                            xmin  = Convert.ToDouble(ss[index]);
                            bxmin = true;
                            index++;
                        }
                    }
                    else if (str == "-rmax")
                    {
                        if (index < ss.Length)
                        {
                            xmax  = Convert.ToDouble(ss[index]);
                            bxmax = true;
                            index++;
                        }
                    }
                    else if (str == "-imin")
                    {
                        if (index < ss.Length)
                        {
                            ymin  = Convert.ToDouble(ss[index]);
                            bymin = true;
                            index++;
                        }
                    }
                    else if (str == "-imax")
                    {
                        if (index < ss.Length)
                        {
                            ymax  = Convert.ToDouble(ss[index]);
                            bymax = true;
                            index++;
                        }
                    }
                    else if (str == "-rcenter")
                    {
                        if (index < ss.Length)
                        {
                            xcenter = Convert.ToDouble(ss[index]);
                            index++;
                        }
                    }
                    else if (str == "-icenter")
                    {
                        if (index < ss.Length)
                        {
                            ycenter = Convert.ToDouble(ss[index]);
                            index++;
                        }
                    }
                    else if (str == "-radius")
                    {
                        if (index < ss.Length)
                        {
                            radius = Convert.ToDouble(ss[index]);
                            index++;
                        }
                    }
                    else if (str == "max_iter" || str == "-max_iter" || str == "-maxiter")
                    {
                        if (index < ss.Length)
                        {
                            max_iter = Convert.ToInt32(ss[index]);
                            index++;
                        }
                    }
                    else if (str == "name" || str == "-name")
                    {
                        if (index < ss.Length)
                        {
                            name = ss[index];
                            index++;
                        }
                    }
                }
            }

            if (radius != 0)
            {
                xmin  = xcenter - radius;
                xmax  = xcenter + radius;
                ymin  = ycenter - radius;
                ymax  = ycenter + radius;
                bxmin = bymin = bxmax = bymax = true;
            }

            if (xmin > xmax)
            {
                double d;
                d    = xmin;
                xmin = xmax;
                xmax = d;
            }
            if (ymin > ymax)
            {
                double d;
                d    = ymin;
                ymin = ymax;
                ymax = d;
            }
            if (xmin < -2)
            {
                xmin = -2;
            }
            if (xmax > 2)
            {
                xmax = 2;
            }
            if (ymin < -2)
            {
                ymin = -2;
            }
            if (ymax > 2)
            {
                ymax = 2;
            }
            if (max_iter < 1)
            {
                max_iter = 100;
            }
            if (max_iter > 10000)
            {
                max_iter = 100;
            }
            if (bxmin == true && bymin == true && bxmax == true && bymax == true)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 2
0
        public bool FromString(string s)
        {
            double xcenter = 0;
            double ycenter = 0;
            double radius = 0;
            xmin = -2;
            xmax = 2;
            ymin = -2;
            ymax = 2;
            max_iter = 100;
            name = null;
            bool bxmin=false, bxmax=false, bymin=false, bymax=false;

            int index = 0;
            string [] ss;
            int n_range = 0;
            StringArgParser p = new StringArgParser();
            ss = p.ParseStrings(s);
            if (ss != null && ss.Length > 0)
            {
                while (index < ss.Length)
                {
                    string str;
                    str = ss[index];
                    str.Trim();
                    index++;
                    if (str.Length > 1 && str[0] == '(' && str[str.Length-1] == ')')
                    {
                        double x,y;
                        string inside = str.Substring(1, str.Length-2);
                        if (inside != null && inside.Length > 0)
                        {
                            string [] range_strings;
                            range_strings = inside.Split(',');
                            if (range_strings != null && range_strings.Length == 2)
                            {
                                x = Convert.ToDouble(range_strings[0]);
                                y = Convert.ToDouble(range_strings[1]);
                                if (n_range == 0)
                                {
                                    xmin = x;
                                    ymin = y;
                                    bxmin = bymin = true;
                                }
                                else if (n_range == 1)
                                {
                                    xmax = x;
                                    ymax = y;
                                    bxmax = bymax = true;
                                }
                                n_range++;
                            }
                        }
                    }
                    else if (str == "-rmin")
                    {
                        if (index < ss.Length)
                        {
                            xmin = Convert.ToDouble(ss[index]);
                            bxmin = true;
                            index++;
                        }
                    }
                    else if (str == "-rmax")
                    {
                        if (index < ss.Length)
                        {
                            xmax = Convert.ToDouble(ss[index]);
                            bxmax = true;
                            index++;
                        }
                    }
                    else if (str == "-imin")
                    {
                        if (index < ss.Length)
                        {
                            ymin = Convert.ToDouble(ss[index]);
                            bymin = true;
                            index++;
                        }
                    }
                    else if (str == "-imax")
                    {
                        if (index < ss.Length)
                        {
                            ymax = Convert.ToDouble(ss[index]);
                            bymax = true;
                            index++;
                        }
                    }
                    else if (str == "-rcenter")
                    {
                        if (index < ss.Length)
                        {
                            xcenter = Convert.ToDouble(ss[index]);
                            index++;
                        }
                    }
                    else if (str == "-icenter")
                    {
                        if (index < ss.Length)
                        {
                            ycenter = Convert.ToDouble(ss[index]);
                            index++;
                        }
                    }
                    else if (str == "-radius")
                    {
                        if (index < ss.Length)
                        {
                            radius = Convert.ToDouble(ss[index]);
                            index++;
                        }
                    }
                    else if (str == "max_iter" || str == "-max_iter" || str == "-maxiter")
                    {
                        if (index < ss.Length)
                        {
                            max_iter = Convert.ToInt32(ss[index]);
                            index++;
                        }
                    }
                    else if (str == "name" || str == "-name")
                    {
                        if (index < ss.Length)
                        {
                            name = ss[index];
                            index++;
                        }
                    }
                }
            }

            if (radius != 0)
            {
                xmin = xcenter - radius;
                xmax = xcenter + radius;
                ymin = ycenter - radius;
                ymax = ycenter + radius;
                bxmin = bymin = bxmax = bymax = true;
            }

            if (xmin > xmax)
            {
                double d;
                d = xmin;
                xmin = xmax;
                xmax = d;
            }
            if (ymin > ymax)
            {
                double d;
                d = ymin;
                ymin = ymax;
                ymax = d;
            }
            if (xmin < -2)
                xmin = -2;
            if (xmax > 2)
                xmax = 2;
            if (ymin < -2)
                ymin = -2;
            if (ymax > 2)
                ymax = 2;
            if (max_iter < 1)
                max_iter = 100;
            if (max_iter > 10000)
                max_iter = 100;
            if (bxmin == true && bymin == true && bxmax == true && bymax == true)
                return true;
            return false;
        }