Hi, I'm trying to make a function that returns the nearest sf::RectangleShape, but I can't really grasp the concept yet. If I'm right in saying you can store the minimum X and Y value required to fit in all the points of a shape in a sf::FloatRect, how can you use this to determine the closest sf::RectangleShape? Can you use the x value with the point you're measuring from's x value and so on? I came up with the following code and compiled it but it doesn't work correctly. I may have the completely wrong idea though so feel free to correct me.

std::vector<myGameClass> levelGenerator(50) // contains the sf::RectangleShapes

...

std::vector<sf::FloatRect> floatRectVec(50); //vector to store the floatRects's

std::vector<int> floatRectDistances(50); //vector to store the y distance

sf::FloatRect playerGlobalBounds = player.getGlobalBounds(); // player is the point measuring from

for (int vecObjects = 0; vecObjects < levelGenerator.size(); vecObjects++){

sf::FloatRect tmpFloatRect = levelGenerator[vecObjects].rectangleShape.getGlobalBounds();

floatRectVec[vecObjects] = tmpFloatRect;

floatRectDistances[vecObjects] = (tmpFloatRect.height - playerGlobalBounds.height);

std::cout<<floatRectDistances[vecObjects]; //for debugging

// ...using floatRectDistances[vecObjects] get the nearest sf::RectangleShape

}