Пример #1
0
        private bool LassoSelect(InqCanvas.StroqCollectedEventArgs e)
        {
            if (e.Stroq.OldPolylineCusps().Length <= 4 && e.Stroq.Count > 4)
            {
                Stroq estroq = e.Stroq;
                CuspDetector.CuspSet cs = CuspDetector.FeaturePoints(estroq);

                Pt[] first = new Pt[cs.pts.Count / 2];
                for (int i = 0; i < first.Length; i++)
                    if (cs.distances[i] > cs.dist / 2)
                        break;
                    else first[i] = cs.pts[i];
                Pt[] second = new Pt[cs.pts.Count - first.Length];
                for (int j = 0; j < second.Length; j++) second[j] = cs.pts[first.Length + j];
                Stroq s1 = new Stroq(first);
                Stroq s2 = new Stroq(second);
                float d1, d2;
                s1.OldNearestPoint(s2[-1], out d1);
                s2.OldNearestPoint(s1[0], out d2);
                if (Math.Min(d1, d2) / Math.Max(estroq.GetBounds().Width, estroq.GetBounds().Height) < 0.3f)
                {
                    StroqCollection stqs = _mathStroqs.HitTest(estroq, 50);
                    StroqCollection stqs2 = _mathStroqs.HitTest(estroq.Reverse1(), 50);
                    if (stqs2.Count > stqs.Count)
                        stqs = stqs2;
                    stqs.Remove(estroq);
                    StroqCollection stqs3 = new StroqCollection(stqs.Where((Stroq s) => _mrec.Charreco.Classification(_mrec.Sim[s]) != null));
                    stqs = stqs3;
                    Recognition rtemp = _mrec.ClassifyOneTemp(estroq);
                    if (stqs.Count > 0 && (rtemp == null || !rtemp.alts.Contains(new Recognition.Result(Unicode.S.SQUARE_ROOT))))
                    {
                        if (rtemp != null) Console.WriteLine("select recognized for " + rtemp.allograph);
                        Deselect();

                        estroq.BackingStroke.DrawingAttributes.Color = Colors.Purple;
                        Selected.Contents = new StroqSel(stqs, estroq, (Stroq s) => _mrec.Charreco.Classification(_mrec.Sim[s]),
                            (Recognition r) => _mrec.Sim[r.strokes], inqCanvas.Stroqs);
                        StroqSel Sel = (StroqSel)Selected.Contents;
                        HashSet<Recognition> recogs = new HashSet<Recognition>(Sel.AllStroqs.Select((Stroq s) => _mrec.Charreco.Classification(_mrec.Sim[s]))
                            .Where((Recognition r) => r != null));
                        if (recogs.Count != 0) showSidebarAlts(recogs, Sel.AllStroqs);

                        return true;
                    }
                    else
                    {
                        // Generic additional selections would be called here.
                        return false;
                    }
                }
            }
            return false;
        }
Пример #2
0
        //BOKANG TODO, check for the tap gesture
        public bool isTapGesture(InqCanvas.StroqCollectedEventArgs e)
        {
            Stroq currentStroq = e.Stroq;

            Recognition rtempt = _mrec.ClassifyOneTemp(currentStroq);

            if (rtempt != null && rtempt.alts.Contains<Recognition.Result>(Unicode.F.FULL_STOP))
            {
                return true;
            }

            return false;
        }
Пример #3
0
        private bool ScribbleDelete(InqCanvas.StroqCollectedEventArgs e)
        {
            bool canBeScribble = e.Stroq.OldPolylineCusps().Length > 4;
            if (e.Stroq.OldPolylineCusps().Length == 4)
            {
                int[] pcusps = e.Stroq.OldPolylineCusps();
                Deg a1 = fpdangle(e.Stroq[0], e.Stroq[pcusps[1]], e.Stroq[pcusps[2]] - e.Stroq[pcusps[1]]);
                Deg a2 = fpdangle(e.Stroq[pcusps[1]], e.Stroq[pcusps[1]], e.Stroq[pcusps[3]] - e.Stroq[pcusps[1]]);
                if (a1 < 35 && a2 < 35)
                    canBeScribble = e.Stroq.BackingStroke.HitTest(e.Stroq.ConvexHull().First(), 1);
            }
            if (canBeScribble)
            {
                IEnumerable<Pt> hull = e.Stroq.ConvexHull();
                StroqCollection stqs = inqCanvas.Stroqs.HitTest(hull, 1);
                if (stqs.Count > 1)
                {
                    inqCanvas.Stroqs.Remove(stqs);
                    _mathStroqs.Remove(stqs);

                    inqCanvas.Stroqs.Remove(e.Stroq);
                    return true;
                }
            }
            return false;
        }
Пример #4
0
        void inqCanvas_StroqCollected(object sender, InqCanvas.StroqCollectedEventArgs e)
        {
            /* filter out gestures before taking everything else as math */

            //BOKANG, check user's tap gesture in order to trigger the animation
            /*
            if (Selected.Contents != null)
            {
                if (isTapGesture(e))
                {
                    triggerAnimationForLogicExpression(Selected.Contents);
                    _mathStroqs.Remove(e.Stroq);
                    inqCanvas.Stroqs.Remove(e.Stroq);
                    return;
                }
            }
             * */

            /* If we get here, it's a real stroke (not movement), so deselect any selection */
            Deselect();

            /* check for scribble delete */
            if (ScribbleDelete(e)) return;

            /* check for lassos/circles around stuff */
            if (LassoSelect(e)) return;

            _mathStroqs.Add(e.Stroq);
        }