コード例 #1
0
        /// <summary>
        /// 查找位于rect内部之线段,需进入直线的子线段查找
        /// </summary>
        /// <param name="rect"></param>
        /// <returns></returns>
        public List <PartitionLine> FindInRectLine(Rectangle rect)
        {
            List <PartitionLine> inRectLines = new List <PartitionLine>();
            List <PartitionLine> CutedLines;
            List <PartitionLine> CutedChildLines;

            FindLineByRect findByRect = new FindLineByRect(rect);

            CutedLines = HPartionLines.FindAll(findByRect.PredicateCutedRect);
            CutedLines.AddRange(VPartionLines.FindAll(findByRect.PredicateCutedRect));

            foreach (PartitionLine line in CutedLines)
            {
                if (line.IsInRect(rect))///line全部包含于rect内部
                {
                    inRectLines.Add(line);
                }
                else
                {
                    if (line.ChildLines != null)
                    {
                        CutedChildLines = line.ChildLines.FindAll(findByRect.PredicateInRect);
                        inRectLines.AddRange(CutedChildLines);
                    }
                }
            }
            return(inRectLines);
        }
コード例 #2
0
 /// <summary>
 /// 删除直线,不做其他动作,只是在数组中删除数据
 /// </summary>
 /// <param name="line"></param>
 internal void RemoveLine(PartitionLine line)
 {
     if (line.IsRow)
     {
         HPartionLines.Remove(line);
     }
     else
     {
         VPartionLines.Remove(line);
     }
 }
コード例 #3
0
 /// <summary>
 /// 添加直线,不做其他动作,只是添加数据到数组
 /// </summary>
 /// <param name="line"></param>
 public void AddLine(PartitionLine line)
 {
     if (line.IsRow)
     {
         HPartionLines.Add(line);
     }
     else
     {
         VPartionLines.Add(line);
     }
 }
