//***************************************
    //      AverageDistanceWithAnomalies
    //
    //      use:        calculates the average difference between
    //                  the points of two gestures but weighing
    //                  those which deviate significantly by
    //                  multiplying them
    //                  Both the tightness of this and the factor
    //                  of multiplication are customizable
    //                  above
    //
    //      param:      playerGesture:  first to be compared
    //                  template:       gesture to be compared against
    //
    //      return:     returns float value of the average distance
    //                  between points of two parameter gestures
    //                  with weights
    private float AverageDifferenceWithAnomalies(DrawnGesture playerGesture, DrawnGesture template)
    {
        int numPoints = playerGesture.GetNumPoints();

        if (numPoints != template.GetNumPoints())
        {
            Debug.Log("Number of points differs from templates");
            return(-1f);
        }

        float totalDifference = 0;

        float[] sampleDifferences = new float[numPoints];
        float[] sampleDeviations  = new float[numPoints];
        float   standardDev       = 0;

        for (int i = 0; i < numPoints; i++)
        {
            float thisDistance = PointDistance(playerGesture.GetPoints()[i], template.GetPoints()[i]);
            sampleDifferences[i] = thisDistance;
            totalDifference     += thisDistance;
        }

        float average = totalDifference / numPoints;

        for (int i = 0; i < numPoints; i++)
        {
            sampleDeviations[i] = Math.Abs(sampleDifferences[i] - average);
            standardDev        += sampleDifferences[i];
        }

        standardDev = standardDev / numPoints;

        for (int i = 0; i < numPoints; i++)
        {
            if (Math.Abs(sampleDeviations[i]) > devTightness * standardDev)
            {
                totalDifference -= sampleDifferences[i];
                totalDifference += anomaliesFactor * sampleDifferences[i];
            }
        }

        average = totalDifference / numPoints;

        return(average);
    }
    //***************************************
    //      AverageDifference
    //
    //      use:        caluclates the average distance between
    //                  the points of two gestures
    //
    //      param:      playerGesture:  first to be compared
    //                  template:       gesture to be compared against
    //
    //      return:     returns float value of the average distance
    //                  between points of two parameter gestures
    private float AverageDifference(DrawnGesture playerGesture, DrawnGesture template)
    {
        int numPoints = playerGesture.GetNumPoints();

        if (numPoints != template.GetNumPoints())
        {
            Debug.Log("Number of points differs from templates");
            return(-1f);
        }

        float totalDifference = 0;

        for (int i = 0; i < numPoints; i++)
        {
            totalDifference += PointDistance(playerGesture.GetPoints()[i], template.GetPoints()[i]);
        }

        return(totalDifference / numPoints);
    }