00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _POINT_H_
00028 #define _POINT_H_
00029
00030 #include <algorithm>
00031
00032 #include "Vector.h"
00033
00034 class Point : public Vector {
00035 public:
00036 Point() {}
00037 Point(const float p[3]) : Vector(p) {}
00038 Point(const double p[3]) : Vector(p) {}
00039 Point(Scalar x, Scalar y, Scalar z) : Vector(x, y, z) {}
00040
00041 Point& operator+=(const Vector& v);
00042 Point& operator-=(const Vector& v);
00043 Point& operator=(const Vector& v);
00044
00045 void setInf(const Point& p);
00046 void setSup(const Point& p);
00047 };
00048
00049 Point operator+(const Point& p, const Vector& v);
00050 Point operator-(const Point& p, const Vector& v);
00051
00052 Vector operator-(const Point& p1, const Point& p2);
00053
00054 bool operator<(const Point& p1, const Point& p2);
00055
00056 Point inf(const Point& p1, const Point& p2);
00057 Point sup(const Point& p1, const Point& p2);
00058
00059 Point affine(const Point& p1, const Point& p2, Scalar t);
00060
00061 Scalar distance(const Point& p1, const Point& p2);
00062 Scalar distance2(const Point& p1, const Point& p2);
00063
00064
00065 inline Point& Point::operator+=(const Vector& v) {
00066 comp[X] += v[X]; comp[Y] += v[Y]; comp[Z] += v[Z];
00067 return *this;
00068 }
00069
00070 inline Point& Point::operator-=(const Vector& v) {
00071 comp[X] -= v[X]; comp[Y] -= v[Y]; comp[Z] -= v[Z];
00072 return *this;
00073 }
00074
00075 inline Point& Point::operator=(const Vector& v) {
00076 comp[X] = v[X]; comp[Y] = v[Y]; comp[Z] = v[Z];
00077 return *this;
00078 }
00079
00080 inline void Point::setInf(const Point& p) {
00081 set_min(comp[X], p[X]); set_min(comp[Y], p[Y]); set_min(comp[Z], p[Z]);
00082 }
00083
00084 inline void Point::setSup(const Point& p) {
00085 set_max(comp[X], p[X]); set_max(comp[Y], p[Y]); set_max(comp[Z], p[Z]);
00086 }
00087
00088 inline Point operator+(const Point& p, const Vector& v) {
00089 return Point(p[X] + v[X], p[Y] + v[Y], p[Z] + v[Z]);
00090 }
00091
00092 inline Point operator-(const Point& p, const Vector& v) {
00093 return Point(p[X] - v[X], p[Y] - v[Y], p[Z] - v[Z]);
00094 }
00095
00096 inline Vector operator-(const Point& p1, const Point& p2) {
00097 return Vector(p1[X] - p2[X], p1[Y] - p2[Y], p1[Z] - p2[Z]);
00098 }
00099
00100 inline bool operator<(const Point& p1, const Point& p2) {
00101 return p1[X] < p2[X] && p1[Y] < p2[Y] && p1[Z] < p2[Z];
00102 }
00103
00104 inline Point inf(const Point& p1, const Point& p2) {
00105 return Point(min(p1[X], p2[X]), min(p1[Y], p2[Y]), min(p1[Z], p2[Z]));
00106 }
00107
00108 inline Point sup(const Point& p1, const Point& p2) {
00109 return Point(max(p1[X], p2[X]), max(p1[Y], p2[Y]), max(p1[Z], p2[Z]));
00110 }
00111
00112 inline Point affine(const Point& p1, const Point& p2, Scalar t) {
00113 return Point(p1[X] + (p2[X] - p1[X]) * t,
00114 p1[Y] + (p2[Y] - p1[Y]) * t,
00115 p1[Z] + (p2[Z] - p1[Z]) * t);
00116 }
00117
00118 inline Scalar distance(const Point& p1, const Point& p2) {
00119 return length(p1 - p2);
00120 }
00121
00122 inline Scalar distance2(const Point& p1, const Point& p2) {
00123 return length2(p1 - p2);
00124 }
00125
00126 #endif