Esempio n. 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);
        }
Esempio n. 2
0
        public static StrokeTemplate Parse(string s)
        {
            string[] strParts = s.Split('>');
            if (strParts.Length % 2 == 0)
            {
                throw new ArgumentException("Invalid Stroke " + s);
            }
            List <StrokePartTemplate> parts = new List <StrokePartTemplate>();

            for (int i = 0; i < strParts.Length / 2; i++)
            {
                string             strStart = strParts[2 * i];
                string             strCurve = strParts[2 * i + 1];
                string             strEnd   = strParts[2 * i + 2];
                float              curve    = strCurve == "" ? 0 : float.Parse(strCurve, CultureInfo.InvariantCulture);
                Vector2f           start    = ParseVector(strStart) / 100;
                Vector2f           end      = ParseVector(strEnd) / 100;
                StrokePartTemplate part     = new StrokePartTemplate(start, end, curve);
                parts.Add(part);
            }
            return(new StrokeTemplate(parts));
        }
 public static StrokeTemplate Parse(string s)
 {
     string[] strParts = s.Split('>');
     if (strParts.Length % 2 == 0)
         throw new ArgumentException("Invalid Stroke " + s);
     List<StrokePartTemplate> parts = new List<StrokePartTemplate>();
     for (int i = 0; i < strParts.Length / 2; i++)
     {
         string strStart = strParts[2 * i];
         string strCurve = strParts[2 * i + 1];
         string strEnd = strParts[2 * i + 2];
         float curve = strCurve == "" ? 0 : float.Parse(strCurve, CultureInfo.InvariantCulture);
         Vector2f start = ParseVector(strStart) / 100;
         Vector2f end = ParseVector(strEnd) / 100;
         StrokePartTemplate part = new StrokePartTemplate(start, end, curve);
         parts.Add(part);
     }
     return new StrokeTemplate(parts);
 }