[GRASS-dev] Re: bug in Vect_cidx_find_next() ?
Moritz Lennert
mlennert at club.worldonline.be
Mon Oct 9 18:33:00 EDT 2006
Radim,
> Radim Blazek wrote:
>> To simplify use of cat index in modules I would suggest 2 new functions
>> (not tested/compiled):
>>
>> void Vect_cidx_find_lines ( struct Map_info *Map, int layer, int cat,
>> struct ilist *lines )
>> {
>> int type, line;
>> struct Cat_index *ci;
>>
>> Vect_reset_list ( lines );
>> int field_index = Vect_cidx_get_field_index ( Map, layer );
>> ci = &(Map->plus.cidx[field_index]);
>>
>> int idx = Vect_cidx_find_next ( Map, field_index, cat, 0,
>> GV_LINES|GV_POINTS, &type, &line );
This should be
int idx = Vect_cidx_find_next ( Map, field_index, cat, GV_LINES|GV_POINTS,
0,&type, &line );
>>
>> if ( idx == -1 ) return;
>>
>> do {
>> if ( !(ci->cat[idx][1] & GV_LINES|GV_POINTS)
>> || ci->cat[idx][0] != cat )
>
>
> Again, if Vect_cidx_find_next works correctly, how could this happen ?
> If it does this would be a bug in Vect_cidx_find_next, or ?
I understand now that this question was nonsense, please forget.
>
>> {
>> break;
>> }
>> Vect_list_append ( lines, ci->cat[idx][2] );
>> idx++;
>> } while ( idx < ci->n_cats );
>> return;
>> }
>>
I have tested above function and it seems to work well. Helps simplifying
my code...
>> and similarly Vect_cidx_find_areas
Would this similar function look like below ? If yes, why make this into a
separate function and not simply add a 'type' parameter to above function
which we could then call Vect_cidx_find_ojects_by_cat or something like
that ?
***proposal for Vect_cidx_find_areas**********
void Vect_cidx_find_areas ( struct Map_info *Map, int layer, int cat,
struct ilist *areas )
{
int type, line;
struct Cat_index *ci;
Vect_reset_list ( areas );
int field_index = Vect_cidx_get_field_index ( Map, layer );
ci = &(Map->plus.cidx[field_index]);
int idx = Vect_cidx_find_next ( Map, field_index, cat,
GV_AREA, 0, &type, &line );
if ( idx == -1 )
{
return;
}
do {
if ( !(ci->cat[idx][1] & GV_AREA)
|| ci->cat[idx][0] != cat )
{
break;
}
Vect_list_append ( areas, ci->cat[idx][2] );
idx++;
} while ( idx < ci->n_cats );
return;
}
Moritz
More information about the grass-dev
mailing list