Exemplo n.º 1
0
        public void AddLetter(Letter l1)
        {
            if (l1 == null)
            {
                return;
            }
            int index = WhatLine(l1);

            if (index == -1)
            {
                Line newLine = new Line();
                newLine.AddLetter(l1);

                lines.Add(newLine);
            }
            else
            {
                Letter l2 = lines[index].Last;

                //DA RIVEDERE
                if (l1.xMax - l1.xMin < l2.xMax - l2.xMin)
                {
                    l1.xMin--;
                    l1.xMax++;
                }
                else
                {
                    l2.xMin--;
                    l2.xMax++;
                }
                //----------

                int distance = (l1.xMax - l2.xMin) / 2;
                if (distance > Settings.charDistance)
                {
                    lines[index].AddLetter(l1);
                    return;
                }

                int min = l1.xMin > l2.xMin ? l1.xMin : l2.xMin;
                int max = l1.xMax < l2.xMax ? l1.xMax : l2.xMax;

                max -= min;

                min = Math.Min(l1.xMax - l1.xMin, l2.xMax - l2.xMin);
                if (max > min / 3)
                {
                    foreach (Coord c in l1.pixels)
                    {
                        l2.AddPixel(c);
                    }
                    foreach (Coord c in l1.outlinePixels)
                    {
                        l2.outlinePixels.Add(c);
                    }
                    lines[index].Update(l2);
                }
                else
                {
                    lines[index].AddLetter(l1);
                }
            }
        }