Esempio n. 1
0
        /// <summary>
        /// Method for returning the collection of styluspoints in the expert stroke from the point at which the pen is standing. Check that none of the Parameters are empty
        /// </summary>
        /// <param name="s">Stroke formed from the event args styluspoint collection</param>
        /// <param name="SC"></param>
        /// <returns></returns>
        //private StylusPoint SelectNearestExpertPoint(Stroke RenderedStroke, StrokeCollection ExpertStrokeCollection, out Stroke ExpertStroke)
        //{
        //    //delcare value that holds the  distance between the pen and the expert stroke.
        //    double tempStrokeDeviation = -0.01d;
        //    //the styluspoint to be returned to the expert, set the first point as default
        //    StylusPoint tempStylusPoint = ExpertStrokeCollection.First().StylusPoints.First();
        //    //assign the first stroke from expertstrokecollection
        //    Stroke tempStroke = ExpertStrokeCollection.First();
        //    //get the bouding rect of the args stroke
        //    Rect rect = RenderedStroke.GetBounds();
        //    //get the center point of the arg stroke for calculating the tempDistance
        //    Point centerPoint = new Point(rect.Left + rect.Width / 2, rect.Top + rect.Height / 2);

        //    // local function iterates through each stroke and their stylusPoint
        //    void loop()
        //    {
        //        foreach (Stroke s in ExpertStrokeCollection)
        //        {
        //            //iterate through each styluspoint in a stroke
        //            foreach (StylusPoint s in s.StylusPoints)
        //            {
        //                double tempDistance = CalculateDistance(centerPoint, s.ToPoint());
        //                //if it is the first time
        //                if (tempStrokeDeviation < 0)
        //                {
        //                    tempStrokeDeviation = tempDistance;
        //                    continue;
        //                }
        //                //if the distance is less than 0.5, return the point and exit the loop
        //                if (tempDistance <= 0.5d)
        //                {
        //                    //assign the values
        //                    tempStroke = s;
        //                    tempStylusPoint = s;
        //                    return;

        //                }
        //                else if (tempDistance < tempStrokeDeviation)
        //                //if the point does not intersect the expert stroke, check if the new tempDistance is smaller than the previous tempDistance
        //                {
        //                    //assign the new shorter tempDistance, and assign the new point as ref point
        //                    tempStrokeDeviation = tempDistance;
        //                    tempStylusPoint = s;
        //                    tempStroke = s;
        //                }
        //            }
        //        }
        //    }
        //    //call the local function
        //    loop();
        //    ExpertStroke = tempStroke;
        //    return tempStylusPoint;

        //}

        /// <summary>
        /// Method that returns collection of Expertstrokes that are colliding with the current stroke.
        /// This is similar to <see cref="BaseInkCanvas"/>'s ReturnExpertStroke collection but instead of a
        /// taking a single input as a point which is updated on physical points hover, which cannot be
        /// accessed in this thread, it takes the whole stroke from the event.
        /// </summary>
        /// <param name="RenderedStroke"></param>
        /// <param name="ExpertStrokeCollection"></param>
        /// <returns></returns>
        //private StrokeCollection SelectBoundingStrokeCollection(Stroke RenderedStroke, StrokeCollection ExpertStrokeCollection)
        //{
        //    //holds all the expert strokes that intersects with the current stroke being drawn
        //    StrokeCollection expertStrokeCollection = new StrokeCollection();

        //    foreach (Stroke es in ExpertStrokeCollection)
        //    {
        //        //if the strokes intersect add it to the collection
        //        if (RenderedStroke.GetBounds().IntersectsWith(es.GetBounds()))
        //        {
        //            expertStrokeCollection.Add(es);
        //        }
        //    }

        //    return expertStrokeCollection;
        //}

        private StylusPoint ReturnExpertStylusPoint(StylusPointCollection StudentSPC, StylusPoint CurrentExpertStylusPoint, Stroke ExpertStroke)
        {
            StylusPoint SP = CurrentExpertStylusPoint;

            if (ExpertStroke.StylusPoints.IndexOf(SP) >= ExpertStroke.StylusPoints.Count - 1)
            {
                return(SP);
            }
            int CurrentExpertSPIndex = ExpertStroke.StylusPoints.IndexOf(CurrentExpertStylusPoint);
            //check if the position of the current stroke is nearer to the previous expert point or has moved on to the next point
            double distanceCurrentSP = -0.01d;
            //the distance from the current position to the next stylusPoint
            double distanceNextSP = -0.01d;

            //get the shortest distance from the current position, by iterating through every point, to the current expert stylus point
            foreach (StylusPoint s in StudentSPC.ToList())
            {
                //the distance form the current position to the current stylusPoint and the next consequtive point
                double tempDistancePre  = CalculateDistance(s.ToPoint(), ExpertStroke.StylusPoints[CurrentExpertSPIndex].ToPoint());
                double tempDistancePost = CalculateDistance(s.ToPoint(), ExpertStroke.StylusPoints[CurrentExpertSPIndex + 1].ToPoint());
                //if it is the first time running
                if (distanceCurrentSP < 0 || distanceNextSP < 0)
                {
                    distanceCurrentSP = tempDistancePre;
                    distanceNextSP    = tempDistancePost;
                    continue;
                }

                //if it is not the first time running, get the shortest distance between the current point and the current expert point.
                if (tempDistancePre < distanceCurrentSP)
                {
                    distanceCurrentSP = tempDistancePre;
                    //Debug.WriteLine("1");
                }

                //if it is not the first time running, get the shortest distance between the current point and the Next expert point.
                if (tempDistancePost < distanceNextSP)
                {
                    distanceNextSP = tempDistancePost;
                    //Debug.WriteLine("2");
                }

                //if it is not the last point
                if (CurrentExpertSPIndex > ExpertStroke.StylusPoints.Count)
                {
                    CurrentExpertSPIndex += 1;
                }
            }

            //if the distance between the next styluspoint and the pen position is smaller than the distance between the pen and the current position
            if (distanceCurrentSP >= distanceNextSP)
            {
                SP = ExpertStroke.StylusPoints[ExpertStroke.StylusPoints.IndexOf(ExpertStylusPoint) + 1];
            }

            return(SP);
        }