GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-d6dec75dd4
rect.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "index.h"
#include <float.h>
#include <math.h>
#include <grass/gis.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 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.

◆ Undefined

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

Definition at line 29 of file rect.c.

◆ UnitSphereVolume

#define UnitSphereVolume   UnitSphereVolumes[NUMDIMS]

Definition at line 395 of file rect.c.

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 81 of file rect.c.

References assert, RTree_Rect::boundary, malloc(), and t.

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 42 of file rect.c.

References assert, malloc(), r, RTreeAllocBoundary(), and t.

◆ RTreeCombineRect()

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

Definition at line 500 of file rect.c.

References RTree_Rect::boundary, MAX, MIN, t, and Undefined.

◆ RTreeCompareRect()

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

Definition at line 570 of file rect.c.

◆ RTreeContained()

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

Definition at line 609 of file rect.c.

◆ RTreeContains()

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

Definition at line 634 of file rect.c.

◆ RTreeExpandRect()

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

Definition at line 536 of file rect.c.

References RTree_Rect::boundary, t, 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 98 of file rect.c.

References assert, free(), NULL, and r.

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 63 of file rect.c.

References assert, free(), r, and RTreeFreeBoundary().

◆ RTreeInitRect()

void RTreeInitRect ( struct RTree_Rect r,
struct RTree t 
)

Initialize a rectangle to have all 0 coordinates.

Definition at line 109 of file rect.c.

References r, and t.

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

◆ RTreeNullRect()

void RTreeNullRect ( struct RTree_Rect r,
struct RTree t 
)

Definition at line 225 of file rect.c.

References r, and t.

Referenced by RTreeInitPVars().

◆ RTreeOverlap()

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

Definition at line 590 of file rect.c.

◆ RTreePrintRect()

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

Definition at line 304 of file rect.c.

◆ RTreeRectMargin()

RectReal RTreeRectMargin ( struct RTree_Rect r,
struct RTree t 
)

Definition at line 483 of file rect.c.

References r, and t.

◆ RTreeRectSphericalVolume()

RectReal RTreeRectSphericalVolume ( struct RTree_Rect r,
struct RTree t 
)

Definition at line 432 of file rect.c.

References r, t, Undefined, and UnitSphereVolumes.

◆ RTreeRectSurfaceArea()

RectReal RTreeRectSurfaceArea ( struct RTree_Rect r,
struct RTree t 
)

Definition at line 456 of file rect.c.

References r, t, and Undefined.

◆ RTreeRectVolume()

RectReal RTreeRectVolume ( struct RTree_Rect R,
struct RTree t 
)

Definition at line 323 of file rect.c.

References assert, r, t, and Undefined.

◆ 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 128 of file rect.c.

References r, RTreeInitRect(), and t.

◆ 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 149 of file rect.c.

References r, RTreeInitRect(), and t.

◆ 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 174 of file rect.c.

References r, RTreeInitRect(), and t.

◆ 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 204 of file rect.c.

References assert, r, RTreeInitRect(), and t.

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 368 of file rect.c.

Referenced by RTreeRectSphericalVolume().