|
From: <axl...@us...> - 2009-10-13 01:43:54
|
Revision: 570
http://hgengine.svn.sourceforge.net/hgengine/?rev=570&view=rev
Author: axlecrusher
Date: 2009-10-13 01:43:47 +0000 (Tue, 13 Oct 2009)
Log Message:
-----------
commit progress
Modified Paths:
--------------
Mercury2/src/DataStructures/SpatialHash.h
Modified: Mercury2/src/DataStructures/SpatialHash.h
===================================================================
--- Mercury2/src/DataStructures/SpatialHash.h 2009-10-13 01:40:18 UTC (rev 569)
+++ Mercury2/src/DataStructures/SpatialHash.h 2009-10-13 01:43:47 UTC (rev 570)
@@ -57,16 +57,35 @@
std::list<T> FindByXY(float x, float y)
{
- int ix = x / m_spacing;
- int iy = y / m_spacing;
+ unsigned int ix = abs(x) / m_spacing;
+ unsigned int iy = abs(y) / m_spacing;
std::list<T> r;
- for (uint32_t iz = 0; iz < m_zSize; ++iz)
- CopyIntoList(m_hashTable[Index(ix, iy, iz)], r);
+ if (ix < m_xSize || iy < m_ySize )
+ {
+ for (uint32_t iz = 0; iz < m_zSize; ++iz)
+ CopyIntoList(m_hashTable[Index(ix, iy, iz)], r);
+ }
return r;
}
+
+ std::list<T> FindByXZ(float x, float z)
+ {
+ unsigned int ix = abs(x) / m_spacing;
+ unsigned int iz = abs(z) / m_spacing;
+
+ std::list<T> r;
+
+ if (ix < m_xSize || iz < m_zSize )
+ {
+ for (uint32_t iy = 0; iy < m_ySize; ++iy)
+ CopyIntoList(m_hashTable[Index(ix, iy, iz)], r);
+ }
+
+ return r;
+ }
private:
inline uint32_t Index(uint32_t x, uint32_t y, uint32_t z)
{
@@ -82,6 +101,7 @@
void CopyIntoList(std::list<T>& in, std::list<T>& r)
{
+ if ( in.empty() ) return;
typename std::list<T>::iterator i = in.begin();
for (;i != in.end(); ++i) r.push_back(*i);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|