/** * This method returns a copy of the blueprint. * This is a Deep Copy, meaning that all the Rooms, Corners in those rooms and Walls connected to those corners will be copied. * The purpose of this is to make a new copy to work in when editing a blueprint, while preserving the original. */ public Blueprint Clone() { Blueprint newBp = new Blueprint(this.Name); List<Wall> newWalls = new List<Wall>(); List<Corner> newCorners = new List<Corner>(); foreach(Room room in this.Rooms) { Room newRoom = new Room(room.Name, room.GetID(), room.GetFloorID(), room.FunctionID); newBp.Rooms.Add(newRoom); foreach(Corner corner in room.GetCorners()) { Corner newCorner = newCorners.Find( (c) => (c.GetID() == corner.GetID()) ); if(newCorner != null) { newRoom.AddCorner(newCorner); continue; } newCorner = new Corner(corner.GetID(), corner.GetPoint()); newRoom.AddCorner(newCorner); newCorners.Add(newCorner); foreach(Wall wall in corner.GetWalls()) { Wall newWall = newWalls.Find( (w) => (w.GetID() == wall.GetID()) ); if(newWall != null) { if(newWall.Left.GetID() == corner.GetID()) { newWall.Left = newCorner; } else if(newWall.Right.GetID() == corner.GetID()) { newWall.Right = newCorner; } if(newWall.GetType() == typeof(Door)) { ((Door)newWall).Hinge = (((Door)newWall).Hinge.Equals(newWall.Left) ? newWall.Left : newWall.Right); } newCorner.AddWall(newWall); continue; } Corner left = (wall.Left.Equals(newCorner) ? newCorner : wall.Left); Corner right = (wall.Right.Equals(newCorner) ? newCorner : wall.Right); if(wall.GetType() == typeof(Door)) { newWall = new Door(wall.GetID(), left, right, (((Door)wall).Hinge.GetID() == left.GetID() ? left : right), ((Door)wall).Direction); } else { newWall = new Wall(wall.GetID(), left, right); } newWalls.Add(newWall); newCorner.AddWall(newWall); } } newRoom.IsChanged = room.IsChanged; } return newBp; }
public void CornerAddCorner(float x, float y) { //arrange Room room = new Room("Leslokaal", 3, 4,1); //act room.AddCorner(new Corner(x, y)); //assert List<Corner> corners = (List<Corner>)room.GetCorners(); Assert.AreEqual(1, corners.Count); Assert.IsNotNull(corners[0]); Assert.IsInstanceOf(typeof(Corner), corners[0]); }
public void NullAddCorner() { //arrange Room room = new Room("Leslokaal", 3, 4,2); //act room.AddCorner(null); //assert List<Corner> corners = (List<Corner>)room.GetCorners(); Assert.AreEqual(0, corners.Count); }