owlps/owlps-positioning/src/point3d.cc

114 lines
1.8 KiB
C++

#include "point3d.hh"
#include <sstream>
#include <boost/functional/hash.hpp>
/* *** Distance operations *** */
/**
* The distance is not square rooted after the computation, in order
* to optimise comparisons.
*/
float Point3D::square_distance(const Point3D &source) const
{
return
(x - source.x) * (x - source.x) +
(y - source.y) * (y - source.y) +
(z - source.z) * (z - source.z) ;
}
/**
* The distance is not square rooted after the computation, in order
* to optimise comparisons.
*/
float Point3D::square_distance(const float _x,
const float _y,
const float _z) const
{
return
(x - _x) * (x - _x) +
(y - _y) * (y - _y) +
(z - _z) * (z - _z) ;
}
/* *** Operators *** */
const Point3D& Point3D::operator=(const Point3D &source)
{
if (this == &source)
return *this ;
x = source.x ;
y = source.y ;
z = source.z ;
return *this ;
}
bool Point3D::operator==(const Point3D &source) const
{
if (this == &source)
return true ;
return
x == source.x &&
y == source.y &&
z == source.z ;
}
bool Point3D::operator<(const Point3D &source) const
{
if (x < source.x)
return true ;
if (x > source.x)
return false ;
if (y < source.y)
return true ;
if (y > source.y)
return false ;
if (z < source.z)
return true ;
return false ;
}
Point3D::operator std::string(void) const
{
std::ostringstream oss ;
oss << *this ;
return oss.str() ;
}
std::ostream& operator<<(std::ostream &os, const Point3D &p)
{
os << "(" << p.x << ";" << p.y << ";" << p.z << ")" ;
return os ;
}
size_t hash_value(const Point3D &source)
{
size_t seed = 0 ;
boost::hash_combine(seed, source.x) ;
boost::hash_combine(seed, source.y) ;
boost::hash_combine(seed, source.z) ;
return seed ;
}