/*
         *  Recognize a Mouse_Data type gesture
         */
        public string Recognize(ref Mouse_Data s, bool Consider_Stroke = true)
        {
            Penny_Pincher_Data P = new Penny_Pincher_Data(s);

            s.Label = Recognize(ref P, Consider_Stroke);
            return(s.Label);
        }
Esempio n. 2
0
        private void RecLast()
        {
            Mouse_Data M = Screen.Last();

            Recognizer.Recognize(ref M);
            Screen[Screen.Count - 1] = M;
        }
Esempio n. 3
0
        private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Temp = new Mouse_Data();
            Point P = e.GetPosition(this);

            Temp.Add_Point(P);
            Mouse_Down = true;
        }
Esempio n. 4
0
 public void Union(Mouse_Data Next)                          //Simply Connect the two Datas
 {
     Trace.Assert(Next.Finished_Collecting);
     foreach (Point P in Next.Points)
     {
         Points.Add(P);
     }
     Finish_Collecting();
 }
Esempio n. 5
0
 public void Tranform_from_Mouse_Data(Mouse_Data Data)
 {
     Trace.Assert(Data.Finished_Collecting);
     for (int i = 1; i < Data.Count; i++)
     {
         Vectors.Add(Data.Points[i] - Data.Points[i - 1]);
     }
     Label   = Data.Label;
     Strokes = Data.Strokes;
     Trace.Assert(Vectors.Count == MainWindow.DIVISION - 1);
 }
Esempio n. 6
0
 public Mouse_Data(Mouse_Data mouse_Data)
 {
     Points = new List <Point>();
     Label  = mouse_Data.Label;
     foreach (Point p in mouse_Data.Points)
     {
         Points.Add(p);
     }
     Finished_Collecting = mouse_Data.Finished_Collecting;
     Center     = mouse_Data.Center;
     Boundary   = mouse_Data.Boundary;
     Strokes    = mouse_Data.Strokes;
     Calculated = mouse_Data.Calculated;
 }
Esempio n. 7
0
 public bool Intersect(Mouse_Data Next)
 {
     Trace.Assert(Next.Finished_Collecting && Finished_Collecting);
     for (int i = 0; i < MainWindow.DIVISION - 1; i++)
     {
         for (int j = 1; j < MainWindow.DIVISION - 1; j++)
         {
             if (Intersect_Point(Points[i], Points[i + 1], Next.Points[j], Next.Points[j + 1]))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 8
0
        /*
         *---------------------------One of the most important functions of the program----------------------------------------
         * Called when the equal sign is written
         */
        private double Calculate_Value()
        {
            List <Mouse_Data> L = new List <Mouse_Data>();

            for (int i = 0; i < Screen.Count; i++)
            {
                Mouse_Data D = Screen[i];
                if (D.Label != "equals" && !D.Calculated)
                {
                    L.Add(D);
                }
                Screen[i].Calculated = true;
            }
            Math_Node Tree = new Math_Node(L);

            return(Tree.Calculate());
        }
Esempio n. 9
0
        static public string ToFormula(List <Mouse_Data> Datas)
        {
            if (Datas.Count == 0)
            {
                return("");
            }
            //Change all "horizontalline" to "minus" or "divide"
            Determine_Horizonal_Line(ref Datas);
            //The return formula
            string S = "";
            //All the formulas including the squareroot sign
            List <string> Sqrt = new List <string>();
            //All the formulas including division
            List <string> Div = new List <string>();
            //All the formulas including the power sign
            List <string> Power = new List <string>();

            //Sort by their X value
            Datas.Sort();
            for (int i = 0; i < Datas.Count; i++)
            {
                Mouse_Data D = Datas[i];
                //Add all the squareroot formulas
                if (D.Label == "square root")
                {
                    List <Mouse_Data> Sqrt_Data = new List <Mouse_Data>();
                    for (int j = 0; j < Datas.Count; j++)
                    {
                        Mouse_Data O = Datas[j];
                        if (O.IsInside(D))
                        {
                            Sqrt_Data.Add(O);
                            Datas.Remove(O);
                            j--;
                        }
                    }
                    D.Combine(Sqrt_Data);
                }
                //Add all the division formulas
                if (i >= Datas.Count - 1)
                {
                    continue;
                }
                List <Mouse_Data> Numerator   = new List <Mouse_Data>();
                List <Mouse_Data> Denominator = new List <Mouse_Data>();
                if (D.Label == "divide")
                {
                    for (int j = 0; j < Datas.Count; j++)
                    {
                        Mouse_Data O = Datas[j];
                        if (O.IsAbove(D))
                        {
                            Numerator.Add(O);
                            Datas.Remove(O);
                            j--;
                        }
                        if (O.IsUnder(D))
                        {
                            Denominator.Add(O);
                            Datas.Remove(O);
                            j--;
                        }
                    }
                    D.Combine(Numerator, Denominator);
                }
                //Add all the power formulas
                if (i >= Datas.Count - 1)
                {
                    continue;
                }
                if (Datas[i + 1].IsOnRightTopOf(Datas[i]) && (char.IsDigit(Datas[i].Label[0]) || (Datas[i].Label == "square root")))
                {
                    List <Mouse_Data> Power_Data = new List <Mouse_Data>();
                    while (i < Datas.Count - 1 && Datas[i + 1].IsOnRightTopOf(Datas[i]))
                    {
                        Power_Data.Add(Datas[i + 1]);
                        Datas.RemoveAt(i + 1);
                    }
                    Mouse_Data _Temp = new Mouse_Data("^");
                    _Temp.Combine(Power_Data);
                    Datas.Insert(i + 1, _Temp);
                }
            }
            //Now build the string!
            foreach (Mouse_Data _d in Datas)
            {
                S += _d.ToFormula();
            }
            Add_Abbreviated_Sign(ref S);
            Add_parentheses(ref S, 0, S.Length - 1);
            Debug.Print(S);
            return(S);
        }
Esempio n. 10
0
 public Penny_Pincher_Data(Mouse_Data Data)
 {
     Vectors = new List <Vector>();
     Tranform_from_Mouse_Data(Data);
 }
Esempio n. 11
0
 public bool IsInside(Mouse_Data d)
 {
     return((d.Boundary.Contains(Center)) && (Boundary.Top > d.Boundary.Top));
 }
Esempio n. 12
0
 public bool IsAbove(Mouse_Data d)
 {
     return(Center.Y < d.Center.Y && Center.X > d.Boundary.Left && Center.X < d.Boundary.Right && Center.Y > d.Center.Y - d.Boundary.Width * 1.5);
 }
Esempio n. 13
0
        public int CompareTo(object D)
        {
            Mouse_Data d = D as Mouse_Data;

            return(Boundary.Left.CompareTo(d.Boundary.Left));
        }
Esempio n. 14
0
 public bool inRect(Mouse_Data data)
 {
     Trace.Assert(data.Finished_Collecting && Finished_Collecting);
     return(Boundary.Contains(data.Center));
 }
Esempio n. 15
0
 internal bool IsOnRightTopOf(Mouse_Data mouse_Data)
 {
     return((Boundary.Left > (mouse_Data.Center.X)) && (Boundary.Bottom < mouse_Data.Center.Y) && (Boundary.Bottom - Boundary.Top < mouse_Data.Boundary.Bottom - mouse_Data.Boundary.Top) && (Boundary.Top < (mouse_Data.Boundary.Top + mouse_Data.Center.Y) / 2));
 }
Esempio n. 16
0
 public bool IsUnder(Mouse_Data d)
 {
     return(Center.Y > d.Center.Y && Center.X > d.Boundary.Left && Center.X < d.Boundary.Right);
 }
Esempio n. 17
0
        private void Window_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (!Mouse_Down)
            {
                return;
            }
            Mouse_Down = false;
            //---------------------------------Add the last point to the canvas and screen---------------------------------
            Point P = e.GetPosition(this);

            Draw_Point(P);
            Temp.Add_Point(P);
            //---------------------------------Do the finished work--------------------------------------------------------
            Temp.Finish_Collecting();
            if (!Temp.Finished_Collecting)
            {
                return;
            }
            //--------------------------check if the current gesture should be unioned with the last gesture-----------------------
            if (Screen.Count != 0)
            {
                Mouse_Data REF = Screen[Screen.Count - 1];
                if ((Screen[Screen.Count - 1].Intersect(Temp) || (Screen[Screen.Count - 1].Boundary.Contains(Temp.Center)) && Recognizer.Recognize(ref REF) != "square root"))
                {
                    Mouse_Data T = Screen[Screen.Count - 1];
                    T.Union(Temp);
                    Screen[Screen.Count - 1] = T;
                }
                else
                {
                    RecLast();
                    if (Screen.Last().Label == "horizontal line")
                    {
                        Mouse_Data D = new Mouse_Data(Screen.Last());
                        D.Union(Temp);
                        if (Recognizer.Recognize(ref Temp) == "horizontal line" && Recognizer.Recognize(ref D, false) == "equals")
                        {
                            Screen[Screen.Count - 1] = D;
                            double R = Calculate_Value();
                            Debug.Print(R.ToString());
                            #region Output_Answer
                            Label AnswerBox = new Label();
                            AnswerBox.Content = R.ToString();
                            double L, T;
                            AnswerBox.Margin   = new Thickness(L = Temp.Boundary.X + Temp.Boundary.Width + 10, T = ((Temp.Boundary.Y + Temp.Boundary.Height + D.Boundary.Y + D.Boundary.Height) / 2 - 50), 0, MainCanvas.Height - T - 20);
                            AnswerBox.FontSize = 50;
                            MainCanvas.Children.Add(AnswerBox);
                            #endregion
                        }
                        else
                        {
                            Screen.Add(Temp);
                        }
                    }
                    else
                    {
                        Screen.Add(Temp);
                    }
                }
            }
            else
            {
                Screen.Add(Temp);
            }
        }