예제 #1
0
        /// <summary>
        /// Adds a Room to the Corridors list.
        /// </summary>
        /// <param name="room">Room to add.</param>
        /// <returns>
        /// True if one or more Rooms were added.
        /// </returns>
        public bool AddCorridor(Room room,
                                bool merge       = true,
                                double tolerance = 0.0,
                                double minLength = 0.0)
        {
            var perimeters = Shaper.FitWithin(room.Perimeter, Perimeter);

            if (perimeters.Count == 0)
            {
                return(false);
            }
            var fitAmong = new List <Polygon>(OpeningsAsPolygons);

            fitAmong.AddRange(ExclusionsAsPolygons);
            fitAmong.AddRange(ServicesAsPolygons);
            var corridors = Shaper.Differences(perimeters, fitAmong).ToList();

            if (corridors.Count() == 0)
            {
                return(false);
            }
            corridors.AddRange(CorridorsAsPolygons);
            if (merge)
            {
                corridors = Shaper.Merge(corridors);
            }
            Corridors.Clear();
            foreach (var corridor in corridors)
            {
                Corridors.Add(
                    new Room(room)
                {
                    Elevation = Elevation,
                    Height    = room.Height,
                    Perimeter = corridor
                });
            }
            FitRooms();
            return(true);
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="suite"></param>
        /// <returns></returns>
        private void PlaceReciprocal()
        {
            if (Rooms.Count == 0)
            {
                return;
            }
            var area = 0.0;

            foreach (var room in Rooms)
            {
                area += room.Area;
            }
            var roomRows = new List <RoomRow>();

            while (RoomsPlaced.Count < Rooms.Count)
            {
                roomRows.Clear();
                Perimeter = Shaper.RectangleByArea(area, Ratio);
                var roomRow = new RoomRow(Perimeter);
                roomRows.Add(roomRow);
                var i = 0;
                while (i < Rooms.Count)
                {
                    if (!roomRow.AddRoomFitted(Rooms[i], false))
                    {
                        break;
                    }
                    i++;
                }
                if (i == Rooms.Count)
                {
                    return;
                }
                var perimeter = Shaper.Differences(roomRow.Perimeter.ToList(), roomRow.Footprint.ToList());
                if (perimeter.Count == 0)
                {
                    break;
                }
                var matchRow = new RoomRow(perimeter.First());
                roomRows.Add(matchRow);
                while (i < Rooms.Count)
                {
                    if (!matchRow.AddRoomFitted(Rooms[i], true))
                    {
                        break;
                    }
                    i++;
                }
                Ratio += 0.1;
            }
            Rooms.Clear();
            foreach (var roomRow in roomRows)
            {
                foreach (var room in roomRow.Rooms)
                {
                    Rooms.Add(room);
                }
            }
            //2020.07.09 Anthony Hauck
            //Commented code makes suite geometric room diffs into one or more extra rooms.
            //Overall the results were more confusing that just ignoring them, but leaving
            //this here in case future developers have a better idea.
            //var lastRow = roomRows.Last();
            //var rooms = lastRow.RoomsAsPolygons;
            //var diffs = lastRow.Perimeter.Difference(rooms).ToList();
            //if (diffs.Count > 0)
            //{
            //    var height = lastRow.Rooms.Last().Height;
            //    diffs = Shaper.Merge(diffs);
            //    foreach (var diff in diffs)
            //    {
            //        Rooms.Add(
            //            new Room(diff, height)
            //            {
            //                Color = Palette.White
            //            });
            //    }
            //}
            Perimeter = Footprint;
        }