Example #1
0
        private void ComputePaintColors(starPadSDK.MathRecognizer.Line root, Recognition update)
        {
            string path = FindPath(root, update);

            if (path == "" || path == "X")
            {
                return;
            }
            colTime ct;

            if (_recent.TryGetValue(path, out ct))  // refresh the time for this path
            {
                _recent[path] = new colTime(ct.col, ++colTime.timestamp);
                return;
            }
            // if there are no colors left, recycle the color assigned to the LRU path
            if (_colors.Count == 0)
            {
                //var oldest = _recent.Aggregate(new Pair<int, string>(colTime.timestamp, null),
                //    (min, old) => old.Value.time <= min.First ? new Pair<int, string>(old.Value.time, old.Key) : min);
                var oldest = _recent.Min(colTime.timestamp, (kvp) => kvp.Value.time);
                if (oldest.Key != null)
                {
                    _colors.Add(oldest.Value.col);
                    _recent.Remove(oldest.Key);
                }
            }
            // choose a color for this path
            _recent.Add(path, new colTime(_colors[_colors.Count - 1], ++colTime.timestamp));
            _colors.RemoveAt(_colors.Count - 1);
        }
Example #2
0
 private Symbol FindSymbol(starPadSDK.MathRecognizer.Line l, Recognition r)
 {
     foreach (Symbol s in l._syms)
     {
         if (s.r.guid == r.guid)
         {
             return(s);
         }
         else
         {
             Symbol l1 = FindSymbol(s.Super, r);
             if (l1 != null)
             {
                 return(l1);
             }
             Symbol l2 = FindSymbol(s.Sub, r);
             if (l2 != null)
             {
                 return(l2);
             }
             if (s is IntSym)
             {
                 Symbol l3 = FindSymbol(((IntSym)s).Integrand, r);
                 if (l3 != null)
                 {
                     return(l3);
                 }
             }
             if (s is ParenSym)
             {
                 foreach (starPadSDK.MathRecognizer.Line ll in ((ParenSym)s).lines)
                 {
                     Symbol l3 = FindSymbol(ll, r);
                     if (l3 != null)
                     {
                         return(l3);
                     }
                 }
                 if (((ParenSym)s).Closing != null && ((ParenSym)s).Closing.r.guid == r.guid)
                 {
                     return(((ParenSym)s).Closing);
                 }
             }
         }
     }
     return(null);
 }
Example #3
0
        private string FindPath(starPadSDK.MathRecognizer.Line l, Recognition r, ref Symbol refParent, ref Symbol lineParent, List <Recognition> pending)
        {
            foreach (Symbol s in l._syms)
            {
                if (s.r.guid == r.guid)
                {
                    bool foundit = false;
                    for (int i = l._syms.IndexOf(s) - 1; i >= 0; i--)
                    {
                        if ("+=><()".IndexOf(l._syms[i].Sym.Character) == -1 && l._syms[i].Sym.Character != Unicode.M.MINUS_SIGN)
                        {
                            lineParent = l._syms[i];
                            foundit    = true;
                            break;
                        }
                    }
                    if (!foundit)
                    {
                        for (int i = l._syms.IndexOf(s) + 1; i < l._syms.Count; i++)
                        {
                            if (!pending.Contains(l._syms[i].r) && "+=><()".IndexOf(l._syms[i].Sym.Character) == -1 && l._syms[i].Sym.Character != Unicode.M.MINUS_SIGN)
                            {
                                lineParent = l._syms[i];
                                foundit    = true;
                                break;
                            }
                        }
                    }
                    return("X");
                }
                else
                {
                    Symbol tmpParent = s, tmpLineParent = null;
                    string path1 = FindPath(s.Super, r, ref tmpParent, ref tmpLineParent, pending);
                    if (path1 != "")
                    {
                        refParent  = tmpParent;
                        lineParent = tmpLineParent;
                        return((s is RootSym ? "R" : (s is DivSym ? "D" : "P")) + path1);
                    }
                    string path2 = FindPath(s.Sub, r, ref tmpParent, ref tmpLineParent, pending);
                    if (path2 != "")
                    {
                        refParent  = tmpParent;
                        lineParent = tmpLineParent;
                        return((s is DivSym ? "V" : (s is RootSym ? "" : "B")) + path2);
                    }
                    if (s is IntSym)
                    {
                        tmpParent = null;

                        string path3 = FindPath(((IntSym)s).Integrand, r, ref tmpParent, ref tmpLineParent, pending);
                        if (path3 != "")
                        {
                            refParent  = (s.r.alt == Unicode.I.INTEGRAL ? tmpParent : refParent);
                            lineParent = path3 == "X" && tmpLineParent == null ? s : tmpLineParent;
                            if (path3[0] == 'P' || path3[0] == 'B')
                            {
                                return("I" + path3);
                            }
                            else
                            {
                                return(path3);
                            }
                        }
                    }
                    if (s is ParenSym)
                    {
                        tmpParent = null;
                        string path3 = "";
                        foreach (starPadSDK.MathRecognizer.Line ll in ((ParenSym)s).lines)
                        {
                            path3 = FindPath(ll, r, ref tmpParent, ref tmpLineParent, pending);
                            if (path3 != "")
                            {
                                lineParent = path3 == "X" && tmpLineParent == null ? s : tmpLineParent;
                                return(path3);
                            }
                        }
                        if (((ParenSym)s).Closing != null && ((ParenSym)s).Closing.r.guid == r.guid)
                        {
                            lineParent = s;
                            return("X");
                        }
                    }
                }
            }
            return("");
        }
Example #4
0
        private string FindPath(starPadSDK.MathRecognizer.Line l, Recognition r)
        {
            Symbol parent = null, lineParent = null;

            return(FindPath(l, r, ref parent, ref lineParent, new List <Recognition>()));
        }