Exemplo n.º 1
0
        public static void Add(this List <ConnectionNode> connectionNodes, Vertex vertex)
        {
            var connectionNode = connectionNodes.FindConnectionNode(vertex);

            if (connectionNode == null)
            {
                connectionNode = new ConnectionNode();
                connectionNodes.Add(connectionNode);
            }
            connectionNode.Add(vertex);
        }
Exemplo n.º 2
0
        private static Dictionary <Stroke, Stroke> MergingAtNode(ConnectionNode conenctionNode, List <Stroke> outStrokes, double widthOfPen)
        {
            var res = new Dictionary <Stroke, Stroke>();
            int n   = outStrokes.Count;

            double[,] angles = new double[n, n];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    angles[i, j] = CalcDiffAngle(outStrokes[i], outStrokes[j], widthOfPen);
                }
            }
            bool[] hasAPair = new bool[n];
            double maxAngle = Math.PI;

            while (maxAngle > minSmooth)
            {
                maxAngle = 0.0;
                int maxi = -1;
                int maxj = -1;
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        if (!hasAPair[i] && !hasAPair[j] && angles[i, j] > maxAngle)
                        {
                            maxi = i; maxj = j; maxAngle = angles[i, j];
                        }
                    }
                }

                if (maxAngle > minSmooth)
                {
                    hasAPair[maxi] = true;
                    hasAPair[maxj] = true;
                    res.TryAdd(outStrokes[maxi].Sibling, outStrokes[maxj]);
                    res.TryAdd(outStrokes[maxj].Sibling, outStrokes[maxi]);
                }
            }
            return(res);
        }