GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71806
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rect.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "index.h"
#include <float.h>
#include <math.h>
Include dependency graph for rect.c:

Go to the source code of this file.

Macros

#define BIG_NUM   (FLT_MAX/4.0)
 
#define Undefined(x, t)   ((x)->boundary[0] > (x)->boundary[t->ndims_alloc])
 
#define MIN(a, b)   ((a) < (b) ? (a) : (b))
 
#define MAX(a, b)   ((a) > (b) ? (a) : (b))
 
#define UnitSphereVolume   UnitSphereVolumes[NUMDIMS]
 

Functions

struct RTree_RectRTreeAllocRect (struct RTree *t)
 Create a new rectangle for a given tree. More...
 
void RTreeFreeRect (struct RTree_Rect *r)
 Delete a rectangle. More...
 
RectRealRTreeAllocBoundary (struct RTree *t)
 Allocate the boundary array of a rectangle for a given tree. More...
 
void RTreeFreeBoundary (struct RTree_Rect *r)
 Delete the boundary of a rectangle. More...
 
void RTreeInitRect (struct RTree_Rect *r, struct RTree *t)
 Initialize a rectangle to have all 0 coordinates. More...
 
void RTreeSetRect1D (struct RTree_Rect *r, struct RTree *t, double x_min, double x_max)
 Set one dimensional coordinates of a rectangle for a given tree. More...
 
void RTreeSetRect2D (struct RTree_Rect *r, struct RTree *t, double x_min, double x_max, double y_min, double y_max)
 Set two dimensional coordinates of a rectangle for a given tree. More...
 
void RTreeSetRect3D (struct RTree_Rect *r, struct RTree *t, double x_min, double x_max, double y_min, double y_max, double z_min, double z_max)
 Set three dimensional coordinates of a rectangle for a given tree. More...
 
void RTreeSetRect4D (struct RTree_Rect *r, struct RTree *t, double x_min, double x_max, double y_min, double y_max, double z_min, double z_max, double t_min, double t_max)
 Set 4 dimensional coordinates of a rectangle for a given tree. More...
 
void RTreeNullRect (struct RTree_Rect *r, struct RTree *t)
 
void RTreePrintRect (struct RTree_Rect *R, int depth, struct RTree *t)
 
RectReal RTreeRectVolume (struct RTree_Rect *R, struct RTree *t)
 
RectReal RTreeRectSphericalVolume (struct RTree_Rect *r, struct RTree *t)
 
RectReal RTreeRectSurfaceArea (struct RTree_Rect *r, struct RTree *t)
 
RectReal RTreeRectMargin (struct RTree_Rect *r, struct RTree *t)
 
void RTreeCombineRect (struct RTree_Rect *r1, struct RTree_Rect *r2, struct RTree_Rect *r3, struct RTree *t)
 
int RTreeExpandRect (struct RTree_Rect *r1, struct RTree_Rect *r2, struct RTree *t)
 
int RTreeCompareRect (struct RTree_Rect *r, struct RTree_Rect *s, struct RTree *t)
 
int RTreeOverlap (struct RTree_Rect *r, struct RTree_Rect *s, struct RTree *t)
 
int RTreeContained (struct RTree_Rect *r, struct RTree_Rect *s, struct RTree *t)
 
int RTreeContains (struct RTree_Rect *r, struct RTree_Rect *s, struct RTree *t)
 

Variables

const double UnitSphereVolumes []
 

Macro Definition Documentation

#define BIG_NUM   (FLT_MAX/4.0)

Definition at line 27 of file rect.c.

#define MAX (   a,
  b 
)    ((a) > (b) ? (a) : (b))

Definition at line 32 of file rect.c.

Referenced by RTreeCombineRect().

#define MIN (   a,
  b 
)    ((a) < (b) ? (a) : (b))

Definition at line 31 of file rect.c.

Referenced by RTreeCombineRect().

#define Undefined (   x,
  t 
)    ((x)->boundary[0] > (x)->boundary[t->ndims_alloc])
#define UnitSphereVolume   UnitSphereVolumes[NUMDIMS]

Definition at line 397 of file rect.c.

Function Documentation

RectReal* RTreeAllocBoundary ( struct RTree t)

Allocate the boundary array of a rectangle for a given tree.

This method allocated the boundary coordinates array in provided rectangle. It does not release previously allocated memory.

