Commit 916f536a authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

nbr_store_distance: check for lowest index

parent 4201790e
......@@ -228,10 +228,9 @@ struct gridsearch *gridsearch_create(unsigned n, const double *restrict lons, co
struct gridsearch *gs = (struct gridsearch *) Calloc(1, sizeof(struct gridsearch));
gs->n = n;
if ( n == 0 ) return gs;
gs->kdt = gs_create_kdtree(n, lons, lats);
gs->kdt = gs_create_kdtree(n, lons, lats);
return gs;
}
......@@ -423,14 +422,28 @@ struct pqueue *gridsearch_qnearest(struct gridsearch *gs, double lon, double lat
float point[3];
float range0 = gs_set_range(prange);
float range = range0;
struct pqueue *result = NULL;
LLtoXYZ_f(lon, lat, point);
struct pqueue *result = kd_qnearest(gs->kdt, point, &range, nnn, 3);
// printf("range %g %g %g %p\n", lon, lat, range, node);
if ( !(range < range0) ) result = NULL;
if ( prange ) *prange = range;
if ( gs )
{
result = kd_qnearest(gs->kdt, point, &range, nnn, 3);
// printf("range %g %g %g %p\n", lon, lat, range, node);
if ( !(range < range0) )
{
if ( result )
{
struct resItem *p;
while ( pqremove_min(result, &p) ) Free(p); // Free the result node taken from the heap
Free(result->d); // free the heap
Free(result); // and free the heap information structure
}
result = NULL;
}
if ( prange ) *prange = range;
}
return result;
}
......@@ -33,7 +33,7 @@ void nbr_store_distance(int nadd, double distance, int num_neighbors, int *restr
int n, nchk;
for ( nchk = 0; nchk < num_neighbors; ++nchk )
{
if ( distance < nbr_dist[nchk] )
if ( distance < nbr_dist[nchk] || (distance <= nbr_dist[nchk] && nadd < nbr_add[nchk]) )
{
for ( n = num_neighbors-1; n > nchk; --n )
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment