tags:

views:

101

answers:

3

anybody can explain me epsilon what is this term although i did not use in my header file. like

Right (const lPoint& a, const lPoint& b, const lPoint& c, double epsilon)
{
#if _NOT_USED_EPSILON
    return (( (a.x_ * b.y_) - (a.y_ * b.x_) +
              (a.y_ * c.x_) - (a.x_ * c.y_) +
              (b.x_ * c.y_) - (c.x_ * b.y_) ) < 0);
#else
/*  return (( (a.x_ * b.y_) - (a.y_ * b.x_) +
              (a.y_ * c.x_) - (a.x_ * c.y_) +
              (b.x_ * c.y_) - (c.x_ * b.y_) ) < -SPATIAL_EPSILON);*/
    if( epsilon == -1 )
        return (b.x_-a.x_)*(c.y_-a.y_)-(c.x_-a.x_)*(b.y_-a.y_) < -SPATIAL_AREA_EPSILON;
    else
        return (b.x_-a.x_)*(c.y_-a.y_)-(c.x_-a.x_)*(b.y_-a.y_) < -epsilon;
#endif
}

here i did not used epsilon in my file than wy we are saying that #if _not_used_epsilon than return this .... while my epsilon by default is 0 because its mot initialized. but its use din if condition and her const is used because it will not change the value of arguemnt. right!

and this #if will not read by complier inside the function i want to ask that #directory are read by coompiler or not.. i am not getting #directories.. why we use it we can sue simple if condition with variables as we use in function,, so why #directory inside the main.. who will deal with it compiler..

+1  A: 

This code is simple. What it does is this?

If the preprocessor symbol _NOT_USED_EPSILON is defined (through make file, command line) etc, then the expression is checked if it is less than 0.

In some cases (since double arithmetic looses precision), one may check the value of the expression if it is significantly close to 0.

If such precision arithmetic is required then the make file would undefine the preprocessor symbols _NOT_USED_EPSILON.

In such a case, the expression will be checked with the value of the last argument to your function (epsilon).

Note that _NOT_USED_EPSILON is not read by the compiler but is a preprocessor directive.

From the OP, the code below is compiled only when _NOT_USED_EPSILON is defined, else it is not.

return (( (a.x_ * b.y_) - (a.y_ * b.x_) + 
          (a.y_ * c.x_) - (a.x_ * c.y_) + 
          (b.x_ * c.y_) - (c.x_ * b.y_) ) < 0); 
Chubsdad
ohh i see actually preprocessor directories are translated 1st as an text than that text is used by compiler later on depending of preprocessor directories where are used.. so 1st preprocessor direcory
piyapiya
dirctory are translated and applied to whoel program and complier use envoked it depend on where preprocessor(jsut like a text) are used..
piyapiya
am i right? is this true?
piyapiya
if yes than my next question is let say i have a header files A.h and B.h and i use #define in one file but can i use it in other header file as #if defined ... { do abc} #else {def} #endif
piyapiya
what "sorta" please i am learning so if you feel me wrong than clear to me instead of saying something bad to me.. ok
piyapiya
@piyapiya: pls feel free to experiment. there is nothing better than trying out yourself. The second best way is to teach (after you learn). What you are asking is easy to try and experiment
Chubsdad
ok finally i got result that preprocessor directories are jsut text that translated 1st and than complier use evoked it thats depend where preprocessor directory is sued.. am i right
piyapiya
and one thing more if an #defined is used by my A.h and in B.h i say #if defined --- (thats in A.h) than do {...}(by compiler) #else {....}.. am i right...
piyapiya
Yes. preprocessor directives are processed before compilation. #defines defined through explicit #define directive are per translation unit. Many compilers provide option to specify the preprocesor directive at command line which then apply to each translation unit
Chubsdad
but i can use condition in functions. why i need to be preprocessor directory.. as i come to understand let say defined Pi as 3.1417 if i sue it in a function or main it will be accessible on her not whole files(classes). so thats y i need to use Pi as #defined.. i think like this..
piyapiya
so i mean all classes can use this PI.. or we can make condition by using #def liek #ifdef PI than do this #else
piyapiya
do other thing .. so i think by using Preprocessor directories.. we do't bound over self.. while if i sue in main or globle than it will only accessible to there not in other class.. so in this case i need to use #preprocessors.
piyapiya
can you refer me any link related to template in c++.. i am not getting from Wikipedia.. any useful textbook
piyapiya
A: 

Epsilon is a small tolerance value using when comparing floating-point values. See http://en.wikipedia.org/wiki/Machine_epsilon.

I'd suggest you pass something like 1e-6 in the epsilon parameter to Right().

Frédéric Hamidi
A: 

#if is a preprocessor directive.

Read up on the preprocessor in your C++ textbook.

Alf P. Steinbach