Parameters
rThe pointer to rectangle to initialize the boundary coordinates. This is usually a rectangle that was created on the stack or self allocated.
tThe pointer to a RTree struct

Definition at line 84 of file rect.c.

References RTree_Rect::boundary, malloc(), and RTree::rectsize.

Referenced by RTreeAllocNode(), RTreeAllocRect(), and RTreeCreateTree().

struct RTree_Rect* RTreeAllocRect ( struct RTree t)

Create a new rectangle for a given tree.

This method allocates a new rectangle and initializes the internal boundary coordinates based on the tree dimension.

Hence a call to RTreeNewBoundary() is not necessary.

Parameters
tThe pointer to a RTree struct
Returns
A new allocated RTree_Rect struct

Definition at line 45 of file rect.c.

References RTree_Rect::boundary, malloc(), r, and RTreeAllocBoundary().

void RTreeCombineRect ( struct RTree_Rect r1,
struct RTree_Rect r2,
struct RTree_Rect r3,
struct RTree t 
)

Definition at line 505 of file rect.c.

References RTree_Rect::boundary, MAX, MIN, RTree::ndims, RTree::ndims_alloc, RTree::nsides_alloc, and Undefined.

Referenced by RTreePickBranch().

int RTreeCompareRect ( struct RTree_Rect r,
struct RTree_Rect s,
struct RTree t 
)

Definition at line 577 of file rect.c.

References RTree_Rect::boundary, RTree::ndims, and RTree::ndims_alloc.

int RTreeContained ( struct RTree_Rect r,
struct RTree_Rect s,
struct RTree t 
)

Definition at line 617 of file rect.c.

References RTree_Rect::boundary, FALSE, RTree::ndims, RTree::ndims_alloc, TRUE, and Undefined.

int RTreeContains ( struct RTree_Rect r,
struct RTree_Rect s,
struct RTree t 
)

Definition at line 644 of file rect.c.

References RTree_Rect::boundary, FALSE, RTree::ndims, RTree::ndims_alloc, TRUE, and Undefined.

int RTreeExpandRect ( struct RTree_Rect r1,
struct RTree_Rect r2,
struct RTree t 
)

Definition at line 542 of file rect.c.

References RTree_Rect::boundary, RTree::ndims, RTree::ndims_alloc, and Undefined.

Referenced by RTreeNodeCover().

void RTreeFreeBoundary ( struct RTree_Rect r)

Delete the boundary of a rectangle.

This method deletes (free) the memory of the boundary of a rectangle and sets the boundary pointer to NULL.

Parameters
rThe pointer to the rectangle to delete the boundary from.

Definition at line 101 of file rect.c.

References RTree_Rect::boundary, free(), and NULL.

Referenced by RTreeDestroyTree(), RTreeFreeListBranch(), RTreeFreeNode(), and RTreeFreeRect().

void RTreeFreeRect ( struct RTree_Rect r)

Delete a rectangle.

This method deletes (free) the allocated memory of a rectangle.

Parameters
rThe pointer to the rectangle to be deleted

Definition at line 66 of file rect.c.

References free(), and RTreeFreeBoundary().

void RTreeInitRect ( struct RTree_Rect r,
struct RTree t 
)

Initialize a rectangle to have all 0 coordinates.

Definition at line 112 of file rect.c.

References RTree_Rect::boundary, and RTree::ndims_alloc.

Referenced by RTreeSetRect1D(), RTreeSetRect2D(), RTreeSetRect3D(), and RTreeSetRect4D().

void RTreeNullRect ( struct RTree_Rect r,
struct RTree t 
)

Definition at line 227 of file rect.c.

References RTree_Rect::boundary, RTree::ndims_alloc, and RTree::nsides_alloc.

Referenced by RTreeInitPVars().

int RTreeOverlap ( struct RTree_Rect r,
struct RTree_Rect s,
struct RTree t 
)

Definition at line 597 of file rect.c.

References RTree_Rect::boundary, FALSE, RTree::ndims, RTree::ndims_alloc, and TRUE.

Referenced by rtree_search(), RTreeSearchF(), and RTreeSearchM().

void RTreePrintRect ( struct RTree_Rect R,
int  depth,
struct RTree t 
)

Definition at line 307 of file rect.c.

References RTree_Rect::boundary, RTree::ndims_alloc, and RTreeTabIn().

Referenced by RTreePrintNode().

RectReal RTreeRectMargin ( struct RTree_Rect r,
struct RTree t 
)

Definition at line 487 of file rect.c.

References RTree_Rect::boundary, RTree::ndims, and RTree::ndims_alloc.

RectReal RTreeRectSphericalVolume ( struct RTree_Rect r,
struct RTree t 
)

Definition at line 435 of file rect.c.

References RTree_Rect::boundary, RTree::ndims, RTree::ndims_alloc, and Undefined.

Referenced by RTreePickBranch().

RectReal RTreeRectSurfaceArea ( struct RTree_Rect r,
struct RTree t 
)

Definition at line 459 of file rect.c.

References RTree_Rect::boundary, RTree::ndims, RTree::ndims_alloc, and Undefined.

RectReal RTreeRectVolume ( struct RTree_Rect R,
struct RTree t 
)

Definition at line 325 of file rect.c.

References RTree_Rect::boundary, RTree::ndims, RTree::ndims_alloc, and Undefined.

void RTreeSetRect1D ( struct RTree_Rect r,
struct RTree t,
double  x_min,
double  x_max 
)

Set one dimensional coordinates of a rectangle for a given tree.

All coordinates of the rectangle will be initialized to 0 before the x coordinates are set.

Parameters
rThe pointer to the rectangle
tThe pointer to the RTree
x_minThe lower x coordinate
x_maxThe higher x coordinate

Definition at line 131 of file rect.c.

References RTree_Rect::boundary, RTree::ndims_alloc, and RTreeInitRect().

void RTreeSetRect2D ( struct RTree_Rect r,
struct RTree t,
double  x_min,
double  x_max,
double  y_min,
double  y_max 
)

Set two dimensional coordinates of a rectangle for a given tree.

All coordinates of the rectangle will be initialized to 0 before the x and y coordinates are set.

Parameters
rThe pointer to the rectangle
tThe pointer to the RTree
x_minThe lower x coordinate
x_maxThe higher x coordinate
y_minThe lower y coordinate
y_maxThe higher y coordinate

Definition at line 152 of file rect.c.

References RTree_Rect::boundary, RTree::ndims_alloc, and RTreeInitRect().

void RTreeSetRect3D ( struct RTree_Rect r,
struct RTree t,
double  x_min,
double  x_max,
double  y_min,
double  y_max,
double  z_min,
double  z_max 
)

Set three dimensional coordinates of a rectangle for a given tree.

All coordinates of the rectangle will be initialized to 0 before the x,y and z coordinates are set.

Parameters
rThe pointer to the rectangle
tThe pointer to the RTree
x_minThe lower x coordinate
x_maxThe higher x coordinate
y_minThe lower y coordinate
y_maxThe higher y coordinate
z_minThe lower z coordinate
z_maxThe higher z coordinate

Definition at line 177 of file rect.c.

References RTree_Rect::boundary, RTree::ndims_alloc, and RTreeInitRect().

void RTreeSetRect4D ( struct RTree_Rect r,
struct RTree t,
double  x_min,
double  x_max,
double  y_min,
double  y_max,
double  z_min,
double  z_max,
double  t_min,
double  t_max 
)

Set 4 dimensional coordinates of a rectangle for a given tree.

All coordinates of the rectangle will be initialized to 0 before the x,y,z and t coordinates are set.

Parameters
rThe pointer to the rectangle
tThe pointer to the RTree
x_minThe lower x coordinate
x_maxThe higher x coordinate
y_minThe lower y coordinate
y_maxThe higher y coordinate
z_minThe lower z coordinate
z_maxThe higher z coordinate
t_minThe lower t coordinate
t_maxThe higher t coordinate

Definition at line 207 of file rect.c.

References RTree_Rect::boundary, RTree::ndims, RTree::ndims_alloc, and RTreeInitRect().

Variable Documentation

const double UnitSphereVolumes[]
Initial value:
= {
0.000000,
2.000000,
3.141593,
4.188790,
4.934802,
5.263789,
5.167713,
4.724766,
4.058712,
3.298509,
2.550164,
1.884104,
1.335263,
0.910629,
0.599265,
0.381443,
0.235331,
0.140981,
0.082146,
0.046622,
0.025807,
}

Definition at line 370 of file rect.c.