Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- placement_tree_t computePlacement(const input_entry_array_t Entries,
- point_t UpperLeftCorner,
- point_t LowerRightCorner,
- point_t BorderSize) {
- assert(Entries.Size > 0 && "No entries to place!");
- (void) LowerRightCorner;
- (void) UpperLeftCorner;
- (void) BorderSize;
- (void) Entries;
- placement_tree_t Root;
- // TODO: Implement me!
- if (Entries.Size == 1){
- Root.NodeKind = LEAF_NODE;
- Root.Content.Leaf->ChildTree = NULL;
- Root.Content.Leaf->Color = Entries.Data->Color;
- Root.Content.Leaf->UpperLeftCorner = UpperLeftCorner;
- Root.Content.Leaf->LowerRightCorner = LowerRightCorner;
- return Root;
- }else {
- int64_t width = LowerRightCorner.X - UpperLeftCorner.X;
- int64_t height = UpperLeftCorner.Y - LowerRightCorner.Y;
- orientation_t Splitd = (width < height)? HORIZONTAL : VERTICAL;
- point_t LowerRightCorner1;
- point_t UpperLeftCorner1 = UpperLeftCorner;
- point_t LowerRightCorner2 = LowerRightCorner;
- point_t UpperLeftCorner2;
- if (Splitd == HORIZONTAL){
- LowerRightCorner1.X = LowerRightCorner.X;
- LowerRightCorner1.Y = LowerRightCorner.Y - (height/2);
- UpperLeftCorner2.X = UpperLeftCorner.X;
- UpperLeftCorner2.Y = UpperLeftCorner.Y - (height/2);
- }else {
- LowerRightCorner1.X = LowerRightCorner.X - (width/2);
- LowerRightCorner1.Y = LowerRightCorner.Y;
- UpperLeftCorner2.X = UpperLeftCorner.X - (width/2);
- UpperLeftCorner2.Y = UpperLeftCorner.Y;
- }
- unsigned Size = computePartitionSize(Entries);
- input_entry_array_t Part1 = computePartitionView(Entries, 0, Size);
- input_entry_array_t Part2 = computePartitionView(Entries, Size, Entries.Size - Size);
- for (unsigned i = 0; i < Size; i++){
- computeEntryPlacement(Part1.Data[i], UpperLeftCorner1, LowerRightCorner1, BorderSize);
- }
- for (unsigned j = 0; j < Entries.Size - Size; ++j){
- computeEntryPlacement(Part2.Data[j], UpperLeftCorner2, LowerRightCorner2, BorderSize);
- }
- }
- return Root;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement