Пример #1
0
        float StrokeCost(int strokeIndex, out StrokeMatch bestMatch)
        {
            StrokeTemplate     template         = Template[strokeIndex];
            List <StrokeMatch> candidateMatches = InputMatches[strokeIndex];
            float bestCost = float.PositiveInfinity;

            bestMatch = null;
            foreach (StrokeMatch match in candidateMatches)
            {
                if (match.Parts.Count != template.Parts.Count)
                {
                    continue;
                }
                float cost = 0;
                for (int partIndex = 0; partIndex < match.Parts.Count; partIndex++)
                {
                    StrokePartMatch    partMatch    = match.Parts[partIndex];
                    StrokePartTemplate partTemplate = template.Parts[partIndex];
                    cost += partTemplate.MatchCost(partMatch);
                }
                cost += match.Cost * 30;
                if (cost < bestCost)
                {
                    bestCost  = cost;
                    bestMatch = match;
                }
            }
            return(bestCost);
        }
Пример #2
0
 float StrokeCost(int strokeIndex, out StrokeMatch bestMatch)
 {
     StrokeTemplate template = Template[strokeIndex];
     List<StrokeMatch> candidateMatches = InputMatches[strokeIndex];
     float bestCost = float.PositiveInfinity;
     bestMatch = null;
     foreach (StrokeMatch match in candidateMatches)
     {
         if (match.Parts.Count != template.Parts.Count)
             continue;
         float cost = 0;
         for (int partIndex = 0; partIndex < match.Parts.Count; partIndex++)
         {
             StrokePartMatch partMatch = match.Parts[partIndex];
             StrokePartTemplate partTemplate = template.Parts[partIndex];
             cost += partTemplate.MatchCost(partMatch);
         }
         cost += match.Cost * 30;
         if (cost < bestCost)
         {
             bestCost = cost;
             bestMatch = match;
         }
     }
     return bestCost;
 }
        private IEnumerable <StrokeMatch> Match()
        {
            if (Input.Count < 2)
            {
                yield break;
            }
            var singleMatch = new List <StrokePartMatch>();

            singleMatch.Add(MatchLine(0, Input.Count - 1));
            yield return(new StrokeMatch(singleMatch));

            foreach (int i in InterestingPoints)
            {
                StrokePartMatch match1 = MatchLine(0, i);
                StrokePartMatch match2 = MatchLine(i, Input.Count - 1);
                var             match  = new List <StrokePartMatch>();
                match.Add(match1);
                match.Add(match2);
                StrokeMatch fullMatch = new StrokeMatch(match);
                yield return(fullMatch);
            }
            foreach (int i in InterestingPoints)
            {
                foreach (int j in InterestingPoints)
                {
                    if (i >= j)
                    {
                        continue;
                    }
                    StrokePartMatch match1 = MatchLine(0, i);
                    StrokePartMatch match2 = MatchLine(i, j);
                    StrokePartMatch match3 = MatchLine(j, Input.Count - 1);
                    var             match  = new List <StrokePartMatch>();
                    match.Add(match1);
                    match.Add(match2);
                    match.Add(match3);
                    StrokeMatch fullMatch = new StrokeMatch(match);
                    yield return(fullMatch);
                }
            }
        }
        private IEnumerable<StrokeMatch> Match()
        {
            if (Input.Count < 2)
                yield break;
            var singleMatch = new List<StrokePartMatch>();
            singleMatch.Add(MatchLine(0, Input.Count - 1));
            yield return new StrokeMatch(singleMatch);

            foreach (int i in InterestingPoints)
            {
                StrokePartMatch match1 = MatchLine(0, i);
                StrokePartMatch match2 = MatchLine(i, Input.Count - 1);
                var match = new List<StrokePartMatch>();
                match.Add(match1);
                match.Add(match2);
                StrokeMatch fullMatch = new StrokeMatch(match);
                yield return fullMatch;
            }
            foreach (int i in InterestingPoints)
                foreach (int j in InterestingPoints)
                {
                    if (i >= j)
                        continue;
                    StrokePartMatch match1 = MatchLine(0, i);
                    StrokePartMatch match2 = MatchLine(i, j);
                    StrokePartMatch match3 = MatchLine(j, Input.Count - 1);
                    var match = new List<StrokePartMatch>();
                    match.Add(match1);
                    match.Add(match2);
                    match.Add(match3);
                    StrokeMatch fullMatch = new StrokeMatch(match);
                    yield return fullMatch;
                }
        }