The Cuik KD-Tree Library


rectangle.c File Reference

Implementation of the functions operating on Trectangle. More...

#include "rectangle.h"
#include "random.h"
#include "definitions.h"
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
+ Include dependency graph for rectangle.c:

Go to the source code of this file.

Functions

void InitRectangle (unsigned int dim, double *l, double *u, Trectangle *b)
 Initializes a rectangle. More...
 
void InitRectangleFromPoint (unsigned int dim, double *p, Trectangle *b)
 Initializes a rectangle from a point. More...
 
unsigned int GetRectangleDim (Trectangle *b)
 Returns the dimension of the rectangle. More...
 
void ExpandRectangle (double *p, Trectangle *b)
 Expands a rectangle so that it includes a given point. More...
 
double EnlargeRectangleWithLimits (double r, Trectangle *limits, Trectangle *bIn, Trectangle *bOut)
 Enlarges a box remaining in a given limits. More...
 
void CopyRectangle (Trectangle *b_out, Trectangle *b_in)
 Rectangle copy operator. More...
 
double GetRectangleLowerLimit (unsigned int i, Trectangle *b)
 Get the lower limit. More...
 
double GetRectangleUpperLimit (unsigned int i, Trectangle *b)
 Get the upper limit. More...
 
void GetRectangleLimits (unsigned int i, double *l, double *u, Trectangle *b)
 Gets the limits of the rectangle along a given dimension. More...
 
void SetRectangleLowerLimit (unsigned int i, double l, Trectangle *b)
 Set the lower limit. More...
 
void SetRectangleUpperLimit (unsigned int i, double u, Trectangle *b)
 Set the upper limit. More...
 
void SetRectangleLimits (unsigned int i, double l, double u, Trectangle *b)
 Changes a rectangle along a given dimension. More...
 
void RandomPointInRectangle (double *c, Trectangle *b)
 Returns the a random point along the selected dimensions. More...
 
double SquaredDistanceToRectangleDimension (unsigned int dim, double p, unsigned int *tp, Trectangle *b)
 Squared distance from a value to a given rectangle dimension. More...
 
double SquaredDistanceToRectangle (double t2, double *p, unsigned int *tp, Trectangle *b)
 Squared distance from a point to a rectangle. More...
 
unsigned int GetRectangleSplitDim (Trectangle *b)
 Computes the rectangle dimension for which it is better to split the rectangle. More...
 
void PrintRectangle (FILE *f, Trectangle *b)
 Prints a rectangle. More...
 
void DeleteRectangle (Trectangle *b)
 Destructor. More...
 

Detailed Description

Implementation of the functions operating on Trectangle.

See Also
rectangle.h, Trectangle.

Definition in file rectangle.c.

Function Documentation

void InitRectangle ( unsigned int  dim,
double *  l,
double *  u,
Trectangle b 
)

Creates a new rectangle with the given parameters.

Parameters
dimDimension of the new rectangle.
lLower limits.
uUpper limits.
bThe rectangle to initialize.

Definition at line 20 of file rectangle.c.

References Trectangle::l, Trectangle::n, NEWZ, and Trectangle::u.

Referenced by main().

+ Here is the caller graph for this function:

void InitRectangleFromPoint ( unsigned int  dim,
double *  p,
Trectangle b 
)

Creates a new rectangle with punctual intervals from a given vector.

Parameters
dimDimension of the new rectangle (i.e., number of intervals).
pThe point to use to initialize the rectangle.
bThe rectangle to initialize.

Definition at line 35 of file rectangle.c.

References Trectangle::l, Trectangle::n, NEW, and Trectangle::u.

Referenced by AddPoint2KDtree(), and BuildKDTree().

+ Here is the caller graph for this function:

unsigned int GetRectangleDim ( Trectangle b)
inline

Returns the number of ranges defining the rectangle.

Parameters
bThe rectangle to query.
Returns
The number of ranges in the rectangle.

Definition at line 47 of file rectangle.c.

References Trectangle::n.

Referenced by InitKDTree().

+ Here is the caller graph for this function:

void ExpandRectangle ( double *  p,
Trectangle b 
)

Expands a rectangle so that it includes a given point.

Parameters
pThe point.
bThe rectangle to modify.
See Also
ExpandInterval.

Definition at line 52 of file rectangle.c.

References Trectangle::l, Trectangle::n, and Trectangle::u.

Referenced by AddPoint2KDtree(), and BuildKDTree().

+ Here is the caller graph for this function:

double EnlargeRectangleWithLimits ( double  r,
Trectangle limits,
Trectangle bIn,
Trectangle bOut 
)

Adds a border to a box, but without scaping a given limits

Parameters
rSize of the border to add to the box.
limitsThe maximum limit for the box expansion. This box is assumed to fully include 'bIn'.
bInThe box to enlarge.
bOutThe output box.
Returns
The volume of the box after updating it.

Definition at line 68 of file rectangle.c.

References Trectangle::l, Trectangle::n, and Trectangle::u.

Referenced by AddPoint2KDtree(), and BuildKDTree().

+ Here is the caller graph for this function:

void CopyRectangle ( Trectangle b_out,
Trectangle b_in 
)

Copies one rectangle into another.

Parameters
b_outOutput rectangle. Rectangle constructed by the copy.
b_inInput rectangle. Rectangle used to create b_out.

Definition at line 91 of file rectangle.c.

References Trectangle::l, Trectangle::n, NEW, and Trectangle::u.

Referenced by AddPoint2KDtree(), and BuildKDTree().

