Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

VectorHash Class Reference

This is a hash of a (2-dimensional) Vector to allow for sorting of Obstacle s by using a square system. This is used by ObstacleGrid . More...

#include <obstacle_grid.h>

Inherited by _classes_ [private].

Inheritance diagram for VectorHash:

Inheritance graph
[legend]
List of all members.

Public Methods

 operator unsigned int () const
 The constructor of this class only takes a Vector for an argument and converts that to hashval . More...

 VectorHash ()
void operator= (const VectorHash &oth)
 VectorHash (const VectorHash &oth)
 VectorHash (const Vector &coord)
bool operator== (const VectorHash &oth) const
 An equal comparism function between two VectorHash es. Since hashval is pre-calculated, all this function needs to do is check for equality. More...

bool operator< (const VectorHash &oth) const
 A less than comparism function between two VectorHash es that allows for sorting. Since hashval is pre-calculated, all this function needs to do is check if our hashval is less than the other. More...


Static Public Methods

const float shortWidth ()
 A constant unexact default for the width of a Surface . More...


Public Attributes

unsigned int hashval
 hashval is the stored hash value used for hasty comparisms. More...


Static Public Attributes

const float ScaleAmt = (float)(2.)
 this constant is one divided by the width/height of each 'square' used for collisions with Obstacle s. More...


Static Private Methods

float frem (float a, float b)
 An internal remainder function that only returns a positive remainder between two floats. More...


Detailed Description

This is a hash of a (2-dimensional) Vector to allow for sorting of Obstacle s by using a square system. This is used by ObstacleGrid .

VectorHash is a hash value used for fast sorting between (2-dimensional) Vector s. This class goes in a board x spaces forward and then y times a fake width for the Surface. This is allowed to be slightly in-accurate because of unlikeliness of getting the same number twice between the range of a short int.


Constructor & Destructor Documentation

VectorHash::VectorHash   [inline]
 

00031                   {
00032         hashval=0;
00033     }

VectorHash::VectorHash const VectorHash &    oth [inline]
 

00037 : hashval(oth.hashval) {}

VectorHash::VectorHash const Vector   coord [inline]
 

00038                                      {
00039         Vector crd (coord.Scale(ScaleAmt));
00040         hashval =((unsigned int)((frem(floor(crd.i),shortWidth()))+(shortWidth()*floor(crd.j))));
00041     }


Member Function Documentation

float VectorHash::frem float    a,
float    b
[inline, static, private]
 

An internal remainder function that only returns a positive remainder between two floats.

00013                                          {
00014         float ne=fmod(a,b);
00015         if (ne<0) {
00016             return b+ne;
00017         } else {
00018             return ne;
00019         }
00020     }

VectorHash::operator unsigned int   const [inline]
 

The constructor of this class only takes a Vector for an argument and converts that to hashval .

00028                                           {
00029         return hashval;
00030     }

bool VectorHash::operator< const VectorHash &    oth const [inline]
 

A less than comparism function between two VectorHash es that allows for sorting. Since hashval is pre-calculated, all this function needs to do is check if our hashval is less than the other.

00047                                                 {
00048         return hashval<oth.hashval;
00049     }

void VectorHash::operator= const VectorHash &    oth [inline]
 

00034                                            {
00035         hashval=oth.hashval;
00036     }

bool VectorHash::operator== const VectorHash &    oth const [inline]
 

An equal comparism function between two VectorHash es. Since hashval is pre-calculated, all this function needs to do is check for equality.

00043                                                  {
00044         return hashval==oth.hashval;
00045     }

const float VectorHash::shortWidth   [inline, static]
 

A constant unexact default for the width of a Surface .

00025 {return 65536-129;} 


Member Data Documentation

unsigned int VectorHash::hashval
 

hashval is the stored hash value used for hasty comparisms.

const float VectorHash::ScaleAmt = (float)(2.) [static]
 

this constant is one divided by the width/height of each 'square' used for collisions with Obstacle s.


The documentation for this class was generated from the following file:
Generated on Mon Jul 7 21:13:56 2003 for Ethereal by doxygen1.2.15