#include "point3d.hh" /* *** Constructors *** */ Point3D::Point3D(const float &_x, const float &_y, const float &_z) { x = _x ; y = _y ; z = _z ; } Point3D::Point3D(const Point3D &p) { x = p.x ; y = p.y ; z = p.z ; } Point3D::Point3D(const float c[3]) { x = c[0] ; y = c[1] ; z = c[2] ; } /* *** Distance operations *** */ /** * The distance is not square rooted after the computation, in order * to optimise comparisons. */ float Point3D::square_distance(const Point3D &p) const { return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y) + (z - p.z) * (z - p.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 &p) { if (this == &p) return *this ; x = p.x ; y = p.y ; z = p.z ; return *this ; } bool Point3D::operator==(const Point3D &p) const { if (this == &p) return true ; return x == p.x && y == p.y && z == p.z ; } bool Point3D::operator<(const Point3D &p) const { if (x < p.x) return true ; if (x > p.x) return false ; if (y < p.y) return true ; if (y > p.y) return false ; if (z < p.z) return true ; return false ; } std::ostream& operator<<(std::ostream &os, const Point3D &p) { os << "(" << p.x << ";" << p.y << ";" << p.z << ")" ; return os ; }