/// <summary> /// Initializes a new instance of the <see cref="Cities.Library.Model.Building"/> class. /// </summary> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="width">Width.</param> /// <param name="height">Height.</param> /// <param name="length">Length.</param> public Building(double x, double y, double width, double height, double length) { Position = new Position(x, y); Size = new Size(width, height, length); }
private static void Generate(Node<Building> root, City city) { var stackX = new Stack<Tuple<Node<Building>, Position, int>>(); stackX.Push(new Tuple<Node<Building>, Position, int>(root,new Position(200,200),1)); bool u = true; double currentUp = 0; double currentDown = 0; double currentLeft = 0; double currentRigh = 0; while (stackX.Count > 0) { var node = stackX.Pop(); currentUp = 0; currentDown = 0; currentLeft = 0; currentRigh = 0; foreach (var item in node.Item1.Children) { if (item.Value != null) { item.Value.Position = GeneratePosition(u, ref currentUp, ref currentDown, ref currentLeft, ref currentRigh, node.Item3, item.Value.Size, node.Item2); u = !u; city.Buildings.Add(item.Value); } else { if (node.Item3 == 1) { Position position; if (u) position = new Position(node.Item2.X + currentUp, node.Item2.Y); else position = new Position(node.Item2.X + currentDown, node.Item2.Y); var tuple = new Tuple<Node<Building>, Position, int>(item, position, u ? 2 : 4); stackX.Push(tuple); } else if (node.Item3 == 3) { Position position; if (u) position = new Position(node.Item2.X - currentUp, node.Item2.Y); else position = new Position(node.Item2.X - currentDown, node.Item2.Y); var tuple = new Tuple<Node<Building>, Position, int>(item, position, u ? 2 : 4); stackX.Push(tuple); } else if (node.Item3 == 2) { Position position; if (u) position = new Position(node.Item2.X, node.Item2.Y + currentLeft); else position = new Position(node.Item2.X, node.Item2.Y + currentRigh); var tuple = new Tuple<Node<Building>, Position, int>(item, position, u ? 1 : 3); stackX.Push(tuple); } else if (node.Item3 == 4) { Position position; if (u) position = new Position(node.Item2.X, node.Item2.Y - currentLeft); else position = new Position(node.Item2.X, node.Item2.Y - currentRigh); var tuple = new Tuple<Node<Building>, Position, int>(item, position, u ? 1 : 3); stackX.Push(tuple); } u = !u; } } } }
/// <summary> /// Initializes a new instance of the <see cref="Cities.Library.Model.Building"/> class. /// </summary> /// <param name="position">Position.</param> /// <param name="size">Size.</param> public Building(Position position, Size size) { Position = position; Size = size; }
private static Position GeneratePosition(bool u, ref double currentUp, ref double currentDown, ref double currentLeft, ref double currentRigth, int direction, Size size, Position position) { switch (direction) { case 1: if (u) { currentUp += size.Width; return new Position(position.X + currentUp - size.Width, position.Y+size.Length); } else { currentDown += size.Width; return new Position(position.X+ currentDown - size.Width, position.Y); } break; case 2: if (u) { currentLeft += size.Length; return new Position(position.X - size.Width, position.Y + currentLeft - size.Length); } else { currentRigth += size.Length; return new Position(position.X, position.Y + currentRigth - size.Length); } break; case 3: if (u) { currentUp += size.Width; return new Position(position.X - currentUp - size.Width, position.Y+size.Length); } else { currentDown += size.Width; return new Position(position.X - currentDown - size.Width, position.Y); } break; case 4: if (u) { currentLeft += size.Length; return new Position(position.X - size.Width, position.Y - currentLeft - size.Length); } else { currentRigth += size.Length; return new Position(position.X, position.Y - currentRigth - size.Length); } break; default: return null; } }