25 #include <grass/gis.h>
27 #define BIG_NUM (FLT_MAX/4.0)
30 #define Undefined(x) ((x)->boundary[0] > (x)->boundary[NUMDIMS])
31 #define MIN(a, b) ((a) < (b) ? (a) : (b))
32 #define MAX(a, b) ((a) > (b) ? (a) : (b))
40 register struct Rect *
r = R;
71 void RTreeRandomRect(
struct Rect *R)
73 register struct Rect *
r = R;
80 width = drand48() * (1000 / 4) + 1;
98 void RTreeSearchRect(
struct Rect *Search,
struct Rect *Data)
100 register struct Rect *search = Search, *
data = Data;
107 for (i = 0; i <
NUMDIMS; i++) {
109 if (data->boundary[i] > -
BIG_NUM && data->boundary[j] <
BIG_NUM) {
110 size = (drand48() * (data->boundary[j] -
111 data->boundary[i] + 1)) / 2;
112 center = data->boundary[i] + drand48() *
113 (data->boundary[j] - data->boundary[i] + 1);
114 search->
boundary[i] = center - size / 2;
115 search->
boundary[j] = center + size / 2;
132 register struct Rect *r = R;
138 fprintf(stdout,
"rect:\n");
139 for (i = 0; i <
NUMDIMS; i++) {
150 register struct Rect *r = R;
160 assert(volume >= 0.0);
180 double log_gamma, log_volume;
182 log_gamma = gamma(dimension / 2.0 + 1);
183 log_volume = dimension / 2.0 *
log(M_PI) - log_gamma;
184 return exp(log_volume);
216 # error "not enough precomputed sphere volumes"
218 #define UnitSphereVolume UnitSphereVolumes[NUMDIMS]
234 register struct Rect *r = R;
241 for (i = 0; i <
NUMDIMS; i++) {
243 if (c_size > maxsize)
255 register struct Rect *r = R;
257 register double sum_of_squares = 0, radius;
262 for (i = 0; i <
NUMDIMS; i++) {
265 sum_of_squares += half_extent * half_extent;
267 radius = sqrt(sum_of_squares);
277 register struct Rect *r = R;
285 for (i = 0; i <
NUMDIMS; i++) {
293 face_area *= j_extent;
307 register struct Rect *r = R, *rr = Rr;
309 struct Rect new_rect;
319 for (i = 0; i <
NUMDIMS; i++) {
333 register struct Rect *r = R, *
s = S;
338 for (i = 0; i <
NUMDIMS; i++) {
340 if (r->
boundary[i] > s->boundary[j] ||
354 register struct Rect *r = R, *
s = S;
355 register int i, j, result;
368 for (i = 0; i <
NUMDIMS; i++) {
370 result = result && r->
boundary[i] >= s->boundary[i]
371 && r->
boundary[j] <= s->boundary[j];
RectReal boundary[NUMSIDES]
RectReal RTreeRectSphericalVolume(struct Rect *R)
int RTreeContained(struct Rect *R, struct Rect *S)
RectReal RTreeRectVolume(struct Rect *R)
double sphere_volume(double dimension)
void RTreeInitRect(struct Rect *)
int RTreeOverlap(struct Rect *, struct Rect *)
void RTreePrintRect(struct Rect *, int)
const double UnitSphereVolumes[]
struct Rect RTreeNullRect(void)
struct Rect RTreeCombineRect(struct Rect *, struct Rect *)
RectReal RTreeRectSurfaceArea(struct Rect *R)