OverSim
NTreeScope Class Reference

#include <NTreeHelper.h>

Public Member Functions

 NTreeScope ()
 NTreeScope (const Vector2D &_origin, double _size)
void resize (const Vector2D &_origin, double _size)
bool contains (const Vector2D &) const
NTreeScope getSubScope (unsigned int quadrant) const
bool isValid () const

Public Attributes

Vector2D origin
double size

Friends

bool operator== (const NTreeScope &a, const NTreeScope &b)
bool operator< (const NTreeScope &a, const NTreeScope &b)
std::ostream & operator<< (std::ostream &Stream, const NTreeScope &scope)

Detailed Description

Definition at line 30 of file NTreeHelper.h.

Constructor & Destructor Documentation

NTreeScope::NTreeScope ( )

Definition at line 3 of file NTreeHelper.cc.

Referenced by getSubScope().

{
size = -1;
}
NTreeScope::NTreeScope ( const Vector2D _origin,
double  _size 
)

Definition at line 8 of file NTreeHelper.cc.

:
origin(_origin), size(_size)
{
// Boundary checking?
}

Member Function Documentation

bool NTreeScope::contains ( const Vector2D point) const

Definition at line 20 of file NTreeHelper.cc.

Referenced by NTree::handleMove(), NTreeGroup::isInScope(), and NTreeNode::isInScope().

{
if( !isValid() ) return false;
return origin.xyMaxDistance(point)*2.0 <= size;
}
NTreeScope NTreeScope::getSubScope ( unsigned int  quadrant) const

Definition at line 26 of file NTreeHelper.cc.

Referenced by NTree::handleDivideCall(), NTree::handlePingCall(), and NTree::handlePingCallTimeout().

{
if( !isValid() ) return NTreeScope();
Vector2D newOrigin = origin;
double newSize = size/2.0;
if( quadrant < 2 ) {
// right half
newOrigin.x += newSize / 2.0;
} else {
newOrigin.x -= newSize / 2.0;
}
if( quadrant == 0 || quadrant == 3 ) {
// upper half
newOrigin.y += newSize / 2.0;
} else {
newOrigin.y -= newSize / 2.0;
}
return NTreeScope( newOrigin, newSize );
}
bool NTreeScope::isValid ( ) const
inline

Definition at line 39 of file NTreeHelper.h.

Referenced by contains(), and getSubScope().

{ return size >= 0; }
void NTreeScope::resize ( const Vector2D _origin,
double  _size 
)

Definition at line 14 of file NTreeHelper.cc.

{
origin = _origin;
size = _size;
}

Friends And Related Function Documentation

bool operator< ( const NTreeScope a,
const NTreeScope b 
)
friend

Definition at line 47 of file NTreeHelper.cc.

{
// for sorting only. This results in the biggest scope comming first
if( a.size == b.size ) {
return a.origin < b.origin;
}
return a.size > b.size;
}
std::ostream& operator<< ( std::ostream &  Stream,
const NTreeScope scope 
)
friend

Definition at line 61 of file NTreeHelper.cc.

{
Stream << "[" << scope.origin << " - " << scope.size << "]";
return Stream;
}
bool operator== ( const NTreeScope a,
const NTreeScope b 
)
friend

Definition at line 56 of file NTreeHelper.cc.

{
return a.origin == b.origin && a.size == b.size;
}

Member Data Documentation

Vector2D NTreeScope::origin
double NTreeScope::size

The documentation for this class was generated from the following files: