Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is this variable never true?

I am testing a latitude/longitude point against a bounding box, to determine if the point is inside of it or not. I am lost as to why the variable inBounds is never set to 1. Since the entire piece of code is complicated, I had the program print out the variables in their current state right before the test. Here are the variables:

fltLatitude 48.2728
fltLongitude -122.772

SITE_LON_EAST[x] =  117.88
SITE_LON_WEST[x] =  125
SITE_LAT_SOUTH[x] = 46.24
SITE_LAT_NORTH[x] =  49.39

And this is the code that executes immediately after:

if(fltLongitude>SITE_LON_EAST[x] && fltLongitude<SITE_LON_WEST[x] && fltLatitude>SITE_LAT_SOUTH[x] && fltLatitude<SITE_LAT_NORTH[x]) // All must be true
{
    inBounds=1;
}
        
if(inBounds==0)
{
    cout << "Point is out of bounds " << endl;  
}
if(inBounds==1)
{
    cout << "Point is in bounds." << endl;
}

Why is inBounds never set to 1?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Because fltLongitude (-122.772) is not greater than SITE_LON_EAST[x] (117.88), then the first check fltLongitude>SITE_LON_EAST[x] is false, which makes the whole set of && conditions false, then inBounds=1; never happens.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading