Exemplo n.º 1
0
 /// <summary>
 /// 如果两直线的position相同,且有相交之处,则返回真
 /// 即,是否有重叠
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public bool PredicateOverlap(PartitionLine line)
 {
     return(line.Position == Line.Position &&
            line.IsRow == Line.IsRow &&
            ((line.Start <= Line.Start && line.End >= Line.Start) ||
             (line.Start > Line.Start && Line.End >= line.Start)));
 }
Exemplo n.º 2
0
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            PartitionLine line2 = (PartitionLine)obj;

            if (this.IsRow != line2.IsRow)
            {
                return(false);
            }

            if (this.Start != line2.Start)
            {
                return(false);
            }

            if (this.End != line2.End)
            {
                return(false);
            }

            if (this.Position != line2.Position)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 查找起于或终于给定直线之直线
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public bool PredicateStartEndTo(PartitionLine line)
 {
     return(line.IsRow != Line.IsRow &&
            ((line.End == Line.Position || line.Start == Line.Position) &&
             line.Position >= Line.Start &&
             line.Position <= Line.End));
 }
Exemplo n.º 4
0
        /// <summary>
        /// 返回和给定line相等的line的引用
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public List <PartitionLine> GetLine(PartitionLine line)
        {
            List <PartitionLine> resultLines = new List <PartitionLine>();

            List <PartitionLine> allLines = new List <PartitionLine>(HPartionLines);

            allLines.AddRange(VPartionLines);

            FindLineByLine findByLine  = new FindLineByLine(line);
            PartitionLine  includeLine = allLines.Find(findByLine.PredicateIncludeLine);

            if (includeLine == null)
            {
                return(resultLines);
            }
            if (line.Start == includeLine.Start && line.End == includeLine.End)///line即为父直线
            {
                resultLines.Add(includeLine);
                return(resultLines);
            }
            if (includeLine.ChildLines != null)
            {
                List <PartitionLine> childLines =
                    includeLine.ChildLines.FindAll(findByLine.PredicateIncludedLine);
                resultLines.AddRange(childLines);
            }
            return(resultLines);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 初始化直线数据:NewLines,EndPointLines,StartPointLines
        /// </summary>
        private void InitLines()
        {
            ///是否和已有直线重合
            PartitionLine line = new PartitionLine(
                MovedLine.Start, MovedLine.End, MovedToPos, MovedLine.IsRow);
            FindLineByLine       findByLine = new FindLineByLine(line);
            List <PartitionLine> allLines   = new List <PartitionLine>(
                TDPanel.DrawPanel.ListLine.HPartionLines);

            allLines.AddRange(TDPanel.DrawPanel.ListLine.VPartionLines);

            List <PartitionLine> overLapLines = allLines.FindAll(findByLine.PredicateOverlap);
            List <PartitionLine> resultLines  = new List <PartitionLine>();

            if (overLapLines.Count > 0)
            {
                resultLines = line.GetNotOverlapLine(overLapLines);
            }
            else            ///没有重合
            {
                resultLines.Add(line);
            }
            NewLines = resultLines;

            ///初始化_endPointLines,_startPointLines
            FindLineByLine findByMovedLine = new FindLineByLine(MovedLine);

            EndPointLines   = allLines.FindAll(findByMovedLine.PredicateEndTo);
            StartPointLines = allLines.FindAll(findByMovedLine.PredicateStartFrom);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 将矩形数组转为相邻的成对存储
        /// </summary>
        /// <param name="rectList"></param>
        /// <param name="line"></param>
        /// <returns></returns>
        public List <NeighbourRect> RectListToNeighbour(List <Rect> rectList, PartitionLine line)
        {
            ///先设置所有rect为未访问
            List <NeighbourRect> neighbourRectList = new List <NeighbourRect>();

            if (line.IsRow)
            {
                rectList.Sort(new CompareRectX());
                for (int i = 0; i < rectList.Count;)
                {
                    neighbourRectList.Add(new NeighbourRect(rectList[i], rectList[i + 1]));
                    i += 2;
                }
            }
            else
            {
                rectList.Sort(new CompareRectY());
                for (int i = 0; i < rectList.Count;)
                {
                    neighbourRectList.Add(new NeighbourRect(rectList[i], rectList[i + 1]));
                    i += 2;
                }
            }
            return(neighbourRectList);
        }
Exemplo n.º 7
0
 /// <summary>
 /// 查找起始于给定直线之直线
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public bool PredicateStartFrom(PartitionLine line)
 {
     return(line.IsRow != Line.IsRow &&
            line.Start == Line.Position &&
            line.Position >= Line.Start &&
            line.Position <= Line.End);
 }
Exemplo n.º 8
0
 /// <summary>
 /// 寻找终点位于给定直线之分割线
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public bool PredicateLineTo(PartitionLine line)
 {
     return(line.Position == Line.End &&
            line.Start < Line.Position &&
            line.End > Line.Position &&
            line.IsRow != Line.IsRow);
 }
Exemplo n.º 9
0
 /// <summary>
 /// 根据直线,得到矩形之边界.
 /// 默认line过了this之某边界
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public PartitionLine GetBorderline(PartitionLine line)
 {
     if (line.IsRow)
     {
         if (line.Position == this.Y)
         {
             return(new PartitionLine(X, X + Width, Y, true));
         }
         else if (line.Position == Y + Height)
         {
             return(new PartitionLine(X, X + Width, Y + Height, true));
         }
         else
         {
             return(null);
         }
     }
     else
     {
         if (line.Position == this.X)
         {
             return(new PartitionLine(Y, Y + Height, X, false));
         }
         else if (line.Position == X + Width)
         {
             return(new PartitionLine(Y, Y + Height, X + Width, false));
         }
         else
         {
             return(null);
         }
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// 得到已知直线能移动的边界直线
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        internal PartitionLine[] GetLineBorderLine(PartitionLine line)
        {
            PartitionLine[]      borderLines = new PartitionLine[2];
            List <PartitionLine> allLines    = new List <PartitionLine>(HPartionLines);

            allLines.AddRange(VPartionLines);

            FindLineByLine       findByLine  = new FindLineByLine(line);
            List <PartitionLine> resultLines = allLines.FindAll(findByLine.PredicateParallelLine);

            resultLines.Sort(new CompareLLDistance(line));
            int i = 1;

            for (; i < resultLines.Count; i++)
            {
                if ((resultLines[0].Position <line.Position && resultLines[i].Position> line.Position) ||
                    (resultLines[0].Position > line.Position && resultLines[i].Position < line.Position))
                {
                    break;
                }
            }
            ///左或上的直线放在前面返回
            if (resultLines[0].Position < resultLines[i].Position)
            {
                borderLines[0] = resultLines[0];
                borderLines[1] = resultLines[i];
            }
            else
            {
                borderLines[0] = resultLines[i];
                borderLines[1] = resultLines[0];
            }
            return(borderLines);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 拷贝构造函数
        /// </summary>
        public PartitionLine(PartitionLine line)
        {
            if (line == null)
            {
                return;
            }

            IsSelected = line.IsSelected;
            IsLocked   = line.IsLocked;

            Start    = line.Start;
            End      = line.End;
            Position = line.Position;
            IsRow    = line.IsRow;
            if (line.ChildLines != null)///拷贝孩子
            {
                ChildLines = new SDLinkedList <PartitionLine>();
                foreach (PartitionLine childLine in line.ChildLines)
                {
                    ChildLines.AddLast(new PartitionLine(childLine));
                }
            }
            if (line.FatherLine != null)
            {
                FatherLine = line.FatherLine;
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// 查找和已知直线平行且有"重合"之直线
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public bool PredicateParallelLine(PartitionLine line)
 {
     return(line.IsRow == Line.IsRow &&
            line.Position != Line.Position &&
            !(line.Start >= Line.End ||
              line.End <= Line.Start
              ));
 }
Exemplo n.º 13
0
 /// <summary>
 /// 查找被给定直线包含之直线
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public bool PredicateIncludedLine(PartitionLine line)
 {
     return
         (line.IsRow == Line.IsRow &&
          line.Position == Line.Position &&
          line.Start >= Line.Start &&
          line.End <= Line.End);
 }
Exemplo n.º 14
0
 /// <summary>
 /// 父直线被给定直线切割
 /// </summary>
 /// <param name="line">给定直线</param>
 public void PartitionByLine(PartitionLine line)
 {
     if (this.IsRow == line.IsRow || this.Start >= line.Position || this.End <= line.Position)
     {
         return;                                                                                      ///两条线并向或并未相交
     }
     PartitionByPos(line.Position);
 }
Exemplo n.º 15
0
 /// <summary>
 /// 查找相交成首尾相交相连之直线
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public bool PredicateJoined(PartitionLine line)
 {
     return(line.IsRow != Line.IsRow &&
            ((line.End == Line.Position || line.Start == Line.Position) &&
             (line.Position == Line.Start || line.Position == Line.End)));
     //((line.End == Line.Position && (line.Position == Line.Start || line.Position == Line.End)) ||
     //(line.Start == Line.Position && (line.Position == Line.Start || line.Position == Line.End)));
 }
Exemplo n.º 16
0
 /// <summary>
 /// 查找能与给定直线正交之分割线:line被Line分割
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public bool PredicatePartedLine(PartitionLine line)
 {
     return(line.Start < Line.Position &&
            line.End > Line.Position &&
            line.Position >= Line.Start &&
            line.Position <= Line.End &&
            line.IsRow != Line.IsRow);
 }
Exemplo n.º 17
0
        /// <summary>
        /// 取消选择直线
        /// </summary>
        /// <param name="line"></param>
        internal void UnSelectLine(PartitionLine line)
        {
            List <PartitionLine> selectedLines = this.GetLine(line);

            foreach (PartitionLine selectedLine in selectedLines)
            {
                selectedLine.UnSelectLine();
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// 得到矩形的边界线
 /// </summary>
 /// <param name="rect"></param>
 /// <returns></returns>
 public static PartitionLine[] GetRectBorderLines(Rectangle rect)
 {
     PartitionLine[] borderLines = new PartitionLine[4];
     borderLines[0] = new PartitionLine(rect.X, rect.X + rect.Width, rect.Y, true);
     borderLines[1] = new PartitionLine(rect.X, rect.X + rect.Width, rect.Y + rect.Height, true);
     borderLines[2] = new PartitionLine(rect.Y, rect.Y + rect.Height, rect.X, false);
     borderLines[3] = new PartitionLine(rect.Y, rect.Y + rect.Height, rect.X + rect.Width, false);
     return(borderLines);
 }
Exemplo n.º 19
0
        /// <summary>
        /// 根据父直线来构造子线段
        /// </summary>
        public PartitionLine(int start, int end, PartitionLine fatherLine)
        {
            Start    = start;
            End      = end;
            Position = fatherLine.Position;
            IsRow    = fatherLine.IsRow;

            FatherLine = fatherLine;
            ChildLines = null;
        }
Exemplo n.º 20
0
        /// <summary>
        /// 得到矩形的边界线
        /// </summary>
        /// <param name="pt1"></param>
        /// <param name="pt2"></param>
        /// <returns></returns>
        public static PartitionLine[] GetRectBorderLines(Point pt1, Point pt2)
        {
            PartitionLine[] borderLines = new PartitionLine[4];
            Rectangle       rect        = CommonFuns.PointToRectangle(pt1, pt2);

            borderLines[0] = new PartitionLine(rect.X, rect.X + rect.Width, rect.Y, true);
            borderLines[1] = new PartitionLine(rect.X, rect.X + rect.Width, rect.Y + rect.Height, true);
            borderLines[2] = new PartitionLine(rect.Y, rect.Y + rect.Height, rect.X, false);
            borderLines[3] = new PartitionLine(rect.Y, rect.Y + rect.Height, rect.X + rect.Width, false);
            return(borderLines);
        }
Exemplo n.º 21
0
 /// <summary>
 /// 添加直线,不做其他动作,只是添加数据到数组
 /// </summary>
 /// <param name="line"></param>
 public void AddLine(PartitionLine line)
 {
     if (line.IsRow)
     {
         HPartionLines.Add(line);
     }
     else
     {
         VPartionLines.Add(line);
     }
 }
Exemplo n.º 22
0
 /// <summary>
 /// 删除直线,不做其他动作,只是在数组中删除数据
 /// </summary>
 /// <param name="line"></param>
 internal void RemoveLine(PartitionLine line)
 {
     if (line.IsRow)
     {
         HPartionLines.Remove(line);
     }
     else
     {
         VPartionLines.Remove(line);
     }
 }
Exemplo n.º 23
0
 /// <summary>
 /// 寻找使得给定点在其start和end之间之分割线
 /// 寻找终点位于给定直线之分割线
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public bool PredicatePointTo(PartitionLine line)
 {
     if (line.IsRow)
     {
         return(line.Start <= Point.X &&
                line.End >= Point.X);
     }
     else
     {
         return(line.Start <= Point.Y &&
                line.End >= Point.Y);
     }
 }
Exemplo n.º 24
0
        public AddLineCommand(DesignPanel tdPanel, PartitionLine addedLine)
        {
            Init();
            AddedLines.Add(addedLine);

            Start    = addedLine.Start;
            End      = addedLine.End;
            Position = addedLine.Position;
            IsRow    = addedLine.IsRow;

            TDPanel          = tdPanel;
            TDPanel.Modified = true;
            CommandInfo      = "插入直线";
        }
Exemplo n.º 25
0
        /// <summary>
        /// 删除直线中的一个结点,可能会导致直线合并
        /// </summary>
        /// <param name="point"></param>
        /// <param name="p"></param>
        internal void DeletePoint(Point point, bool p)
        {
            List <PartitionLine> allLines = new List <PartitionLine>(HPartionLines);

            allLines.AddRange(VPartionLines);

            FindLineByPoint findByPoint = new FindLineByPoint(point);
            PartitionLine   resultLine  = allLines.Find(findByPoint.PredicatePointIn);

            if (resultLine != null)
            {
                resultLine.MergeByPoint(point);
            }
        }
Exemplo n.º 26
0
        public DeleteLineCommand(DesignPanel tdPanel, PartitionLine line, List <Rect> addedRects, List <Rect> removedRects)
        {
            Start    = line.Start;
            End      = line.End;
            Position = line.Position;
            IsRow    = line.IsRow;


            AddedRects   = addedRects;
            RemovedRects = removedRects;

            TDPanel          = tdPanel;
            TDPanel.Modified = true;
            CommandInfo      = "删除直线";
        }
Exemplo n.º 27
0
 /// <summary>
 /// 给定点在其上之直线
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public bool PredicatePointIn(PartitionLine line)
 {
     if (line.IsRow)
     {
         return(line.Position == Point.Y &&
                line.Start < Point.X &&
                line.End > Point.X);
     }
     else
     {
         return(line.Position == Point.X &&
                line.Start < Point.Y &&
                line.End > Point.Y);
     }
 }
Exemplo n.º 28
0
 /// <summary>
 /// 是否在rect内部
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public bool PredicateInRect(PartitionLine line)
 {
     if (line.IsRow)//是横向切割
     {
         return(line.Start >= Rect.X &&
                line.End <= Rect.X + Rect.Width &&
                line.Position > Rect.Y &&
                line.Position < Rect.Y + Rect.Height);
     }
     else
     {
         return(line.Start >= Rect.Y &&
                line.End <= Rect.Y + Rect.Height &&
                line.Position > Rect.X &&
                line.Position < Rect.X + Rect.Width);
     }
 }
Exemplo n.º 29
0
 //查找包含line的切割线
 public bool Predicate(PartitionLine line)
 {
     if (IsRow == true)//是横向切割
     {
         return(line.IsRow == IsRow &&
                line.Start <= Rect.X &&
                line.End >= Rect.X + Rect.Width &&
                line.Position >= Rect.Y &&
                line.Position <= Rect.Y + Rect.Height);
     }
     else
     {
         return(line.IsRow == IsRow &&
                line.Start <= Rect.Y &&
                line.End >= Rect.Y + Rect.Height &&
                line.Position >= Rect.X &&
                line.Position <= Rect.X + Rect.Width);
     }
 }
Exemplo n.º 30
0
        /// <summary>
        /// 根据位置来分割线段
        /// </summary>
        /// <param name="position"></param>
        public void PartitionByPos(int position)
        {
            Point point;

            if (IsRow)
            {
                point = new Point(position, Position);
            }
            else
            {
                point = new Point(Position, position);
            }
            ///如果没有孩子线段
            if (this.ChildLines == null)
            {
                ChildLines = new SDLinkedList <PartitionLine>();
                PartitionLine preLine = new PartitionLine(this.Start, position, this.Position, this.IsRow);
                PartitionLine aftLine = new PartitionLine(position, this.End, this.Position, this.IsRow);
                preLine.FatherLine = this;
                aftLine.FatherLine = this;
                ChildLines.AddFirst(preLine);
                ChildLines.AddLast(aftLine);
            }
            else
            {
                ///找到被切割的线段
                FindLineByPoint findByPoint = new FindLineByPoint(point);
                LinkedListNode <PartitionLine> resultNode = ChildLines.Find(findByPoint.PredicatePointIn);

                ///在被切割的线段前后添加一线段,同时删除原线段
                if (resultNode != null)
                {
                    PartitionLine preLine = new PartitionLine(resultNode.Value.Start, position, resultNode.Value.Position, this.IsRow);
                    PartitionLine aftLine = new PartitionLine(position, resultNode.Value.End, resultNode.Value.Position, this.IsRow);
                    preLine.FatherLine = this;
                    aftLine.FatherLine = this;
                    ChildLines.AddBefore(resultNode, preLine);
                    ChildLines.AddAfter(resultNode, aftLine);
                    ChildLines.Remove(resultNode);
                }
            }
        }