NL3D::CZoneSearch Class Reference

#include <zone_search.h>

Inheritance diagram for NL3D::CZoneSearch:

NL3D::CZoneManager

Detailed Description

CZoneSearch is a class that determine which zone cooresponding to a coordinate and zones are around a position
Author:
Alain Saffray

Nevrax France

Date:
2000

Definition at line 44 of file zone_search.h.

Public Member Functions

 CZoneSearch ()
 Constructor.

void getListZoneId (uint x, uint y, uint sizeArea, std::vector< uint16 > &l)
void getListZoneName (uint x, uint y, uint sizeArea, std::list< std::pair< std::string, uint32 > > &l)
uint16 getZoneId (uint x, uint y) const
std::pair< std::string, uint32getZoneName (uint x, uint y, uint cx, uint cy)
std::string getZoneNameFromId (uint16 zoneid)
void getZonePos (uint16 zoneId, uint &x, uint &y) const

Private Attributes

uint _NbZoneX
uint _NbZoneY
 Number zones on Y axis of landscape.

uint _SizeZoneX
uint _SizeZoneY


Constructor & Destructor Documentation

NL3D::CZoneSearch::CZoneSearch  ) 
 

Constructor.

Constructor : Initialize some privates members

Size X is named of AA to ZZ, current size is IB = 26 * 8 + 2 (AA is zone number 1, AZ zone number 26, BA zone number 27...)

Number zones on Y axis of landscape

Size X of one zone (in meters)

Size X of one zone (in meters)

Definition at line 43 of file zone_search.cpp.

References _NbZoneX, _NbZoneY, _SizeZoneX, and _SizeZoneY.

00044 {
00046         _NbZoneX = 26 * 8 + 2;
00047 
00049         _NbZoneY = 297;
00050         
00052         _SizeZoneX = 160;
00053 
00055         _SizeZoneY = 160;
00056 }


Member Function Documentation

void NL3D::CZoneSearch::getListZoneId uint  x,
uint  y,
uint  sizeArea,
std::vector< uint16 > &  l
 

Definition at line 158 of file zone_search.cpp.

References _NbZoneX, _NbZoneY, _SizeZoneX, _SizeZoneY, getZoneId(), sint, uint, x, and y.

Referenced by NL3D::CZoneManager::checkZonesAround().

00159 {
00160         sint startPosX, startPosY;
00161         uint lastPosX, lastPosY, sizeAreaX, sizeAreaY;
00162 
00163         startPosX = x - sizeArea;
00164         startPosY = y - sizeArea;
00165 
00166         sizeArea += sizeArea;
00167         sizeAreaX = sizeAreaY = sizeArea;
00168 
00169         if(startPosX < 0)
00170         {
00171                 sizeAreaX += startPosX;
00172                 startPosX = 0;
00173         }
00174 
00175         lastPosX = startPosX + sizeAreaX;
00176         if(lastPosX >= (_NbZoneX * _SizeZoneX))
00177         {
00178                 sizeAreaX -= _NbZoneX * _SizeZoneX - lastPosX;
00179                 lastPosX = _NbZoneX * _SizeZoneX - 1;
00180         }
00181 
00182         if(startPosY < 0)
00183         {
00184                 sizeAreaY += startPosY;
00185                 startPosY = 0;
00186         }
00187 
00188         lastPosY = startPosY + sizeAreaY;
00189         if(lastPosY >= (_NbZoneY * _SizeZoneY))
00190         {
00191                 sizeAreaY -= _NbZoneY * _SizeZoneY - lastPosY;
00192                 lastPosY = _NbZoneY * _SizeZoneY - 1;
00193         }
00194 
00195         l.clear();
00196 
00197         for(uint i = startPosY; i <= lastPosY; i += _SizeZoneY)
00198         {
00199                 for(uint j = startPosX; j <= lastPosX; j += _SizeZoneX)
00200                 {
00201                         l.push_back(getZoneId(j, i));
00202                 }
00203         }
00204 }

void NL3D::CZoneSearch::getListZoneName uint  x,
uint  y,
uint  sizeArea,
std::list< std::pair< std::string, uint32 > > &  l
 

Definition at line 96 of file zone_search.cpp.

References _NbZoneX, _NbZoneY, _SizeZoneX, _SizeZoneY, getZoneName(), sint, uint, x, and y.

00097 {
00098         sint startPosX, startPosY;
00099         uint lastPosX, lastPosY, sizeAreaX, sizeAreaY;
00100 
00101         startPosX = x - sizeArea;
00102         startPosY = y - sizeArea;
00103 
00104         sizeArea += sizeArea;
00105         sizeAreaX = sizeAreaY = sizeArea;
00106 
00107         if(startPosX < 0)
00108         {
00109                 sizeAreaX += startPosX;
00110                 startPosX = 0;
00111         }
00112 
00113         lastPosX = startPosX + sizeAreaX;
00114         if(lastPosX >= (_NbZoneX * _SizeZoneX))
00115         {
00116                 sizeAreaX -= _NbZoneX * _SizeZoneX - lastPosX;
00117                 lastPosX = _NbZoneX * _SizeZoneX - 1;
00118         }
00119 
00120         if(startPosY < 0)
00121         {
00122                 sizeAreaY += startPosY;
00123                 startPosY = 0;
00124         }
00125 
00126         lastPosY = startPosY + sizeAreaY;
00127         if(lastPosY >= (_NbZoneY * _SizeZoneY))
00128         {
00129                 sizeAreaY -= _NbZoneY * _SizeZoneY - lastPosY;
00130                 lastPosY = _NbZoneY * _SizeZoneY - 1;
00131         }
00132 
00133         l.clear();
00134 
00135         for(uint i = startPosY; i <= lastPosY; i += _SizeZoneY)
00136         {
00137                 for(uint j = startPosX; j <= lastPosX; j += _SizeZoneX)
00138                 {
00139                         l.push_back(getZoneName(j, i, x, y));
00140                 }
00141         }
00142 }

uint16 NL3D::CZoneSearch::getZoneId uint  x,
uint  y
const
 

Definition at line 144 of file zone_search.cpp.

References _SizeZoneX, _SizeZoneY, uint, uint16, x, and y.

Referenced by getListZoneId().

00145 {
00146         uint zoneY = y / _SizeZoneY;
00147         uint zoneX = x / _SizeZoneX;
00148         
00149         return (zoneX&255)+(zoneY<<8);
00150 }

pair< string, uint32 > NL3D::CZoneSearch::getZoneName uint  x,
uint  y,
uint  cx,
uint  cy
 

Get the zone name corresponding to coordinate

Parameters:
x is axis X coordinate (in meters)
y is axis Y coordinate (in meters)
cx is axis X coordinate of center area (in meters)
cy is axis Y coordinate of center area (in meters)
Returns:
a pair of the zone name and square distance between zone and center area (in zone unit)

Definition at line 67 of file zone_search.cpp.

References _SizeZoneX, _SizeZoneY, uint, uint32, x, and y.

Referenced by getListZoneName(), and NL3D::CLandscapeUser::getZoneName().

00068 {
00069         char name[13];
00070 
00071         uint zoneY = y / _SizeZoneY + 1;
00072         uint zoneX = x / _SizeZoneX;
00073 
00074         uint zoneCenterY = cy / _SizeZoneY + 1;
00075         uint zoneCenterX = cx / _SizeZoneX;
00076 
00077         uint32 distance = (zoneX - zoneCenterX) * (zoneX - zoneCenterX) + (zoneY - zoneCenterY) * (zoneY - zoneCenterY);
00078 
00079         char firstLetter = zoneX / 26 + 'A';
00080         char secondLetter = zoneX % 26 + 'A';
00081 
00082         sprintf(name, "%d_%c%c.zonel", zoneY, firstLetter, secondLetter);
00083 
00084         return make_pair<string, uint32>(string(name), distance);
00085 }

std::string NL3D::CZoneSearch::getZoneNameFromId uint16  zoneid  ) 
 

Definition at line 206 of file zone_search.cpp.

References sint, uint16, x, and y.

Referenced by NL3D::CZoneManager::checkZonesAround(), and NL3D::CZoneManager::isWorkComplete().

00207 {
00208         char name[16];
00209 
00210         sint    x = zoneid & 255;
00211         sint    y = zoneid >> 8;
00212         sprintf (name, "%d_%c%c.zonel", y+1, (char)('A'+(x/26)), (char)('A'+(x%26)));
00213         return string(name);
00214 }

void NL3D::CZoneSearch::getZonePos uint16  zoneId,
uint x,
uint y
const
 

Definition at line 152 of file zone_search.cpp.

References _SizeZoneY, uint, uint16, x, and y.

Referenced by NL3D::CZoneManager::checkZonesAround().

00153 {
00154         x = _SizeZoneY*(zoneId&255);
00155         y = _SizeZoneY*(zoneId>>8);     
00156 }


Field Documentation

uint NL3D::CZoneSearch::_NbZoneX [private]
 

Definition at line 78 of file zone_search.h.

Referenced by CZoneSearch(), getListZoneId(), and getListZoneName().

uint NL3D::CZoneSearch::_NbZoneY [private]
 

Number zones on Y axis of landscape.

Definition at line 81 of file zone_search.h.

Referenced by CZoneSearch(), getListZoneId(), and getListZoneName().

uint NL3D::CZoneSearch::_SizeZoneX [private]
 

Definition at line 84 of file zone_search.h.

Referenced by CZoneSearch(), getListZoneId(), getListZoneName(), getZoneId(), and getZoneName().

uint NL3D::CZoneSearch::_SizeZoneY [private]
 

Definition at line 87 of file zone_search.h.

Referenced by CZoneSearch(), getListZoneId(), getListZoneName(), getZoneId(), getZoneName(), and getZonePos().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 08:36:22 2004 for NeL by doxygen 1.3.6