| 748 | } |
| 749 | |
| 750 | static math::Vec eachNearestGridPos(math::Vec pos, std::function<bool(math::Vec pos)> f) { |
| 751 | math::Vec leftPos = (pos / RACK_GRID_SIZE).round(); |
| 752 | math::Vec rightPos = leftPos + math::Vec(1, 0); |
| 753 | |
| 754 | while (true) { |
| 755 | if (f(leftPos * RACK_GRID_SIZE)) |
| 756 | return leftPos * RACK_GRID_SIZE; |
| 757 | leftPos.x -= 1; |
| 758 | |
| 759 | if (f(rightPos * RACK_GRID_SIZE)) |
| 760 | return rightPos * RACK_GRID_SIZE; |
| 761 | rightPos.x += 1; |
| 762 | } |
| 763 | |
| 764 | assert(false); |
| 765 | return math::Vec(); |
| 766 | } |
| 767 | |
| 768 | void RackWidget::setModulePosNearest(ModuleWidget* mw, math::Vec pos) { |
| 769 | eachNearestGridPos(pos, [&](math::Vec pos) -> bool { |
no test coverage detected