Grid. More...

#include <rgrid.h>

Collaboration diagram for RGrid:
[legend]

Public Member Functions

 RGrid (const RSize &limits)
 
void Clear (void)
 
void Assign (RRect &rect, RPoint &pos, size_t id)
 
bool IsFree (tCoord x, tCoord y) const
 
bool IsOcc (tCoord x, tCoord y) const
 
bool IsOcc (const RRect &rect) const
 
size_t GetMaxX (void) const
 
size_t GetMaxY (void) const
 
size_t GetObjId (tCoord x, tCoord y) const
 
tCoord LookLeft (const RPoint &pt) const
 
tCoord LookRight (const RPoint &pt) const
 
tCoord LookUp (const RPoint &pt) const
 
tCoord LookDown (const RPoint &pt) const
 
tCoord SkirtLeft (const RPoint &pt, const RRect &bound) const
 
tCoord SkirtRight (const RPoint &pt, const RRect &bound) const
 
tCoord SkirtUp (const RPoint &pt, const RRect &bound) const
 
tCoord SkirtDown (const RPoint &pt, const RRect &bound) const
 
bool CalculateFreePolygon (tCoord X, tCoord Y, tDirection from, const RRect &bound, RPolygon &poly) const
 
void AddFreePolygons (RGeoInfo *ins, RFreePolygons *free, const RRect &bound)
 
 ~RGrid (void)
 

Private Attributes

RSize Limits
 
RSize InternalLimits
 
size_t ** OccupiedX
 
size_t ** OccupiedY
 

Detailed Description

Grid.

The RGrid class provides some functions to manipulate a grid of geometric points.

Constructor & Destructor Documentation

RGrid ( const RSize limits)

Construct the grid.

Parameters
limitsRepresenting the maximal limits for the grid. In fact, internally, the grid is allocate 2x the size to be used by the "center" heuristic.
~RGrid ( void  )

Destruct the Grid.

Member Function Documentation

void Clear ( void  )

Clear the Grid.

void Assign ( RRect rect,
RPoint pos,
size_t  id 
)

Assign a rectangle to the grid.

Parameters
rectThe rectangle to assign.
posThe position.
idThe identifier to put.
bool IsFree ( tCoord  x,
tCoord  y 
) const

This function returns true if the position (x,y) is free or if it is out of the limits.

Parameters
xX position.
yY position.
Returns
The function return true if the point is out of the limits or if the position is free.
bool IsOcc ( tCoord  x,
tCoord  y 
) const

This function returns true if the position (x,y) is occupied.

Parameters
xX position.
yY position.
Returns
The function returns true if the position is occupied, false else (also if the point is out of the limits).
bool IsOcc ( const RRect rect) const

This function returns true if at least one position corresponding to a given rectangle is occupied.

Parameters
rectRectangle.
Returns
The function returns true if the position is occupied, false else (also if the point is out of the limits).
size_t GetMaxX ( void  ) const

Get the maximal X size allocated.

Returns
size_t
size_t GetMaxY ( void  ) const

Get the maximal Y size allocated.

Returns
size_t
size_t GetObjId ( tCoord  x,
tCoord  y 
) const

This function returns the identifier of the object placed at position (x,y) or cNoRef if no object is placed there.

Parameters
xX position.
yY position.
tCoord LookLeft ( const RPoint pt) const

Find the left most x coordinates that is free of a reference.

Parameters
ptPoint used as reference.
tCoord LookRight ( const RPoint pt) const

Find the right most x coordinates that is free of a reference.

Parameters
ptPoint used as reference.
tCoord LookUp ( const RPoint pt) const

Find the up most x coordinates that is free of a reference.

Parameters
ptPoint used as reference.
tCoord LookDown ( const RPoint pt) const

Find the down most x coordinates that is free of a reference.

Parameters
ptPoint used as reference.
tCoord SkirtLeft ( const RPoint pt,
const RRect bound 
) const

Find the left most x coordinates that is free and that skirt an edge.

Parameters
ptPoint used as reference.
boundThe rectangle which limits the research.
tCoord SkirtRight ( const RPoint pt,
const RRect bound 
) const

Find the right most x coordinates that is free and that skirt an edge.

Parameters
ptPoint used as reference.
boundThe rectangle which limits the research.
tCoord SkirtUp ( const RPoint pt,
const RRect bound 
) const

Find the up most x coordinates that is free and that skirt an edge.

Parameters
ptPoint used as reference.
boundThe rectangle which limits the research.
tCoord SkirtDown ( const RPoint pt,
const RRect bound 
) const

Find the down most x coordinates that is free and that skirt an edge.

Parameters
ptPoint used as reference.
boundThe rectangle which limits the research.
bool CalculateFreePolygon ( tCoord  X,
tCoord  Y,
tDirection  from,
const RRect bound,
RPolygon poly 
) const

Calculate a free polygon from a given position and a given direction.

Parameters
XX-Coordinate of the position.
YY-Coordinate of the position.
fromThe direction from where "it" is coming.
boundThe bound rectangle.
polyThe polygon to calculated (modified.
Returns
The function returns true if a close polygon has been calculated or false if not.
void AddFreePolygons ( RGeoInfo ins,
RFreePolygons free,
const RRect bound 
)

Add all the polygons representing free spaces that are closed and resulting of the placement of an object.

Parameters
insThe geometric information representing the last inserted object.
freeThe container of polygons where all the free spaces calculated must be add.
boundThe bounding rectangle of the objects already placed.

Member Data Documentation

RSize Limits
private

Limits for the construction.

RSize InternalLimits
private

Internal Limits.

size_t** OccupiedX
private

Grid with X as entry.

size_t** OccupiedY
private

Grid with Y as entry.