コード例 #4
0
        public void AddLine(int start, int end, int position, bool isRow)
        {
            PartitionLine        line = new PartitionLine(start, end, position, isRow);
            List <PartitionLine> resultLines; ///找到与给定直线正交之分割线的结果集
            List <PartitionLine> overLapLine; ///被重叠的直线
            ///找到所有被line切割的分割线
            FindLineByLine findLinePartion = new FindLineByLine(line);

            if (line.IsRow)
            {
                resultLines = VPartionLines.FindAll(findLinePartion.PredicatePartedLine);
                if (resultLines.Count >= 1)
                {
                    ///处理被其切割了其他的直线,同时处理自己也被切割了的情形
                    for (int i = 0; i < resultLines.Count; i++)
                    {
                        resultLines[i].PartitionByLine(line);
                        line.PartitionByLine(resultLines[i]);
                    }
                }
                ///添加新绘之直线,先判断是否有重叠直线
                FindLineByLine findByLine = new FindLineByLine(line);
                overLapLine = HPartionLines.FindAll(findByLine.PredicateOverlap);
                if (overLapLine.Count == 0)
                {
                    HPartionLines.Add(line);
                }
                else if (overLapLine.Count == 1)
                {
                    overLapLine[0].MergeOverlapLine(line);
                }
                else
                {
                    PartitionLine removedLine = line.MergeOverlapLine(overLapLine[0], overLapLine[1]);
                    HPartionLines.Remove(removedLine);
                }
            }
            else
            {
                resultLines = HPartionLines.FindAll(findLinePartion.PredicatePartedLine);
                if (resultLines.Count >= 1)
                {
                    ///处理被其切割了其他的直线,同时处理自己也被切割了的情形
                    for (int i = 0; i < resultLines.Count; i++)
                    {
                        resultLines[i].PartitionByLine(line);
                        line.PartitionByLine(resultLines[i]);
                    }
                }
                ///添加新绘之直线,先判断是否有重叠直线
                FindLineByLine findByLine = new FindLineByLine(line);
                overLapLine = VPartionLines.FindAll(findByLine.PredicateOverlap);
                if (overLapLine.Count == 0)
                {
                    VPartionLines.Add(line);
                }
                else if (overLapLine.Count == 1)
                {
                    overLapLine[0].MergeOverlapLine(line);
                }
                else
                {
                    PartitionLine removedLine = line.MergeOverlapLine(overLapLine[0], overLapLine[1]);
                    VPartionLines.Remove(removedLine);
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// 删除直线
        /// </summary>
        /// <param name="line"></param>
        public void DeleteLine(PartitionLine line)
        {
            List <PartitionLine> resultLines;  ///找到与给定直线正交之分割线的结果集
            ///找到所有被line切割的分割线
            FindLineByLine findLinePartion = new FindLineByLine(line);

            if (line.IsRow)///横向直线
            {
                resultLines = VPartionLines.FindAll(findLinePartion.PredicatePartedLine);
                if (resultLines.Count >= 1)
                {
                    for (int i = 0; i < resultLines.Count; i++)
                    {
                        ///合并孩子线段
                        if (line.FatherLine == null ||
                            (line.FatherLine != null &&
                             (line.FatherLine.Start == resultLines[i].Position || line.FatherLine.End == resultLines[i].Position)
                            ))
                        {
                            resultLines[i].MergeByPos(line.Position);
                        }
                    }
                }
                ///不能简单的HPartionLines.Remove(line),此处只用的为line中的数据,而非引用.因为有可能
                ///HPartionLines.Remove(line);

                FindLineByLine findByLine  = new FindLineByLine(line);
                PartitionLine  overLapLine = HPartionLines.Find(findByLine.PredicateIncludeLine);
                if (overLapLine.Start == line.Start && overLapLine.End == line.End)///如果是同一条线
                {
                    HPartionLines.Remove(overLapLine);
                }
                else
                {
                    PartitionLine newLine = overLapLine.RemoveChildLine(line);
                    if (newLine != null)///如果产生了新的线段
                    {
                        this.HPartionLines.Add(newLine);
                    }
                    if (overLapLine.ChildLines != null && overLapLine.ChildLines.Count == 0)
                    {
                        overLapLine.ChildLines.AddFirst(
                            new LinkedListNode <PartitionLine>(
                                new PartitionLine(
                                    overLapLine.Start,
                                    overLapLine.End,
                                    overLapLine.Position,
                                    overLapLine.IsRow)));
                        //line.ChildLines = null;
                    }
                    else if (overLapLine.ChildLines == null)
                    {
                        overLapLine.ChildLines = new SDLinkedList <PartitionLine>();
                        overLapLine.ChildLines.AddFirst(
                            new LinkedListNode <PartitionLine>(
                                new PartitionLine(
                                    overLapLine.Start,
                                    overLapLine.End,
                                    overLapLine.Position,
                                    overLapLine.IsRow)));
                    }
                }
            }
            else///删除纵向切割线
            {
                resultLines = HPartionLines.FindAll(findLinePartion.PredicatePartedLine);
                if (resultLines.Count >= 1)
                {
                    for (int i = 0; i < resultLines.Count; i++)
                    {
                        if (line.FatherLine == null ||
                            (line.FatherLine != null &&
                             (line.FatherLine.Start == resultLines[i].Position || line.FatherLine.End == resultLines[i].Position)
                            ))
                        {
                            ///合并孩子线段
                            resultLines[i].MergeByPos(line.Position);
                        }
                    }
                }
                FindLineByLine findByLine  = new FindLineByLine(line);
                PartitionLine  overLapLine = VPartionLines.Find(findByLine.PredicateIncludeLine);
                if (overLapLine != null)
                {
                    if (overLapLine.Start == line.Start && overLapLine.End == line.End)///如果是同一条线
                    {
                        VPartionLines.Remove(overLapLine);
                    }
                    else
                    {
                        PartitionLine newLine = overLapLine.RemoveChildLine(line);
                        if (newLine != null)///如果产生了新的线段
                        {
                            this.VPartionLines.Add(newLine);
                        }
                        if (overLapLine.ChildLines != null && overLapLine.ChildLines.Count == 0)
                        {
                            overLapLine.ChildLines.AddFirst(
                                new LinkedListNode <PartitionLine>(
                                    new PartitionLine(
                                        overLapLine.Start,
                                        overLapLine.End,
                                        overLapLine.Position,
                                        overLapLine.IsRow)));
                            //line.ChildLines = null;
                        }
                        else if (overLapLine.ChildLines == null)
                        {
                            overLapLine.ChildLines = new SDLinkedList <PartitionLine>();
                            overLapLine.ChildLines.AddFirst(
                                new LinkedListNode <PartitionLine>(
                                    new PartitionLine(
                                        overLapLine.Start,
                                        overLapLine.End,
                                        overLapLine.Position,
                                        overLapLine.IsRow)));
                        }
                    }
                }
            }
        }