public Room RoomHull(Room room) { var aabb = room.aabb; var vertices = new List<IntVertex2>(room); var newRoom = new List<IntVertex2>(); var last = ScanY(vertices, aabb.min, aabb.max.y) ?? ScanX(vertices, aabb.min, aabb.max.x); if (last == null) { return null; } newRoom.Add(last); vertices.Remove(last); bool parallelX = false; while (vertices.Count > 0) { if (parallelX) { last = ScanX(vertices, newRoom.Last(), aabb.max.x) ?? ScanX(vertices, newRoom.Last(), aabb.min.x); if (last != null) { newRoom.Add(last); vertices.Remove(last); parallelX = false; } } else { last = ScanY(vertices, newRoom.Last(), aabb.max.y) ?? ScanY(vertices, newRoom.Last(), aabb.min.y); if (last != null) { newRoom.Add(last); vertices.Remove(last); parallelX = true; } } } return new Room(newRoom); }
private void GenerateOuterRoom() { var outerRooms = new List<Room>(); foreach (var o in outerWalls) { outerRooms.Add(new Room(new[] { new IntVertex2(o[0], o[1]), new IntVertex2(o[0], o[1] + o[3]), new IntVertex2(o[0] + o[2], o[1] + o[3]), new IntVertex2(o[0] + o[2], o[1]) })); } var outerVertices = new List<IntVertex2>(); foreach (var room in outerRooms) { outerVertices.AddRange(room); foreach (var o in outerRooms) { List<IntSegment2> intersections; if (room != o && Intersection.IntPolygonToIntPolygon(room, o, out intersections)) { foreach (var intersection in intersections) { if (intersection.a == intersection.b) { outerVertices.Add(intersection.a); } } } } } var outerRoom = new Room(outerVertices) {canGrow = false, color = Color.gray}; //outerRoom.RemoveDuplicateVertices(); outerRoom.RemoveCollinearVertices(); rooms.Add(outerRoom); }