예제 #1
0
        private void DoSomething(ref _Room room, List <_Line> overlappedlistinroom)
        {
            List <_Point> thesepointsexist = new List <_Point>();

            foreach (_Line line in overlappedlistinroom)
            {
                if (!thesepointsexist.Contains(line.StartPoint))
                {
                    thesepointsexist.Add(line.StartPoint);
                }
                if (!thesepointsexist.Contains(line.EndPoint))
                {
                    thesepointsexist.Add(line.EndPoint);
                }
            }
            thesepointsexist = thesepointsexist.OrderBy(i => i.X).OrderBy(i => i.Y).ToList();
            List <_Line> newLines = new List <_Line>();

            for (var index = 0; index < thesepointsexist.Count - 1; index += 1)
            {
                _Point p0 = thesepointsexist[index];
                _Point p1 = thesepointsexist[index + 1];
                newLines.Add(new _Line(p0, p1));
            }

            _Line l = overlappedlistinroom.Last();

            foreach (_Line newLine in newLines)
            {
                newLine.relatedrooms = l.relatedrooms;
            }

            room.Lines.RemoveAll(i => overlappedlistinroom.Contains(i));
            room.Lines.AddRange(newLines);
        }
예제 #2
0
 public static void ChangeAllParams(ref _Room keep, _Room getDataFrom)
 {
     keep.Number = getDataFrom.Number;
     keep.Name   = getDataFrom.Name;
     keep.type   = getDataFrom.type;
     keep.Guid   = getDataFrom.Guid;
 }
예제 #3
0
        public _Model DeepCopy(_Room oldMyRoom1, out _Room newMyRoom1)
        {
            _Model copy = this.DeepCopy(true);

            newMyRoom1 = oldNewRooms[oldMyRoom1];
            return(copy);
        }
예제 #4
0
        public void SwitchRooms(ref _Room room1, ref _Room room2)
        {
            _Room temp1 = room1.DeepCopy();
            _Room temp2 = room2.DeepCopy();

            _Room.ChangeAllParams(ref room1, temp2);
            _Room.ChangeAllParams(ref room2, temp1);
        }
예제 #5
0
        private void TryToRemoveRemainderLines(_Room room, _Line l1, _Line l2)
        {
            bool isComplete;

            try
            {
                if (room.Lines.Contains(l1))
                {
                    room.Lines.Remove(l1);
                    isComplete = room.CanGetBoundarySorted();
                    if (!isComplete)
                    {
                        room.Lines.Add(l1);
                    }
                }
            }
            catch (Exception e)
            {
            }
            try
            {
                if (room.Lines.Contains(l2))
                {
                    room.Lines.Remove(l2);
                    isComplete = room.CanGetBoundarySorted();
                    if (!isComplete)
                    {
                        room.Lines.Add(l2);
                    }
                }
            }
            catch (Exception e)
            {
            }

            try
            {
                if (room.Lines.Contains(l1) && room.Lines.Contains(l2))
                {
                    room.Lines.Remove(l1);
                    room.Lines.Remove(l2);
                    isComplete = room.CanGetBoundarySorted();
                    if (!isComplete)
                    {
                        room.Lines.Add(l1);
                    }
                    if (!isComplete)
                    {
                        room.Lines.Add(l2);
                    }
                }
            }
            catch (Exception e)
            {
            }
        }
