This question already has an answer here:
- Sorting a vector of custom objects 13 answers
How can I sort std::vector<vec2>
containing vec2(x, y)
coordinates based on their distance from point 0.0
?
Example: I'd like to sort this:
std::vector<vec2> vec = { vec2(9,9), vec2(1,1), vec2(5,5), vec2(4,4) };
Into this:
std::vector<vec2> vec = { vec2(1,1), vec2(4,4), vec2(5,5), vec2(9,9) };
Aucun commentaire:
Enregistrer un commentaire