I'm working on a function which should return false if any of the point positions are outside of the defined rectangle boundaries.
My current c++ code is as follows:
bool trackingPointsVisible(){
//I've got 4 points here
if(!points.empty()){
// loop through each of the points
for(int i=0; i<points.size(); i++){
//check if points' x and y positions are out of the boundaries
if(points[i].x < -60 || points[i].x > 300 ||
points[i].y < -60 || points[i].y > 300){
// if any of them are out return false
return false;
}else{
//if they're within the boundaries, return true
return true;
}
}
}
}
For some reason, it returns true even if one of the points if out of the specified boundaries. I don't think this should be the case. Should I rewrite this function and check each point individually or is there another approach?
Could anyone please point what am I doing wrong here? Thanks.
Aucun commentaire:
Enregistrer un commentaire