예제 #6
0
        private void TryToDivideRoomLinesWithL1L2(_Room room, _Line l1, _Line l2)
        {
            bool isComplete = room.CanGetBoundarySorted(); //this might be bad

            if (!isComplete)
            {
                for (int i = 0; i < room.Lines.Count; i++)
                {
                    _Line chosenLine = room.Lines.ElementAt(i);

                    if (chosenLine.Equals(l1) || chosenLine.Equals(l2))
                    {
                        continue;
                    }

                    var connectsPoint = chosenLine.ConnectsPoint(l1);
                    if (connectsPoint != null)
                    {
                        _Point otherPoint = l1.EndPoint.Equals(connectsPoint) ? l1.StartPoint : l1.EndPoint;
                        if (IsOnLine(otherPoint, chosenLine))
                        {
                            if (chosenLine.EndPoint.Equals(connectsPoint))
                            {
                                chosenLine.EndPoint = otherPoint;
                            }
                            else
                            {
                                chosenLine.StartPoint = otherPoint;
                            }
                        }
                    }

                    connectsPoint = chosenLine.ConnectsPoint(l2);
                    if (connectsPoint != null)
                    {
                        _Point otherPoint = l2.EndPoint.Equals(connectsPoint) ? l2.StartPoint : l2.EndPoint;
                        if (IsOnLine(otherPoint, chosenLine))
                        {
                            if (chosenLine.EndPoint.Equals(connectsPoint))
                            {
                                chosenLine.EndPoint = otherPoint;
                            }
                            else
                            {
                                chosenLine.StartPoint = otherPoint;
                            }
                        }
                    }
                }
            }
            isComplete = room.CanGetBoundarySorted(); //we need to check it after the split
        }
예제 #7
0
        public _Model DeepCopy(bool isTagNeeded = false)
        {
            if (isTagNeeded)
            {
                oldNewLines.Clear();
                oldNewPoints.Clear();
                oldNewRooms.Clear();
            }
            List <_Room> newRooms = new List <_Room>();

            foreach (_Room room in rooms)
            {
                _Room deepCopy = room.DeepCopy();

                if (isTagNeeded)
                {
                    bool isroomthere = oldNewRooms.ContainsKey(deepCopy);
                    if (!isroomthere)
                    {
                        oldNewRooms.Add(room, deepCopy);
                    }

                    for (var index = 0; index < room.Lines.Count; index++)
                    {
                        _Line i     = room.Lines[index];
                        _Line iCopy = deepCopy.Lines[index];
                        bool  ifs   = oldNewLines.ContainsKey(i);
                        if (!ifs)
                        {
                            oldNewLines.Add(i, iCopy);
                        }
                    }
                }

                //this storage type is duplicate this way
                newRooms.Add(deepCopy);
            }

            _Model m = new _Model(newRooms);

            //RemoveRedundancy(m);
            m.OutlinePolygonPoints    = OutlinePolygonPoints;
            m.AvailableOutlinePolygon = AvailableOutlinePolygon;
            m.AdjacencyMatrix         = AdjacencyMatrix;
            m.TransparencyMatrix      = TransparencyMatrix;
            m.DepthMatrix             = DepthMatrix;
            m.IsInInvalidState        = IsInInvalidState;
            return(m);
        }
예제 #8
0
        public _Room DeepCopy()
        {
            List <_Line> newLines = new List <_Line>();

            foreach (_Line line in lines)
            {
                newLines.Add(line.DeepCopy());
            }

            _Room deepCopy = new _Room(newLines);

            deepCopy.Name   = Name;
            deepCopy.Number = Number;
            deepCopy.type   = type;
            deepCopy.Points = Points;
            return(deepCopy);
        }
예제 #9
0
        //this is important only when the room contained the original line, only then is it possible
        //TODO: here I only solve it for one line, if two lines are overlapped, we have a problem.
        private void TryToCatchIfGlobalCase(_Room room, _Line movedLine)
        {
            List <_Line> overlappedlistinroom = new List <_Line>();

            //overlappedlistinroom.Add(movedLine);
            foreach (_Line roomLine in room.Lines)
            {
                if (roomLine.Overlaps(movedLine))
                {
                    overlappedlistinroom.Add(roomLine);
                }
            }

            if (overlappedlistinroom.Count > 1)
            {
                DoSomething(ref room, overlappedlistinroom);
                //until we know how to fix it, mark as invalid
                //IsInInvalidState = true;
            }
        }