//***************************************
 //      ContinueGesture
 //
 //      use:            Update min and max x and y values for
 //                      the current gesture being recorded
 //                      and add the new point to the list.
 //                      Called while player holds input down.
 private void ContinueGesture()
 {
     currentPoint.SetX(Input.mousePosition.x - startPoint.GetX());
     currentPoint.SetY(Input.mousePosition.y - startPoint.GetY());
     currentPointList.Add(new TwoDPoint(currentPoint.GetX(), currentPoint.GetY()));
     if (currentPoint.GetX() > currentGesture.GetMaxX())
     {
         currentGesture.SetMaxX(currentPoint.GetX());
     }
     if (currentPoint.GetX() < currentGesture.GetMinX())
     {
         currentGesture.SetMinX(currentPoint.GetX());
     }
     if (currentPoint.GetY() > currentGesture.GetMaxY())
     {
         currentGesture.SetMaxY(currentPoint.GetY());
     }
     if (currentPoint.GetY() < currentGesture.GetMinY())
     {
         currentGesture.SetMinY(currentPoint.GetY());
     }
     if (limitSamples && currentPointList.Count >= maxPointsAllowed)
     {
         gestureComplete = true;
         Debug.Log(message: "Gesture Complete!");
     }
 }
    //***************************************
    //      PointDistance
    //
    //      use:        calculates the absolute value of the distance
    //                  between two points using pythagorean theorem
    private float PointDistance(TwoDPoint a, TwoDPoint b)
    {
        float xDif = a.GetX() - b.GetX();
        float yDif = a.GetY() - b.GetY();

        return(Mathf.Sqrt((xDif * xDif) + (yDif * yDif)));
    }
    //***************************************
    //      MapPoints
    //
    //      use:        maps the list of recorded points to a desired
    //                  number of points by calculating an even distance
    //                  between such a number of points and interpolating
    //                  when that distance is reached upon traversal of the
    //                  list
    //                  Called after scaling on every gesture
    //
    //      param:      gesture:    the object to store the new array
    private void MapPoints(DrawnGesture gesture)
    {
        reducedPoints[0].SetX(currentPointList[0].GetX());
        reducedPoints[0].SetY(currentPointList[0].GetY());
        int   newIndex        = 1;
        float totalDistance   = TotalDistance();
        float coveredDistance = 0;
        float thisDistance    = 0;
        float idealInterval   = totalDistance / pointsPerGesture;

        for (int i = 0; i < currentPointList.Count - 1; i++)
        {
            thisDistance = PointDistance(currentPointList[i], currentPointList[i + 1]);
            bool passedIdeal = (coveredDistance + thisDistance) >= idealInterval;
            if (passedIdeal)
            {
                TwoDPoint reference = currentPointList[i];
                while (passedIdeal && newIndex < reducedPoints.Length)
                {
                    float percentNeeded = (idealInterval - coveredDistance) / thisDistance;
                    if (percentNeeded > 1f)
                    {
                        percentNeeded = 1f;
                    }
                    if (percentNeeded < 0f)
                    {
                        percentNeeded = 0f;
                    }
                    float new_x = (((1f - percentNeeded) * reference.GetX()) + (percentNeeded * currentPointList[i + 1].GetX()));
                    float new_y = (((1f - percentNeeded) * reference.GetY()) + (percentNeeded * currentPointList[i + 1].GetY()));
                    reducedPoints[newIndex] = new TwoDPoint(new_x, new_y);
                    reference = reducedPoints[newIndex];
                    newIndex++;
                    thisDistance    = (coveredDistance + thisDistance) - idealInterval;
                    coveredDistance = 0;
                    passedIdeal     = (coveredDistance + thisDistance) >= idealInterval;
                }
                coveredDistance = thisDistance;
            }
            else
            {
                coveredDistance += thisDistance;
            }
            gesture.SetPoints(reducedPoints);
        }
    }