+ Here is the caller graph for this function:

double GetRectangleLowerLimit ( unsigned int  i,
Trectangle b 
)
inline

Gets the lower limit along a given dimension.

Parameters
iThe dimension.
bThe rectagle to modify.
Returns
The lower limit.

Definition at line 101 of file rectangle.c.

References Trectangle::l.

double GetRectangleUpperLimit ( unsigned int  i,
Trectangle b 
)
inline

Gets the upper limit along a given dimension.

Parameters
iThe dimension.
bThe rectagle to modify.
Returns
The upper limit.

Definition at line 108 of file rectangle.c.

References Trectangle::u.

void GetRectangleLimits ( unsigned int  i,
double *  l,
double *  u,
Trectangle b 
)
inline

Gets the lower and upper limit of a rectangle along a given dimension.

Parameters
iThe dimension.
lThe lower limit (output).
uThe upper limit (output).
bThe rectagle to query.

Definition at line 115 of file rectangle.c.

References Trectangle::l, and Trectangle::u.

Referenced by BuildKDTree(), and InitKDTree().

+ Here is the caller graph for this function:

void SetRectangleLowerLimit ( unsigned int  i,
double  l,
Trectangle b 
)
inline

Set the lower limit along a given dimension.

Parameters
iThe dimension.
lThe new lower limit.
bThe rectagle to modify.

Definition at line 123 of file rectangle.c.

References Trectangle::l.

Referenced by BuildKDTree(), and main().

+ Here is the caller graph for this function:

void SetRectangleUpperLimit ( unsigned int  i,
double  u,
Trectangle b 
)
inline

Set the upper limit along a given dimension.

Parameters
iThe dimension.
uThe new upper limit.
bThe rectagle to modify.

Definition at line 130 of file rectangle.c.

References Trectangle::u.

Referenced by BuildKDTree(), and main().

+ Here is the caller graph for this function:

void SetRectangleLimits ( unsigned int  i,
double  l,
double  u,
Trectangle b 
)
inline

Changes the lower and the upper limit along a given dimension.

Parameters
iThe dimension.
lThe new lower limit.
uThe new upper limit.
bThe rectagle to modify.

Definition at line 137 of file rectangle.c.

References Trectangle::l, and Trectangle::u.

Referenced by BuildKDTree(), and InitKDTree().

+ Here is the caller graph for this function:

void RandomPointInRectangle ( double *  c,
Trectangle b 
)

Computes a random point along the selected dimensions.

Parameters
cSpace where to store the random point (should be allocated by the caller with, at least, space for the point along the selected dimensions).
bThe rectangle.

Definition at line 145 of file rectangle.c.

References Trectangle::l, Trectangle::n, randomDouble(), and Trectangle::u.

Referenced by main(), and SampleInKDtree().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

double SquaredDistanceToRectangleDimension ( unsigned int  dim,
double  p,
unsigned int *  tp,
Trectangle b 
)

Squared distance of a value to the interval defining a rectangle along a given dimension.

Parameters
dimThe dimension.
pThe point.
tpThe topology of the space where the rectangle and the point are defined.
bThe rectangle.
Returns
The squared distance from the value to the interval.

Definition at line 153 of file rectangle.c.

References ANGLE_ACCURACY, Trectangle::l, M_2PI, M_PI, PI2PI, TOPOLOGY_R, and Trectangle::u.

Referenced by SearchInBallKDtree(), and SearchKDtree().

+ Here is the caller graph for this function:

double SquaredDistanceToRectangle ( double  t2,
double *  p,
unsigned int *  tp,
Trectangle b 
)

Computes the minimum squared distance from a point to a rectangle but considering a possible special topology for the input rectangle and the input point.

Parameters
t2Threshold. Only poits closer than 't2' to the rectangle are relevant. Use INF if all points must be considered. Using a threshold accelerates the computation in some cases.
pThe point.
tpThe topology of the space where the rectangle and the point are defined.
bThe rectangle.
Returns
The minimum distance between the input parameters.

Definition at line 230 of file rectangle.c.

References ANGLE_ACCURACY, Trectangle::l, M_2PI, M_PI, Trectangle::n, PI2PI, TOPOLOGY_R, and Trectangle::u.

Referenced by SearchInBallKDtree(), and SearchKDtree().

+ Here is the caller graph for this function:

unsigned int GetRectangleSplitDim ( Trectangle b)

Computes the rectangle dimension for which it is better to split the rectangle. Right now this function is an alias to GetRectangleMaxDim.

Parameters
bThe rectangle.
Returns
The best split dimension for the given rectangle.
See Also
GetRectangleMaxDim

Definition at line 344 of file rectangle.c.

References Trectangle::l, Trectangle::n, and Trectangle::u.

Referenced by BuildKDTree().

+ Here is the caller graph for this function:

void PrintRectangle ( FILE *  f,
Trectangle b 
)

Prints a rectangle. Used for debug.

Parameters
fThe file where to print the rectangle. Typically stdout or stderr.
bThe rectangle to print.

Definition at line 365 of file rectangle.c.

References Trectangle::l, Trectangle::n, and Trectangle::u.

Referenced by PrintKDtree().

+ Here is the caller graph for this function:

void DeleteRectangle ( Trectangle b)
inline

Deletes a previously generated rectangle.

Parameters
bThe rectangle to be deleted.

Definition at line 375 of file rectangle.c.

References Trectangle::l.

Referenced by DeleteKDtree(), and main().

+ Here is the caller graph for this function: