27 #define BIG_NUM (FLT_MAX / 4.0)
29 #define Undefined(x, t) ((x)->boundary[0] > (x)->boundary[t->ndims_alloc])
113 for (i = 0; i <
t->ndims_alloc; i++)
114 r->boundary[i] =
r->boundary[i +
t->ndims_alloc] = (
RectReal)0;
133 r->boundary[
t->ndims_alloc] = (
RectReal)x_max;
150 double x_max,
double y_min,
double y_max)
154 r->boundary[
t->ndims_alloc] = (
RectReal)x_max;
156 r->boundary[1 +
t->ndims_alloc] = (
RectReal)y_max;
175 double x_max,
double y_min,
double y_max,
double z_min,
180 r->boundary[
t->ndims_alloc] = (
RectReal)x_max;
182 r->boundary[1 +
t->ndims_alloc] = (
RectReal)y_max;
184 r->boundary[2 +
t->ndims_alloc] = (
RectReal)z_max;
205 double x_max,
double y_min,
double y_max,
double z_min,
206 double z_max,
double t_min,
double t_max)
212 r->boundary[
t->ndims_alloc] = (
RectReal)x_max;
214 r->boundary[1 +
t->ndims_alloc] = (
RectReal)y_max;
216 r->boundary[2 +
t->ndims_alloc] = (
RectReal)z_max;
218 r->boundary[3 +
t->ndims_alloc] = (
RectReal)t_max;
232 r->boundary[
t->nsides_alloc - 1] = (
RectReal)-1;
233 for (i = 1; i <
t->ndims_alloc; i++)
234 r->boundary[i] =
r->boundary[i +
t->ndims_alloc] = (
RectReal)0;
251 for (i = 0; i < NUMDIMS; i++) {
254 width = drand48() * (1000 / 4) + 1;
258 r->boundary[i] = drand48() * (1000 - width);
259 r->boundary[i + NUMDIMS] =
r->boundary[i] + width;
274 register struct RTree_Rect *search = Search, *data = Data;
281 for (i = 0; i < NUMDIMS; i++) {
283 if (data->boundary[i] > -
BIG_NUM && data->boundary[j] <
BIG_NUM) {
284 size = (drand48() * (data->boundary[j] -
285 data->boundary[i] + 1)) / 2;
286 center = data->boundary[i] + drand48() *
287 (data->boundary[j] - data->boundary[i] + 1);
288 search->
boundary[i] = center - size / 2;
289 search->
boundary[j] = center + size / 2;
312 fprintf(stdout,
"rect:\n");
313 for (i = 0; i <
t->ndims_alloc; i++) {
315 fprintf(stdout,
"%f\t%f\n",
r->boundary[i],
316 r->boundary[i +
t->ndims_alloc]);
334 for (i = 0; i <
t->ndims; i++)
335 volume *=
r->boundary[i +
t->ndims_alloc] -
r->boundary[i];
356 double log_gamma, log_volume;
358 log_gamma = gamma(dimension / 2.0 + 1);
359 log_volume = dimension / 2.0 * log(
M_PI) - log_gamma;
360 return exp(log_volume);
393 #error "not enough precomputed sphere volumes"
395 #define UnitSphereVolume UnitSphereVolumes[NUMDIMS]
419 for (i = 0; i <
t->ndims; i++) {
420 c_size =
r->boundary[i + NUMDIMS] -
r->boundary[i];
421 if (c_size > maxsize)
424 return (
RectReal) (pow(maxsize / 2, NUMDIMS) *
435 double sum_of_squares = 0, extent;
442 for (i = 0; i <
t->ndims; i++) {
443 extent = (
r->boundary[i +
t->ndims_alloc] -
r->boundary[i]);
446 sum_of_squares += extent * extent / 4.;
449 return (
RectReal)(pow(sqrt(sum_of_squares),
t->ndims) *
466 for (i = 0; i <
t->ndims; i++) {
469 for (j = 0; j <
t->ndims; j++)
472 face_area *= (
r->boundary[j +
t->ndims_alloc] -
r->boundary[j]);
490 for (i = 0; i <
t->ndims; i++) {
491 margin +=
r->boundary[i +
t->ndims_alloc] -
r->boundary[i];
508 for (i = 0; i <
t->nsides_alloc; i++)
515 for (i = 0; i <
t->nsides_alloc; i++)
521 for (i = 0; i <
t->ndims; i++) {
523 j = i +
t->ndims_alloc;
526 for (i =
t->ndims; i < t->ndims_alloc; i++) {
528 j = i +
t->ndims_alloc;
546 for (i = 0; i <
t->ndims; i++) {
551 j = i +
t->ndims_alloc;
558 for (i =
t->ndims; i < t->ndims_alloc; i++) {
560 j = i +
t->ndims_alloc;
577 for (i = 0; i <
t->ndims; i++) {
578 j = i +
t->ndims_alloc;
596 for (i = 0; i <
t->ndims; i++) {
597 j = i +
t->ndims_alloc;
623 for (i = 0; i <
t->ndims; i++) {
624 j = i +
t->ndims_alloc;
648 for (i = 0; i <
t->ndims; i++) {
649 j = i +
t->ndims_alloc;
double sphere_volume(double dimension)
#define assert(condition)
RectReal * RTreeAllocBoundary(struct RTree *t)
Allocate the boundary array of a rectangle for a given tree.
void RTreeFreeRect(struct RTree_Rect *r)
Delete a rectangle.
void RTreeNullRect(struct RTree_Rect *r, struct RTree *t)
const double UnitSphereVolumes[]
void RTreeCombineRect(struct RTree_Rect *r1, struct RTree_Rect *r2, struct RTree_Rect *r3, struct RTree *t)
struct RTree_Rect * RTreeAllocRect(struct RTree *t)
Create a new rectangle for a given tree.
RectReal RTreeRectVolume(struct RTree_Rect *R, struct RTree *t)
void RTreeFreeBoundary(struct RTree_Rect *r)
Delete the boundary of a rectangle.
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.
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.
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.
void RTreeInitRect(struct RTree_Rect *r, struct RTree *t)
Initialize a rectangle to have all 0 coordinates.
int RTreeContains(struct RTree_Rect *r, struct RTree_Rect *s, struct RTree *t)
RectReal RTreeRectSurfaceArea(struct RTree_Rect *r, struct RTree *t)
int RTreeExpandRect(struct RTree_Rect *r1, struct RTree_Rect *r2, struct RTree *t)
RectReal RTreeRectMargin(struct RTree_Rect *r, 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 RTreeCompareRect(struct RTree_Rect *r, struct RTree_Rect *s, struct RTree *t)
void RTreePrintRect(struct RTree_Rect *R, int depth, struct RTree *t)
RectReal RTreeRectSphericalVolume(struct RTree_Rect *r, struct RTree *t)
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.