Просмотр исходного кода

Vlib: optimize Vect_find_area(), add comments

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@64203 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 10 лет назад
Родитель
Сommit
76d0db9f16
1 измененных файлов с 12 добавлено и 2 удалено
  1. 12 2
      lib/vector/Vlib/find.c

+ 12 - 2
lib/vector/Vlib/find.c

@@ -287,7 +287,13 @@ int Vect_find_area(struct Map_info *Map, double x, double y)
     Vect_select_areas_by_box(Map, &box, List);
     G_debug(3, "  %d areas selected by box", List->n_values);
 
-    /* sort areas by size, the smallest is likely to be the nearest */
+    /* sort areas by bbox size
+     * get the smallest area that contains the point
+     * using the bbox size is working because if 2 areas both contain
+     * the point, one of these areas must be inside the other area
+     * which means that the bbox of the outer area must be larger than
+     * the bbox of the inner area, and equal bbox sizes are not possible */
+
     if (alloc_size_list < List->n_values) {
 	alloc_size_list = List->n_values;
 	size_list = G_realloc(size_list, alloc_size_list * sizeof(BOX_SIZE));
@@ -314,7 +320,9 @@ int Vect_find_area(struct Map_info *Map, double x, double y)
 
     for (i = 0; i < List->n_values; i++) {
 	area = size_list[i].i;
-	ret = Vect_point_in_area(x, y, Map, area, &size_list[i].box);
+	/* testing only the outer ring is sufficient because 
+	 * inner rings have been tested earlier (sorted list) */
+	ret = Vect_point_in_area_outer_ring(x, y, Map, area, &size_list[i].box);
 
 	G_debug(3, "    area = %d Vect_point_in_area() = %d", area, ret);
 
@@ -342,6 +350,8 @@ int Vect_find_island(struct Map_info *Map, double x, double y)
     static struct boxlist *List;
     static struct line_pnts *Points;
 
+    /* TODO: sync to Vect_find_area() */
+
     G_debug(3, "Vect_find_island() x = %f y = %f", x, y);
 
     if (first) {