#ifndef _OWLPS_POSITIONING_POINT3D_HH_ #define _OWLPS_POSITIONING_POINT3D_HH_ #include #include /// Represents a point of the 3-D space class Point3D { protected: float x ; ///< X horizontal coordinate (abscissa) float y ; ///< Y horizontal coordinate (ordinate) float z ; ///< Vertical coordinate public: Point3D(const float &_x = 0, const float &_y = 0, const float &_z = 0): x(_x), y(_y), z(_z) {} Point3D(const Point3D &source): x(source.x), y(source.y), z(source.z) {} Point3D(const float source[3]): x(source[0]), y(source[1]), z(source[2]) {} virtual ~Point3D(void) {} /** @name Read accessors */ //@{ float get_x(void) const ; float get_y(void) const ; float get_z(void) const ; //@} /** @name Write accessors */ //@{ void set_x(const float &_x) ; void set_y(const float &_y) ; void set_z(const float &_z) ; /// Sets all coordinates void set_coordinates(const Point3D &source) ; //@} /** @name Distance operations */ //@{ /// Square euclidean distance to a Point3D float square_distance(const Point3D &p) const ; /// Euclidean distance to a Point3D float distance(const Point3D &p) const ; /// Square euclidean distance to a 3-float defined point float square_distance(const float &mx, const float &my, const float &mz) const ; /// Euclidean distance to a 3-float defined point float distance(const float &mx, const float &my, const float &mz) const ; //@} /** @name Operators */ //@{ const Point3D& operator=(const Point3D &source) ; bool operator==(const Point3D &source) const ; bool operator!=(const Point3D &source) const ; bool operator<(const Point3D &source) const ; bool operator>(const Point3D &source) const ; bool operator<=(const Point3D &source) const ; bool operator>=(const Point3D &source) const ; operator std::string(void) const ; //@} /// Displays a Point3D friend std::ostream& operator<<(std::ostream &os, const Point3D &p) ; } ; /* *** Read accessors *** */ inline float Point3D::get_x() const { return x ; } inline float Point3D::get_y() const { return y ; } inline float Point3D::get_z() const { return z ; } /* *** Write accessors *** */ 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 &source) { this->operator=(source) ; } /* *** Distance operations *** */ /** * Note: to compare distances, use preferably square_distance(), * which is more efficient. */ inline float Point3D::distance(const Point3D &source) const { return sqrt(square_distance(source)) ; } /** * Note: to compare distances, use preferably square_distance(), * which is more efficient. */ inline float Point3D::distance(const float &_x, const float &_y, const float &_z) const { return sqrt(square_distance(_x, _y, _z)) ; } /* *** Operators *** */ inline bool Point3D::operator!=(const Point3D &source) const { return !(*this == source) ; } inline bool Point3D::operator>(const Point3D &source) const { return source < *this ; } inline bool Point3D::operator<=(const Point3D &source) const { return *this == source || *this < source ; } inline bool Point3D::operator>=(const Point3D &source) const { return source <= *this ; } #endif // _OWLPS_POSITIONING_POINT3D_HH_