示例#1
0
        public FlickDirections DetectFlickDirection(StrokeInfo strokeInfo)
        {
            //Find the first points as A(X1, Y1) and last points as B(X2, Y2) in the current stroke
            StylusPoint pointA = strokeInfo.CurrentStroke.StylusPoints[0];
            StylusPoint pointB = strokeInfo.CurrentStroke.StylusPoints[strokeInfo.CurrentStroke.StylusPoints.Count - 1];

            double pointAx = pointA.X;
            double pointAy = pointA.Y;
            double pointBx = pointB.X;
            double pointBy = pointB.Y;

            double deltaX = Math.Abs(pointAx - pointBx);
            double deltaY = Math.Abs(pointAy - pointBy);

            double radians = Math.Atan2(deltaY, deltaX);
            double angle = radians * (180 / Math.PI);

            if (pointBy < pointAy)
            {
                //up direction
                if (pointBx < pointAx && angle < 60)
                {
                    strokeInfo.StrokeFlickDirection = FlickDirections.UpLeft;
                    return FlickDirections.UpLeft;
                }
                else if (pointBx > pointAx && angle < 60)
                {
                    strokeInfo.StrokeFlickDirection = FlickDirections.UpRight;
                    return FlickDirections.UpRight;
                }
                else
                {
                    strokeInfo.StrokeFlickDirection = FlickDirections.Up;
                    return FlickDirections.Up;
                }
            }
            else
            {
                //down direction
                if (pointBx < pointAx && angle < 60)
                {
                    strokeInfo.StrokeFlickDirection = FlickDirections.DownLeft;
                    return FlickDirections.DownLeft;
                }
                else if (pointBx > pointAx && angle < 60)
                {
                    strokeInfo.StrokeFlickDirection = FlickDirections.DownRight;
                    return FlickDirections.DownRight;
                }
                else
                {
                    strokeInfo.StrokeFlickDirection = FlickDirections.Down;
                    return FlickDirections.Down;
                }
            }
        }
示例#2
0
        public bool IsFlick(StrokeInfo strokeInfo)
        {
            //Feature 1: speed > SpeedRatio
            //Feature 2: first 5 points pressure average > last 5 points pressure average
            //Feature 3: distance between first point and last point < distanceRatio
            //Feature 4: TimeSpan total milliseconds < 400
            if (strokeInfo.Span.TotalMilliseconds < TimeThreshold)
            {
                //if (strokeInfo.Speed > SpeedMin)
                //{
                if (strokeInfo.StrokeLength < DistanceMax && DistanceMin < strokeInfo.StrokeLength)
                {
                    if (strokeInfo.PressureRatio > PressureRatioThreshold)
                    {
                        strokeInfo.IsFlickGesture = true;
                        return true;
                    }
                }
                //}
            }

            strokeInfo.IsFlickGesture = false;
            return false;
        }
示例#3
0
        public void circuitInkCanvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e)
        {
            CurrentStroke = e.Stroke;

            if (!circuitInkCanvas.Strokes.Contains(e.Stroke))
            {
                circuitInkCanvas.Strokes.Add(e.Stroke);
            }

            #region Flick Detection

            //Flick Gesture
            TimeSpan timespan = DateTime.Now - _stylusDownTime;

            StrokeInfo stroke = new StrokeInfo(CurrentStroke, timespan);

            //Real Analysis
            if (StrokeAnalyzer.Instance.IsFlick(stroke) && 1 == 0)
            {
                FlickDirections direction = StrokeAnalyzer.Instance.DetectFlickDirection(stroke);
                StylusPoint PointA = stroke.StartPoint;
                StylusPoint PointB = stroke.EndPoint;
                AnimateArrowInFlickDirection(PointA.X, PointA.Y, PointB.X, PointB.Y);

                //Throw one gate xaml on the canvas
                Gate newGate = null;

                switch (direction)
                {
                    case FlickDirections.UpLeft:
                        newGate = new UserOutput();
                        break;
                    case FlickDirections.DownLeft:
                        newGate = new Xor();
                        //OR
                        break;
                    case FlickDirections.Down:
                        newGate = new And();
                        //AND
                        break;
                    case FlickDirections.DownRight:
                        //NOT
                        newGate = new Not();
                        break;
                    case FlickDirections.Up:
                        //INPUT
                        newGate = new Or();
                        break;
                    case FlickDirections.UpRight:
                        //OUTPUT
                        newGate = new UserInput();
                        break;
                }
                //GateLocation location = new GateLocation();
                //Heuristic
                //BO KANG??
                Point temp = new Point(PointA.X - 30, PointA.Y - 30);

                this.AddGate(newGate, new GateLocation(this.GetNearestSnapTo(this.TranslateScrolledPoint(temp))));
                //this.AddGate(newGate, location);
                this.circuitInkCanvas.UpdateLayout();
                this.circuitInkCanvas.Strokes.Remove(CurrentStroke);
            }

            #endregion

            /* check for drag Gate Stroke*/
            if (onGateStroke)
            {
                circuitInkCanvas.Strokes.Remove(e.Stroke);
                return;
            }

            /*check for draw wire stroke*/
            if(onWireStroke)
            {
                circuitInkCanvas.Strokes.Remove(e.Stroke);
                onWireStroke = false;
                return;
            }else
            {
                if(onWireMoveStroke)
                {
                    circuitInkCanvas.Strokes.Remove(e.Stroke);
                    onWireMoveStroke = false;
                    return;
                }
            }

            //Debug.WriteLine("Stroke Bound Percentage is " + stroke.BoundPercentage);
            /* Test if the current stroke is wire connect stroke */
            if (stroke.BoundPercentage > 10)
            {
                return;
            }

            //Debug.WriteLine("Stroke BoundPercentage is " + stroke.BoundPercentage.ToString());

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