[Positioning] Point3D: set_coordinates(), distance_to_sphere()
- Add function set_coordinates(float, float, float). - Add function distance_to_sphere(). - Suppress calls by reference for simple types (use const float instead of const &float).
This commit is contained in:
parent
64715f7a79
commit
f0831db109
|
@ -24,9 +24,9 @@ float Point3D::square_distance(const Point3D &source) const
|
|||
* 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
|
||||
float Point3D::square_distance(const float _x,
|
||||
const float _y,
|
||||
const float _z) const
|
||||
{
|
||||
return
|
||||
(x - _x) * (x - _x) +
|
||||
|
|
|
@ -13,7 +13,7 @@ protected:
|
|||
float z ; ///< Vertical coordinate
|
||||
|
||||
public:
|
||||
Point3D(const float &_x = 0, const float &_y = 0, const float &_z = 0):
|
||||
Point3D(const float _x = 0, const float _y = 0, const float _z = 0):
|
||||
x(_x), y(_y), z(_z) {}
|
||||
|
||||
Point3D(const Point3D &source):
|
||||
|
@ -33,10 +33,10 @@ public:
|
|||
|
||||
/** @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_x(const float _x) ;
|
||||
void set_y(const float _y) ;
|
||||
void set_z(const float _z) ;
|
||||
void set_coordinates(const float _x, const float _y, const float _z) ;
|
||||
void set_coordinates(const Point3D &source) ;
|
||||
//@}
|
||||
|
||||
|
@ -47,13 +47,16 @@ public:
|
|||
/// 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 ;
|
||||
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 ;
|
||||
float distance(const float mx,
|
||||
const float my,
|
||||
const float mz) const ;
|
||||
/// Euclidean distance to the radius of a sphere
|
||||
float distance_to_sphere(const Point3D ¢re,
|
||||
const float radius) const ;
|
||||
//@}
|
||||
|
||||
/** @name Operators */
|
||||
|
@ -99,24 +102,33 @@ inline float Point3D::get_z() const
|
|||
/* *** Write accessors *** */
|
||||
|
||||
|
||||
inline void Point3D::set_x(const float &_x)
|
||||
inline void Point3D::set_x(const float _x)
|
||||
{
|
||||
x = _x ;
|
||||
}
|
||||
|
||||
|
||||
inline void Point3D::set_y(const float &_y)
|
||||
inline void Point3D::set_y(const float _y)
|
||||
{
|
||||
y = _y ;
|
||||
}
|
||||
|
||||
|
||||
inline void Point3D::set_z(const float &_z)
|
||||
inline void Point3D::set_z(const float _z)
|
||||
{
|
||||
z = _z ;
|
||||
}
|
||||
|
||||
|
||||
inline void Point3D::
|
||||
set_coordinates(const float _x, const float _y, const float _z)
|
||||
{
|
||||
x = _x ;
|
||||
y = _y ;
|
||||
z = _z ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates x, y, z by passing a Point3D.
|
||||
* This is useful for derivated classes, and different than a direct
|
||||
|
@ -146,14 +158,25 @@ inline float Point3D::distance(const Point3D &source) const
|
|||
* 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
|
||||
inline float Point3D::distance(const float _x,
|
||||
const float _y,
|
||||
const float _z) const
|
||||
{
|
||||
return sqrt(square_distance(_x, _y, _z)) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param centre The centre of the sphere.
|
||||
* @param radius The radius of the sphere.
|
||||
*/
|
||||
inline float Point3D::distance_to_sphere(
|
||||
const Point3D ¢re, const float radius) const
|
||||
{
|
||||
return distance(centre) - radius ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* *** Operators *** */
|
||||
|
||||
|
|
Loading…
Reference in New Issue