예제 #1
0
        /// <summary>
        /// Creates or expands a final Room in the remaining RoomRow area.
        /// </summary>
        /// <param name="height">Desired height of the Room if a new Room must be created.</param>
        /// <param name="tolerance">Minimum area of a infill Room. Smaller rooms will be joined to the last Room.</param>
        public void Infill(double height, bool join = false)
        {
            height = Math.Round(Math.Abs(height));
            if (height.NearEqual(0.0) || insert.IsAlmostEqualTo(compass.SE))
            {
                return;
            }
            var polygons = Shaper.Intersections(Polygon.Rectangle(insert, compass.NE).ToList(), perimeterJig.ToList());

            if (polygons.Count == 0)
            {
                return;
            }
            if (polygons.Count > 0 && Rooms.Count > 0 && (join || polygons.First().Area() < Tolerance))
            {
                Rooms.Last().Perimeter =
                    Shaper.Merge(
                        new List <Polygon>
                {
                    polygons.First().Rotate(Vector3.Origin, Angle),
                    Rooms.Last().Perimeter
                }).First();
                return;
            }
            if (Rooms.Count > 0)
            {
                Rooms.Add(new Room(polygons.First().Rotate(Vector3.Origin, Angle), height));
                return;
            }
            Rooms.Add(new Room(perimeterJig.Rotate(Vector3.Origin, Angle), height));
            insert = compass.SE;
        }
예제 #2
0
        /// <summary>
        /// Attempts to place a Room perimeter on the next open segment of the row.
        /// </summary>
        /// <param name="room">Room from which to derive the Polygon to place.</param>
        /// <returns>
        /// True if the room was successfully placed.
        /// </returns>
        public bool AddRoom(Room room, bool within = true)
        {
            if (room == null ||
                insert.DistanceTo(compass.SE) < 1.0 ||
                compass.SW.DistanceTo(insert) >= compass.SW.DistanceTo(compass.SE))
            {
                return(false);
            }
            var     ratio  = room.DesignRatio > 1.0 ? 1 / room.DesignRatio : room.DesignRatio;
            var     length = Math.Sqrt(room.Area * ratio);
            Polygon polygon;

            if (within)
            {
                var polygons = Shaper.Intersections(
                    Polygon.Rectangle(insert, new Vector3(insert.X + length, insert.Y + compass.SizeY)).ToList(),
                    perimeterJig.ToList());
                if (polygons.Count == 0)
                {
                    return(false);
                }
                polygon = polygons.First();
            }
            else
            {
                polygon = Polygon.Rectangle(insert, new Vector3(insert.X + length, insert.Y + compass.SizeY));
            }
            insert         = polygon.Compass().SE;
            room.Perimeter = polygon.Rotate(Vector3.Origin, Angle);
            room.Placed    = true;
            Rooms.Add(room);
            return(true);
        }