tags:

views:

63

answers:

2
GValue GmBase::getDistancePL(const lPoint& pt, const char* line)
{
    int i, curr=0;
    InfoType ptcnt;
    GValue d, dist = KDBL_MAX;

    lPoint *p;
    ptcnt = *(InfoType*)line;
    p = (lPoint*)&line[InfoSize];
    for( i=1; i<ptcnt; i++ )
    {
        d = getDistance( pt, p[i-1], p[i] );
        if( d < dist ) dist = d;
    }
    return dist;
}

here InfoType is defined as double and KDEL_MEX as defined as some flaot point value like 1.75633565664645e+3256 can anybody tell em about this

lPoint *p;
    ptcnt = *(InfoType*)line;
    p = (lPoint*)&line[InfoSize];
    for( i=1; i<ptcnt; i++ )
    {
        d = getDistance( pt, p[i-1], p[i] );
        if( d < dist ) dist = d;
    }
    return dist;
  • p is apoint of IPoint but ptcnt = *(InfoType*)line; is not apointer.. please explain me this function
A: 

I'm not entirely sure what your problem is. p is indeed a pointer and it's used as one in the expression p[i-1] which is equivalent to *(p+i-1).

And ptcnt is not a pointer but then it's not being used as one. It's simply used as the terminating condition of i in the for loop.

That seems perfectly acceptable to me. Perhaps I'm missing something.

From examination of the code, it looks like it's trying to calculate a minimum distance of some description.

Describing in more detail what the lines in question do:

ptcnt = *(InfoType*)line;

This casts the passed-in parameter to a double pointer (assuming your description of the type is correct) then dereferences it. In other words, it gets the double stored in the first few bytes of line.

p = (lPoint*)&line[InfoSize];

This one gets an address of a double array starting InfoSize bytes in from the start of line.

paxdiablo
A: 
line;                         // char*
(InfoType*)line;              // casts line to an Infotype*
*(InfoType*)line;             // dereferences line as though it were an Infotype*

ptcnt = *(InfoType*)line;     // assigns the value of the dereferenced pointer to ptcnt.
                              // Since ptcnt is of type Infotype, this makes sense
PigBen