MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / FindClosestSide

Method FindClosestSide

Source/PatchCable.cpp:665–699  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

663}
664
665ofVec2f PatchCable::FindClosestSide(float x, float y, float w, float h, ofVec2f start, ofVec2f startDirection, ofVec2f& endDirection)
666{
667 ofVec2f dirs[4];
668 dirs[0].set(-1, 0);
669 dirs[1].set(1, 0);
670 dirs[2].set(0, -1);
671 dirs[3].set(0, 1);
672
673 ofVec2f sides[4];
674 sides[0].set(x, y + h / 2); //left
675 sides[1].set(x + w, y + h / 2); //right
676 sides[2].set(x + w / 2, y); //top
677 sides[3].set(x + w / 2, y + h); //bottom
678
679 float best = -FLT_MAX;
680 int bestIndex = 0;
681 for (int i = 0; i < 4; ++i)
682 {
683 if (i == 3) //skip bottom
684 continue;
685
686 float score = MathUtils::Normal(start - sides[i]).dot(dirs[i]);
687 if (score > best)
688 {
689 best = score;
690 bestIndex = i;
691 }
692 }
693
694 if (w == 0 && h == 0)
695 endDirection = MathUtils::Normal(start - ofVec2f(x, y));
696 else
697 endDirection = dirs[bestIndex];
698 return sides[bestIndex];
699}
700
701void PatchCable::Grab()
702{

Callers

nothing calls this directly

Calls 4

NormalFunction · 0.85
ofVec2fClass · 0.85
dotMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected