00001 #include <cmath>
00002 #include "Point3D.h"
00003
00004 namespace rcrt
00005 {
00006
00007
00008 Point3D::Point3D()
00009 {
00010 values[0] = values[1] = values[2] = 0;
00011 }
00012
00013
00014 Point3D::Point3D(const float& val)
00015 {
00016 values[0] = values[1] = values[2] = val;
00017 }
00018
00019
00020 Point3D::Point3D(const float& xc, const float& yc, const float& zc)
00021 {
00022 values[0] = xc;
00023 values[1] = yc;
00024 values[2] = zc;
00025 }
00026
00027
00028 Point3D::Point3D(const Point3D& p)
00029 {
00030 assign(p);
00031 }
00032
00033 Point3D::Point3D(const Vec3D& vec)
00034 {
00035 values[0] = vec[0];
00036 values[1] = vec[1];
00037 values[2] = vec[2];
00038 }
00039
00040
00041 Point3D::~Point3D()
00042 {
00043 }
00044
00045
00046 void Point3D::assign(const Point3D& p)
00047 {
00048 if(&p != this){
00049 values[0] = p.values[0];
00050 values[1] = p.values[1];
00051 values[2] = p.values[2];
00052 }
00053 }
00054
00055
00056
00057 const Point3D& Point3D::operator= (const Point3D& p)
00058 {
00059 assign(p);
00060
00061 return *this;
00062 }
00063
00064
00065 Point3D Point3D::operator+ (const Vec3D& vec) const
00066 {
00067 return Point3D(values[0]+vec.x(),
00068 values[1]+vec.y(),
00069 values[2]+vec.z());
00070 }
00071
00072
00073 Point3D Point3D::operator- (const Vec3D& vec) const
00074 {
00075 return Point3D(values[0]-vec.x(),
00076 values[1]-vec.y(),
00077 values[2]-vec.z());
00078 }
00079
00080
00081 Vec3D Point3D::operator+ (const Point3D& p) const
00082 {
00083 return Vec3D(values[0]+p.values[0],
00084 values[1]+p.values[1],
00085 values[2]+p.values[2]);
00086 }
00087
00088
00089 Vec3D Point3D::operator- (const Point3D& p) const
00090 {
00091 return Vec3D(values[0]-p.values[0],
00092 values[1]-p.values[1],
00093 values[2]-p.values[2]);
00094 }
00095
00096
00097 Point3D Point3D::operator* (const float& f) const
00098 {
00099 return Point3D(values[0]*f,values[1]*f,values[2]*f);
00100 }
00101
00102
00103 Point3D Point3D::operator/ (const float& f) const
00104 {
00105 float g = 1/f;
00106 return Point3D(values[0]*g,values[1]*g,values[2]*g);
00107 }
00108
00109 float Point3D::operator[] (int i) const
00110 {
00111 return values[i];
00112 }
00113
00114 float& Point3D::operator[] (int i)
00115 {
00116 return values[i];
00117 }
00118
00119 bool Point3D::operator!= (const Point3D& p) const
00120 {
00121 return values[0] != p.values[0] || values[1] != p.values[1]
00122 || values[2] != p.values[2];
00123 }
00124
00125 bool Point3D::operator== (const Point3D& p) const
00126 {
00127 return values[0] == p.values[0] && values[1] == p.values[1]
00128 && values[2] == p.values[2];
00129 }
00130
00131 Vec3D Point3D::getPosVec3D() const
00132 {
00133 return Vec3D(values[0], values[1], values[2]);
00134 }
00135
00136
00137 Point3D Point3D::abs() const
00138 {
00139 return Point3D(fabs(values[0]),fabs(values[1]),fabs(values[2]));
00140 }
00141
00142 bool Point3D::equals(const Point3D& p) const
00143 {
00144 for(int i = 0; i < 4; i++)
00145 if(values[i] != p.values[i])
00146 return false;
00147 return true;
00148 }
00149
00150
00151 const float& Point3D::x() const
00152 {
00153 return values[0];
00154 }
00155
00156
00157 const float& Point3D::y() const
00158 {
00159 return values[1];
00160 }
00161
00162
00163 const float& Point3D::z() const
00164 {
00165 return values[2];
00166 }
00167
00168 }