[GRASS-SVN] r64032 - grass/trunk/lib/vector/Vlib
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jan 9 12:03:02 PST 2015
Author: mmetz
Date: 2015-01-09 12:03:02 -0800 (Fri, 09 Jan 2015)
New Revision: 64032
Modified:
grass/trunk/lib/vector/Vlib/poly.c
Log:
Vlib: optimize Vect_point_in_area_outer_ring() and Vect_point_in_island()
Modified: grass/trunk/lib/vector/Vlib/poly.c
===================================================================
--- grass/trunk/lib/vector/Vlib/poly.c 2015-01-09 15:10:33 UTC (rev 64031)
+++ grass/trunk/lib/vector/Vlib/poly.c 2015-01-09 20:03:02 UTC (rev 64032)
@@ -558,8 +558,12 @@
x2 = Points->x[n];
y2 = Points->y[n];
+ /* G_debug() is slow, avoid it in loops over points,
+ * activate when needed */
+ /*
G_debug(3, "X = %f Y = %f x1 = %f y1 = %f x2 = %f y2 = %f", X, Y, x1,
y1, x2, y2);
+ */
/* I know, it should be possible to do that with less conditions,
* but it should be enough readable also! */
@@ -692,7 +696,6 @@
int n_intersects, inter;
int i, line;
static struct line_pnts *Points;
- struct bound_box lbox;
const struct Plus_head *Plus;
struct P_area *Area;
@@ -717,20 +720,20 @@
line = abs(Area->lines[i]);
G_debug(3, " line[%d] = %d", i, line);
- /* this is slow, but the fastest of all alternatives */
- Vect_get_line_box(Map, line, &lbox);
+ Vect_read_line(Map, Points, NULL, line);
- /* slower as long as the spatial index is in memory: */
- /*
- Vect_read_line(Map, Points, NULL, line);
- Vect_line_box(Points, &lbox);
- */
-
- /* dont check lines that obviously do not intersect with test ray */
- if ((lbox.N < Y) || (lbox.S > Y) || (lbox.E < X))
+ /* if the bbox of the line would be available,
+ * the bbox could be used for a first check: */
+
+ /* Vect_line_box(Points, &lbox);
+ * do not check lines that obviously do not intersect with test ray */
+ /* if ((lbox.N < Y) || (lbox.S > Y) || (lbox.E < X))
continue;
+ */
- Vect_read_line(Map, Points, NULL, line);
+ /* retrieving the bbox from the spatial index or
+ * calculating the box from the vertices is slower than
+ * just feeding the line to segments_x_ray() */
inter = segments_x_ray(X, Y, Points);
G_debug(3, " inter = %d", inter);
@@ -765,7 +768,6 @@
int n_intersects, inter;
int i, line;
static struct line_pnts *Points;
- struct bound_box lbox;
const struct Plus_head *Plus;
struct P_isle *Isle;
@@ -786,20 +788,20 @@
for (i = 0; i < Isle->n_lines; i++) {
line = abs(Isle->lines[i]);
- /* this is slow, but the fastest of all alternatives */
- Vect_get_line_box(Map, line, &lbox);
+ Vect_read_line(Map, Points, NULL, line);
- /* slower as long as the spatial index is in memory: */
- /*
- Vect_read_line(Map, Points, NULL, line);
- Vect_line_box(Points, &lbox);
- */
-
- /* dont check lines that obviously do not intersect with test ray */
- if ((lbox.N < Y) || (lbox.S > Y) || (lbox.E < X))
+ /* if the bbox of the line would be available,
+ * the bbox could be used for a first check: */
+
+ /* Vect_line_box(Points, &lbox);
+ * dont check lines that obviously do not intersect with test ray */
+ /* if ((lbox.N < Y) || (lbox.S > Y) || (lbox.E < X))
continue;
+ */
- Vect_read_line(Map, Points, NULL, line);
+ /* retrieving the bbox from the spatial index or
+ * calculating the box from the vertices is slower than
+ * just feeding the line to segments_x_ray() */
inter = segments_x_ray(X, Y, Points);
if (inter == -1)
More information about the grass-commit
mailing list