Before I add one to libgis, does anyone know if there is an existing lib
function that will test if a coordinate pair is inside or outside the
current region?
e.g.
/* is e,n in the current region? */
int point_in_region(double easting, double northing)
{
struct Cell_head window;
/* use directly when speed is important or for eg point in map */
int point_in_window(double easting, double northing,
struct Cell_head window)
{
if ( easting > window.east || easting < window.west ||
northing > window.north || northing < window.south)
return FALSE;
return TRUE;
}
a C question:
if (FALSE && G_something())
will stop as soon as it tests the first term (FALSE) and won't execute
G_something(), does OR work the same way?
if(TRUE || G_something())
is there a chance G_somthing() will get run in the OR case?
(the first term will know if the G_() call will be valid)
will stop as soon as it tests the first term (FALSE) and won't execute
G_something(), does OR work the same way?
These days, that may be up to the compiler (tunable?). Some
architectures offer parallel branching that would execute both
simultaneously and compare results. Glynn would know more details.
For the above to continue into the if branch, both variables must return
a value >= 1. ANSI C specifies that order of operation is guaranteed
left to right for '||', '&&', and '?:'.
In short, if the left-hand expression is 'false', the right-hand
expression will not be executed.
if(TRUE || G_something())
is there a chance G_somthing() will get run in the OR case?
(the first term will know if the G_() call will be valid)
See above.
--
Brad Douglas <rez touchofmadness com> KB8UYR/6
Address: 37.493,-121.924 / WGS84 National Map Corps #TNMC-3785
On 2/13/07, Hamish <hamish_nospam@yahoo.com> wrote:
Before I add one to libgis, does anyone know if there is an existing lib
function that will test if a coordinate pair is inside or outside the
current region?
e.g.
/* is e,n in the current region? */
int point_in_region(double easting, double northing)
{
struct Cell_head window;
/* use directly when speed is important or for eg point in map */
int point_in_window(double easting, double northing,
struct Cell_head window)
{
if ( easting > window.east || easting < window.west ||
northing > window.north || northing < window.south)
return FALSE;
return TRUE;
}
a C question:
if (FALSE && G_something())
will stop as soon as it tests the first term (FALSE) and won't execute
G_something(), does OR work the same way?
if(TRUE || G_something())
is there a chance G_somthing() will get run in the OR case?
(the first term will know if the G_() call will be valid)
Hi Hamish, I think that this would be a great convenience
to have, especially since there are a couple bugs in v.drape which
could be fixed with a quick call to point_in_region() at each vertex.
> a C question:
>
> if (FALSE && G_something())
>
> will stop as soon as it tests the first term (FALSE) and won't execute
> G_something(), does OR work the same way?
These days, that may be up to the compiler (tunable?). Some
architectures offer parallel branching that would execute both
simultaneously and compare results. Glynn would know more details.
C's && and || operators are guaranteed to stop once the answer is
known. Any subsequent expressions will not be evaluated, in the sense
that if those expressions have "visible" side-effects, those
side-effects will not occur.
Visible side-effects include modifying variables, calling functions
(except for locally-defined functions which are known to have no
visible side-effects), dereferencing pointers, and reading "volatile"
variables.