//creates a product where a table and chair are combined.
 public static ChairTablePair CreatePair(ProductModel chair, ProductModel table, float margin) {
     ChairTablePair pair = new ChairTablePair();
     pair.Chair = chair;
     pair.Table = table;
     pair.Representation = DetermineSize(pair, margin);
     return pair;
 }
Exemple #2
0
        //checks how large the pair will be.
        public static Rectangle DetermineSize(ChairTablePair pair, float margin)
        {
            Rectangle rectangle = new Rectangle();

            rectangle.Height = (int)(pair.Table.Width + margin * 2);
            rectangle.Width  = (int)(pair.Chair.Height + pair.Table.Height + margin * 2);
            return(rectangle);
        }
Exemple #3
0
        //creates a product where a table and chair are combined.
        public static ChairTablePair CreatePair(ProductModel chair, ProductModel table, float margin)
        {
            ChairTablePair pair = new ChairTablePair();

            pair.Chair          = chair;
            pair.Table          = table;
            pair.Representation = DetermineSize(pair, margin);
            return(pair);
        }
 /// <summary>
 /// Fills the room with ChairTablePairs. I don't assign ProductModels directly here because the
 /// amount of possibilities is based on the width and height of the pairs.
 /// </summary>
 /// <param name="people"></param>
 /// <param name="pair"></param>
 /// <param name="possibilities"></param>
 /// <returns></returns>
 public List<ChairTablePair> FillRoom(int people, ChairTablePair pair,
     List<Rectangle> possibilities)
 {
     List<ChairTablePair> result = new List<ChairTablePair>();
     int currentPossibility = 0;
     for (int i = 0; i < people; i++)
     {
         try
         {
             ChairTablePair newPair = pair.Clone();
             Rectangle temp = new Rectangle();
             if (i == 0)
             {
                 // teacher column
                 temp.Height = pair.Representation.Height;
                 temp.Width = pair.Representation.Width;
                 temp.X = 0; // teacher should be on the left side of the room in this setup
                 temp.Y = _rows; // and should be placed in the middle.
                 currentPossibility += _rows; // students start on the next column
             }
             else
             {
                 // student column
                 temp.Height = pair.Representation.Height;
                 temp.Width = pair.Representation.Width;
                 temp.X = possibilities[currentPossibility].X*pair.Representation.Width;
                     // setting the X coordinate of a student
                 temp.Y = possibilities[currentPossibility].Y*pair.Representation.Height;
                     // setting Y coordinate.
                 currentPossibility++;
             }
             newPair.Representation = temp; // assign rectangle to pair
             result.Add(newPair);
         }
         catch (ArgumentOutOfRangeException e)
         {
             // You get this exception when the amount of people don't fit in the room.
             throw new RoomTooSmallException("Room is too small to fit the specified amount of people.", e);
         }
     }
     return result;
 }
 /// <summary>
 /// Calculates how many pairs of Chairs and Tables can be fit in the room.
 /// I first need to know how many columns and rows the room can have, which I get from:
 /// columns = roomwidth/pairwidth
 /// rows = roomheight/pairheight
 /// 
 /// Then I add a rectangle to a list for every row/column combination.
 /// </summary>
 /// <param name="pair"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="margin"></param>
 /// <returns></returns>
 public List<Rectangle> CalculatePossibilities(ChairTablePair pair, float width,
     float height, float margin)
 {
     List<Rectangle> possibilities = new List<Rectangle>();
     _columns = (int) width/pair.Representation.Width; // We need to know how many columns and rows there are in a room
     _rows = (int) height/pair.Representation.Height; // to put the pairs in later.
     for (int i = 0; i < _columns; i++)
     {
         for (int j = 0; j < _rows; j++)
         {
             // For every row/column combination, add a rectangle with the x,y values of the row/columns.
             possibilities.Add(new Rectangle
             {
                 X = i,
                 Y = j
             });
         }
     }
     return possibilities;
 }
 //checks how large the pair will be.
 public static Rectangle DetermineSize(ChairTablePair pair, float margin) {
     Rectangle rectangle = new Rectangle();
     rectangle.Height = (int) (pair.Table.Width + margin*2);
     rectangle.Width = (int) (pair.Chair.Height + pair.Table.Height + margin*2);
     return rectangle;
 }