MCPcopy Create free account
hub / github.com/VCVRack/Rack / eachNearestGridPos

Function eachNearestGridPos

src/app/RackWidget.cpp:750–766  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

748}
749
750static 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
768void RackWidget::setModulePosNearest(ModuleWidget* mw, math::Vec pos) {
769 eachNearestGridPos(pos, [&](math::Vec pos) -> bool {

Callers 2

setModulePosNearestMethod · 0.85

Calls 3

VecClass · 0.85
roundMethod · 0.80
fFunction · 0.50

Tested by

no test coverage detected