Ejemplo n.º 1
0
        /// <summary>
        /// The HLines from this edge, with the HLines at the beginning and end of the newLine split into two.
        /// The dictionary's key is the left edge of each HLine.
        /// </summary>
        private Dictionary <double, HLine> SplitEdge(HLine newLine, double leftY, double rightY)
        {
            M.Assert(Lines.Count > 0);

            Dictionary <double, HLine> splitEdge = new Dictionary <double, HLine>();

            foreach (HLine hline in Lines)
            {
                if (hline.Left < newLine.Left && hline.Right > newLine.Left && leftY > newLine.Y)
                {
                    Dictionary <double, HLine> splitLines1 = hline.Split(newLine.Left);
                    Dictionary <double, HLine> splitLines2 = new Dictionary <double, HLine>();
                    foreach (double x in splitLines1.Keys)
                    {
                        HLine line = splitLines1[x];
                        if (line.Left < newLine.Right && line.Right > newLine.Right && line.Y > newLine.Y)
                        {
                            splitLines2 = line.Split(newLine.Right);
                        }
                    }
                    foreach (double x in splitLines1.Keys)
                    {
                        if (!splitLines2.ContainsKey(x))
                        {
                            splitEdge.Add(splitLines1[x].Left, splitLines1[x]);
                        }
                    }

                    foreach (double x in splitLines2.Keys)
                    {
                        splitEdge.Add(splitLines2[x].Left, splitLines2[x]);
                    }
                }
                else if (hline.Left < newLine.Right && hline.Right > newLine.Right && rightY > newLine.Y)
                {
                    Dictionary <double, HLine> splitLines = hline.Split(newLine.Right);
                    foreach (double x in splitLines.Keys)
                    {
                        splitEdge.Add(splitLines[x].Left, splitLines[x]);
                    }
                }
                else
                {
                    splitEdge.Add(hline.Left, hline);
                }
            }

            return(splitEdge);
        }
Ejemplo n.º 2
0
        public void AddLineToUpperEdge(HLine newLine)
        {
            M.Assert(newLine.Y != double.MaxValue);
            if (Lines.Count == 0)
            {
                Lines.Add(newLine);
            }
            else
            {
                double leftY  = this.YatX(newLine.Left);
                double rightY = this.YatX(newLine.Right);
                Dictionary <double, HLine> splitEdge    = SplitEdge(newLine, leftY, rightY);
                List <double> splitXsOnNewLine          = SplitXsOnNewLine(newLine);
                Dictionary <double, HLine> splitNewLine = newLine.Split(splitXsOnNewLine); // if

                List <HLine> newLines = new List <HLine>();
                double       currentX = splitEdge[0].Left;
                foreach (double x in splitEdge.Keys)
                {
                    if (splitNewLine.ContainsKey(x))
                    {
                        if (newLine.Y < splitEdge[x].Y)
                        {
                            newLines.Add(splitNewLine[x]);
                            currentX = splitNewLine[x].Right;
                        }
                        else
                        {
                            newLines.Add(splitEdge[x]);
                            currentX = splitEdge[x].Right;
                        }
                    }
                    else if (splitEdge[x].Left == currentX)
                    {
                        newLines.Add(splitEdge[x]);
                        currentX = splitEdge[x].Right;
                    }
                }

                for (int i = 1; i < newLines.Count; ++i)
                {
                    M.Assert(newLines[i - 1].Right == newLines[i].Left);
                }

                Lines = null;
                Lines = newLines;
            }
        }
Ejemplo n.º 3
0
        public void AddLineToUpperEdge(HLine newLine)
        {
            Debug.Assert(newLine.Y != float.MaxValue);
            if(Lines.Count == 0)
            {
                Lines.Add(newLine);
            }
            else
            {
                float leftY = this.YatX(newLine.Left);
                float rightY = this.YatX(newLine.Right);
                Dictionary<float, HLine> splitEdge = SplitEdge(newLine, leftY, rightY);
                List<float> splitXsOnNewLine = SplitXsOnNewLine(newLine);
                Dictionary<float, HLine> splitNewLine = newLine.Split(splitXsOnNewLine); // if

                List<HLine> newLines = new List<HLine>();
                float currentX = splitEdge[0].Left;
                foreach(float x in splitEdge.Keys)
                {
                    if(splitNewLine.ContainsKey(x))
                    {
                        if(newLine.Y < splitEdge[x].Y)
                        {
                            newLines.Add(splitNewLine[x]);
                            currentX = splitNewLine[x].Right;
                        }
                        else
                        {
                            newLines.Add(splitEdge[x]);
                            currentX = splitEdge[x].Right;
                        }
                    }
                    else if(splitEdge[x].Left == currentX)
                    {
                        newLines.Add(splitEdge[x]);
                        currentX = splitEdge[x].Right;
                    }
                }

                for(int i = 1; i < newLines.Count; ++i)
                {
                    Debug.Assert(newLines[i - 1].Right == newLines[i].Left);
                }

                Lines = null;
                Lines = newLines;
            }
        }