00001 #ifndef CCTBX_COORDINATES_H
00002 #define CCTBX_COORDINATES_H
00003
00004 #include <scitbx/vec3.h>
00005 #include <cctbx/import_scitbx_af.h>
00006
00007 namespace cctbx {
00008
00009 template <typename FloatType>
00010 class fractional;
00011
00012 template <typename IntType>
00013 class grid_point;
00014
00016
00021 template <typename FloatType = double>
00022 class cartesian : public scitbx::vec3<FloatType>
00023 {
00024 public:
00025 typedef scitbx::vec3<FloatType> base_type;
00026
00028 cartesian() {}
00029
00031 template <typename OtherFloatType>
00032 cartesian(af::tiny_plain<OtherFloatType, 3> const& v)
00033 {
00034 for(std::size_t i=0;i<3;i++) this->elems[i] = v[i];
00035 }
00036
00038 explicit
00039 cartesian(const FloatType* xyz)
00040 {
00041 for(std::size_t i=0;i<3;i++) this->elems[i] = xyz[i];
00042 }
00043
00045 cartesian(FloatType const& x, FloatType const& y, FloatType const& z)
00046 {
00047 this->elems[0] = x; this->elems[1] = y; this->elems[2] = z;
00048 }
00049
00050 private:
00051
00052 template <typename OtherFloatType>
00053 cartesian(fractional<OtherFloatType> const&);
00054
00055 template <typename OtherFloatType>
00056 cartesian(grid_point<OtherFloatType> const&);
00057 };
00058
00060
00065 template <typename FloatType = double>
00066 class fractional : public scitbx::vec3<FloatType>
00067 {
00068 public:
00069 typedef scitbx::vec3<FloatType> base_type;
00070
00072 fractional() {}
00073
00075 template <typename OtherFloatType>
00076 fractional(af::tiny_plain<OtherFloatType, 3> const& v)
00077 {
00078 for(std::size_t i=0;i<3;i++) this->elems[i] = v[i];
00079 }
00080
00082 template <typename OtherFloatType>
00083 explicit
00084 fractional(const OtherFloatType* xyz)
00085 {
00086 for(std::size_t i=0;i<3;i++) this->elems[i] = xyz[i];
00087 }
00088
00090 fractional(FloatType const& x, FloatType const& y, FloatType const& z)
00091 {
00092 this->elems[0] = x; this->elems[1] = y; this->elems[2] = z;
00093 }
00094
00098 fractional mod_positive() const
00099 {
00100 fractional result;
00101 for(std::size_t i=0;i<3;i++) {
00102 result[i] = std::fmod(this->elems[i], 1.);
00103 while (result[i] < 0.) result[i] += 1.;
00104 while (result[i] >= 1.) result[i] -= 1.;
00105 }
00106 return result;
00107 }
00108
00112 fractional mod_short() const
00113 {
00114 fractional result;
00115 for(std::size_t i=0;i<3;i++) {
00116 result[i] = std::fmod(this->elems[i], 1.);
00117 if (result[i] <= -.5) result[i] += 1.;
00118 else if (result[i] > .5) result[i] -= 1.;
00119 }
00120 return result;
00121 }
00122
00123 scitbx::vec3<int>
00124 unit_shifts() const
00125 {
00126 scitbx::vec3<int> result;
00127 for(std::size_t i=0;i<3;i++) {
00128 if (this->elems[i] >= 0.) result[i] = int(this->elems[i] + 0.5);
00129 else result[i] = int(this->elems[i] - 0.5);
00130 }
00131 return result;
00132 }
00133
00134 private:
00135
00136 template <typename OtherFloatType>
00137 fractional(cartesian<OtherFloatType> const&);
00138
00139 template <typename OtherFloatType>
00140 fractional(grid_point<OtherFloatType> const&);
00141 };
00142
00144
00149 template <typename IntType = signed long>
00150 class grid_point : public scitbx::vec3<IntType>
00151 {
00152 public:
00153 typedef scitbx::vec3<IntType> base_type;
00154
00156 grid_point() {}
00157
00159 template <typename OtherIntType>
00160 grid_point(af::tiny_plain<OtherIntType, 3> const& v)
00161 {
00162 for(std::size_t i=0;i<3;i++) this->elems[i] = v[i];
00163 }
00164
00166 explicit
00167 grid_point(const IntType* xyz)
00168 {
00169 for(std::size_t i=0;i<3;i++) this->elems[i] = xyz[i];
00170 }
00171
00173 grid_point(IntType const& x, IntType const& y, IntType const& z)
00174 {
00175 this->elems[0] = x; this->elems[1] = y; this->elems[2] = z;
00176 }
00177
00178 private:
00179
00180 template <typename OtherIntType>
00181 grid_point(fractional<OtherIntType> const&);
00182
00183 template <typename OtherIntType>
00184 grid_point(cartesian<OtherIntType> const&);
00185 };
00186
00187 }
00188
00189 #endif // CCTBX_COORDINATES_H