| 298 | } |
| 299 | |
| 300 | size_t GUIHelpers::OverlapDetector::placeItem(double x_start, double x_end) |
| 301 | { |
| 302 | if (x_start < 0) |
| 303 | OPENMS_LOG_WARN << "Warning: x coordinates should be positive!\n"; |
| 304 | if (x_start > x_end) |
| 305 | OPENMS_LOG_WARN << "Warning: x-end is larger than x-start!\n"; |
| 306 | |
| 307 | size_t best_index = 0; |
| 308 | double best_distance = std::numeric_limits<double>::max(); |
| 309 | for (size_t i = 0; i < rows_.size(); ++i) |
| 310 | { |
| 311 | if (rows_[i] < x_start) |
| 312 | { // easy win; row[i] does not overlap; take it |
| 313 | rows_[i] = x_end; // update space for next call |
| 314 | return i; |
| 315 | } |
| 316 | // x_start is smaller than row's end... |
| 317 | if ((rows_[i] - x_start) < best_distance) |
| 318 | { |
| 319 | best_distance = rows_[i] - x_start; |
| 320 | best_index = i; |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | rows_[best_index] = x_end; // update space for next call |
| 325 | return best_index; |
| 326 | } |
| 327 | |
| 328 | } //namespace OpenMS |
| 329 |
no test coverage detected