Пример #1
0
        float CalculateTemplateDistance(IList <GestureStroke> strokes, GestureTemplate templateToMatch)
        {
            var distance = 0.0f;

            for (var i = 0; i < strokes.Count; i++)
            {
                var stroke        = strokes[i];
                var strokeToMatch = templateToMatch.Strokes[i];

                if (strokeToMatch.IsDot != stroke.IsDot)
                {
                    return(Mathf.Infinity);
                }

                if (strokeToMatch.IsDot && stroke.IsDot)
                {
                    distance += Vector2.Distance(strokeToMatch.DotPosition, stroke.DotPosition) * dotDistancePenalty;
                }
                else
                {
                    if (stroke.Points.Count != strokeToMatch.Points.Count)
                    {
                        Debug.LogError("Difference in list length when calculating distance is not supported");
                        return(Mathf.Infinity);
                    }
                    var tempdistance = 0.0f;
                    for (var j = 0; j < stroke.Points.Count; j++)
                    {
                        var strokePoint     = stroke.Points[j];
                        var pointToMatch    = strokeToMatch.Points[j];
                        var penaltyModifier = templateToMatch.PenaltyModifier(strokePoint, pointToMatch);
                        tempdistance += Vector2.Distance(strokePoint, pointToMatch) * penaltyModifier;
                    }

                    distance += (tempdistance / stroke.Points.Count);
                }
            }

            return(distance);
        }