SHARE
TWEET

Untitled

a guest May 19th, 2017 41 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. placement_tree_t computePlacement(const input_entry_array_t Entries,
  2.                                   point_t UpperLeftCorner,
  3.                                   point_t LowerRightCorner,
  4.                                   point_t BorderSize) {
  5.   assert(Entries.Size > 0 && "No entries to place!");
  6.  
  7.   (void) LowerRightCorner;
  8.   (void) UpperLeftCorner;
  9.   (void) BorderSize;
  10.   (void) Entries;
  11.  
  12.   placement_tree_t Root;
  13.  
  14.   // TODO: Implement me!
  15.   if (Entries.Size == 1){
  16.     Root.NodeKind = LEAF_NODE;
  17.     Root.Content.Leaf->ChildTree = NULL;
  18.     Root.Content.Leaf->Color = Entries.Data->Color;
  19.     Root.Content.Leaf->UpperLeftCorner = UpperLeftCorner;
  20.     Root.Content.Leaf->LowerRightCorner = LowerRightCorner;
  21.     return Root;
  22.   }else {
  23.     int64_t width = LowerRightCorner.X - UpperLeftCorner.X;
  24.     int64_t height = UpperLeftCorner.Y - LowerRightCorner.Y;
  25.     orientation_t Splitd = (width < height)? HORIZONTAL : VERTICAL;
  26.     point_t LowerRightCorner1;
  27.     point_t UpperLeftCorner1 = UpperLeftCorner;
  28.     point_t LowerRightCorner2 = LowerRightCorner;
  29.     point_t UpperLeftCorner2;
  30.     if (Splitd == HORIZONTAL){
  31.       LowerRightCorner1.X = LowerRightCorner.X;
  32.       LowerRightCorner1.Y = LowerRightCorner.Y - (height/2);
  33.       UpperLeftCorner2.X  = UpperLeftCorner.X;
  34.       UpperLeftCorner2.Y  = UpperLeftCorner.Y - (height/2);
  35.     }else {
  36.       LowerRightCorner1.X = LowerRightCorner.X - (width/2);
  37.       LowerRightCorner1.Y = LowerRightCorner.Y;
  38.       UpperLeftCorner2.X  = UpperLeftCorner.X - (width/2);
  39.       UpperLeftCorner2.Y  = UpperLeftCorner.Y;
  40.     }
  41.     unsigned Size = computePartitionSize(Entries);
  42.     input_entry_array_t Part1 = computePartitionView(Entries, 0, Size);
  43.     input_entry_array_t Part2 = computePartitionView(Entries, Size, Entries.Size - Size);
  44.     for (unsigned i = 0; i < Size; i++){
  45.       computeEntryPlacement(Part1.Data[i], UpperLeftCorner1, LowerRightCorner1, BorderSize);
  46.     }
  47.     for (unsigned j = 0; j < Entries.Size - Size; ++j){
  48.       computeEntryPlacement(Part2.Data[j], UpperLeftCorner2, LowerRightCorner2, BorderSize);
  49.     }
  50.   }
  51.   return Root;
  52. }
RAW Paste Data
Pastebin PRO Summer Special!
Get 60% OFF on Pastebin PRO accounts!
Top