[GRASS-SVN] r52519 - grass/trunk/lib/vector/rtree
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Aug 4 11:21:35 PDT 2012
Author: mmetz
Date: 2012-08-04 11:21:34 -0700 (Sat, 04 Aug 2012)
New Revision: 52519
Modified:
grass/trunk/lib/vector/rtree/index.c
grass/trunk/lib/vector/rtree/index.h
grass/trunk/lib/vector/rtree/rect.c
grass/trunk/lib/vector/rtree/rtree.h
Log:
rtree: prepare for future modifications
Modified: grass/trunk/lib/vector/rtree/index.c
===================================================================
--- grass/trunk/lib/vector/rtree/index.c 2012-08-04 18:19:10 UTC (rev 52518)
+++ grass/trunk/lib/vector/rtree/index.c 2012-08-04 18:21:34 UTC (rev 52519)
@@ -207,9 +207,15 @@
* Search in an index tree for all data retangles that
* overlap or touch the argument rectangle.
* Return the number of qualifying data rects.
+ *
+ * add option to select operator to select rectangles ?
+ * current: overlap
+ * possible alternatives:
+ * - select all rectangles that are fully contained in r
+ * - select all rectangles that fully contain r
*/
-int RTreeSearch(struct RTree *t, struct RTree_Rect *r, SearchHitCallback *shcb,
- void *cbarg)
+int RTreeSearch(struct RTree *t, struct RTree_Rect *r,
+ SearchHitCallback *shcb, void *cbarg)
{
assert(r && t);
Modified: grass/trunk/lib/vector/rtree/index.h
===================================================================
--- grass/trunk/lib/vector/rtree/index.h 2012-08-04 18:19:10 UTC (rev 52518)
+++ grass/trunk/lib/vector/rtree/index.h 2012-08-04 18:21:34 UTC (rev 52519)
@@ -59,15 +59,15 @@
void RTreeFreeListBranch(struct RTree_ListBranch *);
/* indexm.c */
-int RTreeSearchM(struct RTree *, struct RTree_Rect *, SearchHitCallback *,
- void *);
+int RTreeSearchM(struct RTree *, struct RTree_Rect *,
+ SearchHitCallback *, void *);
int RTreeInsertRectM(struct RTree_Rect *, union RTree_Child, int, struct RTree *);
int RTreeDeleteRectM(struct RTree_Rect *, union RTree_Child, struct RTree *);
int RTreeValidChildM(union RTree_Child *child);
/* indexf.c */
-int RTreeSearchF(struct RTree *, struct RTree_Rect *, SearchHitCallback *,
- void *);
+int RTreeSearchF(struct RTree *, struct RTree_Rect *,
+ SearchHitCallback *, void *);
int RTreeInsertRectF(struct RTree_Rect *, union RTree_Child, int, struct RTree *);
int RTreeDeleteRectF(struct RTree_Rect *, union RTree_Child, struct RTree *);
int RTreeValidChildF(union RTree_Child *);
Modified: grass/trunk/lib/vector/rtree/rect.c
===================================================================
--- grass/trunk/lib/vector/rtree/rect.c 2012-08-04 18:19:10 UTC (rev 52518)
+++ grass/trunk/lib/vector/rtree/rect.c 2012-08-04 18:21:34 UTC (rev 52519)
@@ -436,11 +436,11 @@
/*-----------------------------------------------------------------------------
-| Decide whether rectangle r is contained in rectangle s.
+| Decide whether rectangle s is contained in rectangle r.
-----------------------------------------------------------------------------*/
int RTreeContained(struct RTree_Rect *r, struct RTree_Rect *s, struct RTree *t)
{
- register int i, j, result;
+ register int i, j;
/* assert(r && s); */
@@ -452,11 +452,38 @@
if (Undefined(s, t))
return FALSE;
- result = TRUE;
for (i = 0; i < t->ndims; i++) {
j = i + t->ndims_alloc; /* index for high sides */
- result = result && r->boundary[i] >= s->boundary[i]
- && r->boundary[j] <= s->boundary[j];
+ if (s->boundary[i] < r->boundary[i] ||
+ s->boundary[j] > r->boundary[j])
+ return FALSE;
}
- return result;
+ return TRUE;
}
+
+
+/*-----------------------------------------------------------------------------
+| Decide whether rectangle s fully contains rectangle r.
+-----------------------------------------------------------------------------*/
+int RTreeContains(struct RTree_Rect *r, struct RTree_Rect *s, struct RTree *t)
+{
+ register int i, j;
+
+ /* assert(r && s); */
+
+ /* undefined rect is contained in any other */
+ if (Undefined(r, t))
+ return TRUE;
+
+ /* no rect (except an undefined one) is contained in an undef rect */
+ if (Undefined(s, t))
+ return FALSE;
+
+ for (i = 0; i < t->ndims; i++) {
+ j = i + t->ndims_alloc; /* index for high sides */
+ if (s->boundary[i] > r->boundary[i] ||
+ s->boundary[j] < r->boundary[j])
+ return FALSE;
+ }
+ return TRUE;
+}
Modified: grass/trunk/lib/vector/rtree/rtree.h
===================================================================
--- grass/trunk/lib/vector/rtree/rtree.h 2012-08-04 18:19:10 UTC (rev 52518)
+++ grass/trunk/lib/vector/rtree/rtree.h 2012-08-04 18:21:34 UTC (rev 52519)
@@ -195,13 +195,15 @@
};
/* RTree main functions */
-int RTreeSearch(struct RTree *, struct RTree_Rect *, SearchHitCallback *,
- void *);
+int RTreeSearch(struct RTree *, struct RTree_Rect *,
+ SearchHitCallback *, void *);
int RTreeInsertRect(struct RTree_Rect *, int, struct RTree *);
int RTreeDeleteRect(struct RTree_Rect *, int, struct RTree *);
struct RTree *RTreeNewIndex(int, off_t, int);
void RTreeFreeIndex(struct RTree *);
int RTreeOverlap(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
+int RTreeContained(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
+int RTreeContains(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
/* RTree node management */
struct RTree_Node *RTreeNewNode(struct RTree *, int);
More information about the grass-commit
mailing list