The Cuik KD-Tree Library


rectangle.h File Reference

Definition of the Trectangle type and the associated functions. More...

#include "definitions.h"
#include <stdio.h>
Include dependency graph for rectangle.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Trectangle
 A rectangle. More...

Functions

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

Detailed Description

Definition of the Trectangle type and the associated functions.

See also:
Trectangle, rectangle.c.

Definition in file rectangle.h.


Function Documentation

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

Creates a new rectangle with the given parameters.

Parameters:
dim Dimension of the new rectangle.
l Lower limits.
u Upper limits.
b The rectangle to initialize.

Definition at line 19 of file rectangle.c.

References Trectangle::l, Trectangle::n, NEW, 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:
dim Dimension of the new rectangle (i.e., number of intervals).
p The point to use to initialize the rectangle.
b The rectangle to initialize.

Definition at line 46 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  ) 

Returns the number of ranges defining the rectangle.

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

Definition at line 60 of file rectangle.c.

References Trectangle::n.

Referenced by BuildKDTree().

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:
p The point.
b The rectangle to modify.
See also:
ExpandInterval.

Definition at line 65 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:
r Size of the border to add to the box.
limits The maximum limit for the box expansion. This box is assumed to fully include 'bIn'.
bIn The box to enlarge.
bOut The output box.
Returns:
The volume of the box after updating it.

Definition at line 81 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:

void CopyRectangle ( Trectangle b_out,
Trectangle b_in 
)

Copies one rectangle into another.

Parameters:
b_out Output rectangle. Rectangle constructed by the copy.
b_in Input rectangle. Rectangle used to create b_out.

Definition at line 108 of file rectangle.c.

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

Referenced by 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:
i The dimension.
b The rectagle to modify.
Returns:
The lower limit.

Definition at line 118 of file rectangle.c.

References Trectangle::l.

double GetRectangleUpperLimit ( unsigned int  i,
Trectangle b 
) [inline]

Gets the upper limit along a given dimension.

Parameters:
i The dimension.
b The rectagle to modify.
Returns:
The upper limit.

Definition at line 125 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:
i The dimension.
l The lower limit (output).
u The upper limit (output).
b The rectagle to query.

Definition at line 132 of file rectangle.c.

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

Referenced by BuildKDTree().

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:
i The dimension.
l The new lower limit.
b The rectagle to modify.

Definition at line 140 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:
i The dimension.
u The new upper limit.
b The rectagle to modify.

Definition at line 147 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:
i The dimension.
l The new lower limit.
u The new upper limit.
b The rectagle to modify.

Definition at line 154 of file rectangle.c.

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

Referenced by BuildKDTree().

Here is the caller graph for this function:

void RandomPointInRectangle ( double *  c,
Trectangle b 
)

Computes a random point along the selected dimensions.

Parameters:
c Space where to store the random point (should be allocated by the caller with, at least, space for the point along the selected dimensions).
b The rectangle.

Definition at line 162 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:
dim The dimension.
p The point.
tp The topology of the space where the rectangle and the point are defined.
b The rectangle.
Returns:
The squared distance from the value to the interval.

Definition at line 170 of file rectangle.c.

References Trectangle::l, M_2PI, M_PI, PI2PI, SWAP, 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:
t2 Threshold. 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.
p The point.
tp The topology of the space where the rectangle and the point are defined.
b The rectangle.
Returns:
The minimum distance between the input parameters.

Definition at line 229 of file rectangle.c.

References Trectangle::l, M_2PI, M_PI, Trectangle::n, PI2PI, SWAP, 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:
b The rectangle.
Returns:
The best split dimension for the given rectangle.
See also:
GetRectangleMaxDim

Definition at line 324 of file rectangle.c.

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

Referenced by BuildKDTree().

Here is the caller graph for this function:

void DeleteRectangle ( Trectangle b  ) 

Deletes a previously generated rectangle.

Parameters:
b The rectangle to be deleted.

Definition at line 346 of file rectangle.c.

References Trectangle::l.

Referenced by DeleteKDtree(), and main().

Here is the caller graph for this function: