164 lines
3.0 KiB
C++
164 lines
3.0 KiB
C++
#ifndef _OWLPS_POSITIONING_POINT3D_HH_
|
|
#define _OWLPS_POSITIONING_POINT3D_HH_
|
|
|
|
#include <ostream>
|
|
#include <cmath>
|
|
|
|
class Point3D
|
|
{
|
|
protected:
|
|
float x ;
|
|
float y ;
|
|
float z ;
|
|
|
|
public:
|
|
Point3D(const float &_x = 0, const float &_y = 0, const float &_z = 0) ;
|
|
Point3D(const Point3D &p) ;
|
|
Point3D(const float c[3]) ;
|
|
|
|
virtual ~Point3D(void) {}
|
|
|
|
float get_x(void) const ;
|
|
float get_y(void) const ;
|
|
float get_z(void) const ;
|
|
|
|
void set_x(const float &_x) ;
|
|
void set_y(const float &_y) ;
|
|
void set_z(const float &_z) ;
|
|
void set_coordinates(const Point3D &p) ;
|
|
|
|
float square_distance(const Point3D &p) const ;
|
|
float distance(const Point3D &p) const ;
|
|
float square_distance(const float &mx,
|
|
const float &my,
|
|
const float &mz) const ;
|
|
float distance(const float &mx,
|
|
const float &my,
|
|
const float &mz) const ;
|
|
|
|
const Point3D& operator=(const Point3D &p) ;
|
|
bool operator==(const Point3D &p) const ;
|
|
bool operator!=(const Point3D &p) const ;
|
|
bool operator<(const Point3D &p) const ;
|
|
bool operator>(const Point3D &p) const ;
|
|
bool operator<=(const Point3D &p) const ;
|
|
bool operator>=(const Point3D &p) const ;
|
|
|
|
friend std::ostream& operator<<(std::ostream &os, const Point3D &p) ;
|
|
} ;
|
|
|
|
|
|
|
|
/*** Accesseurs lecture ***/
|
|
|
|
|
|
inline float Point3D::get_x() const
|
|
{
|
|
return x ;
|
|
}
|
|
|
|
|
|
inline float Point3D::get_y() const
|
|
{
|
|
return y ;
|
|
}
|
|
|
|
|
|
inline float Point3D::get_z() const
|
|
{
|
|
return z ;
|
|
}
|
|
|
|
|
|
|
|
/*** Accesseurs écriture ***/
|
|
|
|
|
|
inline void Point3D::set_x(const float &_x)
|
|
{
|
|
x = _x ;
|
|
}
|
|
|
|
|
|
inline void Point3D::set_y(const float &_y)
|
|
{
|
|
y = _y ;
|
|
}
|
|
|
|
|
|
inline void Point3D::set_z(const float &_z)
|
|
{
|
|
z = _z ;
|
|
}
|
|
|
|
|
|
/*
|
|
* Updates x, y, z by passing a Point3D
|
|
* This is useful for derivated classes, and different than a direct
|
|
* call to operator=().
|
|
*/
|
|
inline void Point3D::set_coordinates(const Point3D &p)
|
|
{
|
|
this->operator=(p) ;
|
|
}
|
|
|
|
|
|
|
|
/*** Calcul de distances ***/
|
|
|
|
|
|
/*
|
|
* Distance à un point (Point3D)
|
|
* Note : pour comparer deux distances, utiliser de préférence
|
|
* square_distance, qui fait économiser une racine carrée.
|
|
*/
|
|
inline float Point3D::distance(const Point3D &p) const
|
|
{
|
|
return sqrt(square_distance(p)) ;
|
|
}
|
|
|
|
|
|
/*
|
|
* Distance à un point décrit par ses coordonnées
|
|
* Note : pour comparer deux distances, utiliser de préférence
|
|
* square_distance, qui fait économiser une racine carrée.
|
|
*/
|
|
inline float Point3D::distance(const float &_x,
|
|
const float &_y,
|
|
const float &_z) const
|
|
{
|
|
return sqrt(square_distance(_x, _y, _z)) ;
|
|
}
|
|
|
|
|
|
|
|
/*** Opérateurs ***/
|
|
|
|
|
|
inline bool Point3D::operator!=(const Point3D &p) const
|
|
{
|
|
return !(*this == p) ;
|
|
}
|
|
|
|
|
|
inline bool Point3D::operator>(const Point3D &p) const
|
|
{
|
|
return (p < *this) ;
|
|
}
|
|
|
|
|
|
inline bool Point3D::operator<=(const Point3D &p) const
|
|
{
|
|
return (*this < p || *this == p) ;
|
|
}
|
|
|
|
|
|
inline bool Point3D::operator>=(const Point3D &p) const
|
|
{
|
|
return (p <= *this) ;
|
|
}
|
|
|
|
|
|
|
|
#endif // _OWLPS_POSITIONING_POINT3D_HH_
|