| 16 | // ---------------------------------------------------------------------------------------- |
| 17 | |
| 18 | inline rectangle compute_box_dimensions ( |
| 19 | const double width_to_height_ratio, |
| 20 | const double area |
| 21 | ) |
| 22 | { |
| 23 | // make sure requires clause is not broken |
| 24 | DLIB_ASSERT(width_to_height_ratio > 0 && area > 0, |
| 25 | "\t rectangle compute_box_dimensions()" |
| 26 | << "\n\t Invalid arguments were given to this function. " |
| 27 | << "\n\t width_to_height_ratio: " << width_to_height_ratio |
| 28 | << "\n\t area: " << area |
| 29 | ); |
| 30 | |
| 31 | /* |
| 32 | width*height == area |
| 33 | width/height == width_to_height_ratio |
| 34 | */ |
| 35 | |
| 36 | const int height = (int)std::floor(std::sqrt(area/width_to_height_ratio) + 0.5); |
| 37 | const int width = (int)std::floor(area/height + 0.5); |
| 38 | |
| 39 | return centered_rect(0,0,width,height); |
| 40 | } |
| 41 | |
| 42 | // ---------------------------------------------------------------------------------------- |
| 43 | |