GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
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

◆ BIG_NUM

#define BIG_NUM   (FLT_MAX/4.0)

Definition at line 27 of file rect.c.

◆ MAX

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

Definition at line 32 of file rect.c.

Referenced by RTreeCombineRect().

◆ MIN

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

Definition at line 31 of file rect.c.

Referenced by RTreeCombineRect().

◆ Undefined

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

◆ UnitSphereVolume

#define UnitSphereVolume   UnitSphereVolumes[NUMDIMS]

Definition at line 397 of file rect.c.

Referenced by RTreeRectVolume().

Function Documentation

◆ RTreeAllocBoundary()

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 assert, RTree_Rect::boundary, malloc(), and RTree::rectsize.

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

◆ RTreeAllocRect()

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 assert, RTree_Rect::boundary, malloc(), r, and RTreeAllocBoundary().

◆ RTreeCombineRect()

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

◆ RTreeCompareRect()

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

Definition at line 577 of file rect.c.

◆ RTreeContained()

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

Definition at line 617 of file rect.c.

◆ RTreeContains()

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

Definition at line 644 of file rect.c.

◆ RTreeExpandRect()

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().

◆ RTreeFreeBoundary()

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 assert, RTree_Rect::boundary, free(), and NULL.

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

◆ 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 assert, free(), and RTreeFreeBoundary().

◆ RTreeInitRect()

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().

◆ RTreeNullRect()

void RTreeNullRect ( struct RTree_Rect r,
struct RTree t 
)

Definition at line 227 of file rect.c.

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

Referenced by RTreeInitPVars().

◆ RTreeOverlap()

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

Definition at line 597 of file rect.c.

◆ RTreePrintRect()

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

Definition at line 307 of file rect.c.

Referenced by RTreePrintNode().

◆ RTreeRectMargin()

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.

◆ RTreeRectSphericalVolume()

RectReal RTreeRectSphericalVolume ( struct RTree_Rect r,
struct RTree t 
)

◆ RTreeRectSurfaceArea()

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.

◆ RTreeRectVolume()

RectReal RTreeRectVolume ( struct RTree_Rect R,
struct RTree t 
)

◆ RTreeSetRect1D()

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().

◆ RTreeSetRect2D()

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().

◆ RTreeSetRect3D()

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().

◆ RTreeSetRect4D()

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 assert, RTree_Rect::boundary, RTree::ndims, RTree::ndims_alloc, and RTreeInitRect().

Variable Documentation

◆ UnitSphereVolumes

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.

Referenced by RTreeRectSphericalVolume().