Beispiel #1
0
        /// <summary>
        /// Creates a group of rooms by dividing the supplied Polygon perimeter by the quantity of supplied divisions along the orthogonal x and y axes. Room perimeters conform to fit within the supplied Polygon.
        /// </summary>
        /// <param name="perimeter">The Polygon to divide with a number of Room perimeters.</param>
        /// <param name="xRooms">The quantity of Rooms along the x axis.</param>
        /// <param name="yRooms">The quantity of Rooms along the y axis.</param>
        /// <param name="name">An arbitrary string identifier for this RoomGroup.</param>
        /// <returns>
        /// A new RoomGroup.
        /// </returns>
        public RoomGroup(Polygon perimeter, int xRooms = 1, int yRooms = 1, string name = "")
        {
            Perimeter = new Polygon(perimeter.Vertices);
            Name      = name;
            Box       = new TopoBox(perimeter);
            Rooms     = new List <Room>();

            var sizeX = Box.SizeX / xRooms;
            var sizeY = Box.SizeY / yRooms;
            var count = xRooms * yRooms;

            for (int xIdx = 0; xIdx < xRooms; xIdx++)
            {
                var xCoord = Box.SW.X + (xIdx * sizeX);
                for (int yIdx = 0; yIdx < yRooms; yIdx++)
                {
                    var yCoord  = Box.SW.Y + (yIdx * sizeY);
                    var polygon = Shaper.PolygonBox(sizeX, sizeY);
                    polygon = polygon.MoveFromTo(new Vector3(), new Vector3(xCoord, yCoord)).Intersection(perimeter).First();

                    var room = new Room()
                    {
                        Color     = Palette.Aqua,
                        Perimeter = polygon
                    };
                    Rooms.Add(room);
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Creates and sets a rectangular Room Perimeter, Height, and southwest corner location with a supplied vectors.
 /// Sets the DesignX and DesignY properties.
 /// </summary>
 /// <param name="xyz">Vector3 dimensions of a new Polygon Perimeter. If xy.Z is > 0.0, sets the height of the Room.</param>
 /// <param name="moveTo">Vector3 location of the new Polygon's southwest corner.</param>
 /// <returns>
 /// True if the Perimeter is successfully set.
 /// </returns>
 public bool SetDimensions(Vector3 xyz, Vector3 moveTo = null)
 {
     if (xyz.X <= 0.0 || xyz.Y <= 0.0)
     {
         return(false);
     }
     Perimeter = Shaper.PolygonBox(xyz.X, xyz.Y, moveTo);
     if (xyz.Z > 0.0)
     {
         Height = xyz.Z;
     }
     return(true);
 }
Beispiel #3
0
 /// <summary>
 /// Creates and sets a rectangular Room Perimeter with dimensions derived from Room characteristics with its southwest corner at the origin or at the 2D location implied by the supplied Vector3.
 /// </summary>
 /// <returns>
 /// True if the Perimeter is successfully set.
 /// </returns>
 public bool SetPerimeter(Vector3 moveTo = null)
 {
     if (DesignSet)
     {
         Perimeter = Shaper.PolygonBox(DesignLength, DesignWidth, moveTo);
         return(true);
     }
     else if (DesignArea > 0.0 && DesignRatio > 0.0)
     {
         Perimeter = Shaper.PolygonByArea(DesignArea, DesignRatio, moveTo);
         return(true);
     }
     return(false);
 }
Beispiel #4
0
 /// <summary>
 /// Creates a Polygon perimeter derived from the supplied Room characteristics.
 /// </summary>
 /// <param name="room">The Room from which to derive the Polygon to place.</param>
 /// <returns>
 /// A new Polygon derived either from fixed dimensions or as a variably proportioned area.
 /// </returns>
 private Polygon RoomPerimeter(Room room)
 {
     if (room.Perimeter != null)
     {
         return(room.Perimeter);
     }
     if (room.DesignX > 0.0 && room.DesignY > 0.0)
     {
         return(Shaper.PolygonBox(room.DesignX, room.DesignY));
     }
     else
     {
         return(Shaper.AreaFromCorner(room.DesignArea, Shaper.RandomDouble(1, 2)));
     }
 }
Beispiel #5
0
 /// <summary>
 /// Creates a Polygon perimeter at the origin with dimensions derived from Room characteristics. Assumes the Perimeter will be relocated and so omits setting the Room's Perimeter.
 /// </summary>
 /// <returns>
 /// A new rectilinear Polygon derived either from fixed dimensions or as a rectilinear target area of a randomly determined ratio between 1 and 2 between the Room's X and Y dimensions.
 /// </returns>
 public Polygon MakePerimeter()
 {
     if (Perimeter != null)
     {
         return(Perimeter);
     }
     if (DesignX > 0.0 && DesignY > 0.0)
     {
         return(Shaper.PolygonBox(DesignX, DesignY));
     }
     else
     {
         return(Shaper.AreaFromCorner(DesignArea, Shaper.RandomDouble(1, 2)));
     }
 }
Beispiel #6
0
        /// <summary>
        /// Places a Polygon east of another Polygon, attempting to align bounding box corners or the horizontal bounding box axis.
        /// </summary>
        /// <param name="polygon">The Polygon to be placed adjacent to another Polygon.</param>
        /// <param name="adjTo">The Polygon adjacent to which the new Polygon will be located.</param>
        /// <param name="perimeter">The Polygon that must cover the resulting Polygon.</param>
        /// <param name="among">The collection of Polygons that must not intersect the resulting Polygon.</param>
        /// <returns>
        ///  A new Polygon or null if the conditions of placement cannot be satisfied.
        /// </returns>



        /// <summary>
        /// Creates and sets a rectangular Room Perimeter with dimensions derived from Room characteristics with its southwest corner at the supplied Vector3 point. If no point is supplied, the southwest corner is placed at the origin.
        /// </summary>
        /// <param name="moveTo">The Vector3 indication the location of new Polygon's southwest corner.</param>
        /// <returns>
        /// A new rectilinear Polygon derived either from fixed DesignX and DesignY dimensions or as a rectilinear target area of a random ratio between 1 and 2 of the Room's X to Y dimensions.
        /// </returns>
        public Polygon MakePerimeter(Vector3 moveTo = null)
        {
            if (DesignX > 0.0 && DesignY > 0.0)
            {
                Perimeter = Shaper.PolygonBox(DesignX, DesignY);
            }
            else
            {
                Perimeter = Shaper.AreaFromCorner(DesignArea, Shaper.RandomDouble(1, 2));
            }
            if (moveTo != null)
            {
                Perimeter = Perimeter.MoveFromTo(new Vector3(), moveTo);
            }
            return(Perimeter);
        }
Beispiel #7
0
        /// <summary>
        /// Tests if the supplied Polygon resides in a corner of a Polygon perimeter.
        /// </summary>
        /// <param name="polygon">The Polygon to test.</param>
        /// <param name="perimeter">The Polygon to test against.</param>
        /// <returns>
        /// Returns true if exactly three of the polygon bounding box points fall on the Polygon perimeter bounding box.
        /// </returns>
        public static bool AtCorner(this Polygon polygon, Polygon perimeter)
        {
            var count    = 0;
            var box      = new TopoBox(perimeter);
            var boundary = Shaper.PolygonBox(box.SizeX, box.SizeY).MoveFromTo(Vector3.Origin, box.SW);

            foreach (Vector3 vertex in BoxCorners(polygon))
            {
                if (boundary.Touches(vertex))
                {
                    count++;
                }
            }
            if (count != 3)
            {
                return(false);
            }
            return(true);
        }
Beispiel #8
0
        /// <summary>
        /// Clears the current Rooms list and creates new Rooms defined by orthogonal x- and y-axis divisions of the RoomGroup Perimeter.
        /// </summary>
        /// <param name="xRooms">The quantity of Rooms along orthogonal x-axis. Must be positive.</param>
        /// <param name="yRooms">The quantity of Rooms along orthogonal y-axis. Must be positive.</param>
        /// <returns>
        /// True if the Rooms are created.
        /// </returns>
        public bool RoomsByDivision(int xRooms = 1, int yRooms = 1, double height = 3.0)
        {
            if (Perimeter == null || xRooms < 1 || yRooms < 1 || height <= 0.0)
            {
                return(false);
            }
            var sizeX    = SizeX / xRooms;
            var sizeY    = SizeY / yRooms;
            var count    = xRooms * yRooms;
            var box      = new TopoBox(Perimeter);
            var newRooms = new List <Room>();

            for (int xIdx = 0; xIdx < xRooms; xIdx++)
            {
                var xCoord = box.SW.X + (xIdx * sizeX);
                for (int yIdx = 0; yIdx < yRooms; yIdx++)
                {
                    var yCoord  = box.SW.Y + (yIdx * sizeY);
                    var polygon = Shaper.PolygonBox(sizeX, sizeY);
                    polygon = polygon.MoveFromTo(Vector3.Origin, new Vector3(xCoord, yCoord)).Intersection(Perimeter).First();
                    var room = new Room()
                    {
                        Height    = height,
                        Perimeter = polygon
                    };
                    newRooms.Add(room);
                }
            }
            if (newRooms.Count == 0)
            {
                return(false);
            }
            Rooms.Clear();
            Rooms.AddRange(newRooms);
            return(true);
        }