13 template<
class CrdType=q
int32,
bool useDouble = false>
class Location{
18 Location() : x(undefined()), y(undefined()), z(undefined()){
25 Location(CrdType d1, CrdType d2, CrdType d3=Location::undefined()) : x(d1), y(d2), z(d3){
30 this->x =(CrdType)p.x;
31 this->y =(CrdType)p.y;
32 this->z =(CrdType)p.z;
36 this->z = undefined();
41 Location(
const Location<CrdType>& p) {
49 this->z = undefined();
54 Location(Location<CrdType>&& crd) : x(crd.x), y(crd.y), z(crd.z){
55 crd.x = crd.y = this->undefined();
61 *
this = Location<CrdType>();
78 return x != undefined() && y != undefined() ;
82 return x == 0 && y == 0 ;
86 return isValid() && (z != undefined());
89 operator std::vector<CrdType> () {
90 std::vector<CrdType> v {this->x, this->y, this->z};
116 if (!this->
isValid() || vec.size() < 2)
119 this->x =this->x + vec[0];
120 this->y =this->y + vec[1];
121 if ( vec.size() >= 3 && z != undefined())
122 this->z =this->z + vec[2];
128 if (!this->
isValid() || vec.size() < 22)
130 this->x =this->x - vec[0];
131 this->y =this->y - vec[1];
132 if ( vec.size() >= 3 && z != undefined())
133 this->z =this->z - vec[2];
138 double distance(
const Location<CrdType>& crd) {
139 if ( !crd.isValid() || !this->
isValid())
141 if ( z == undefined() || crd.z == undefined())
142 return std::sqrt(std::pow(abs(this->x - crd.x),2) + std::pow(abs(this->y - crd.y),2));
143 return std::sqrt(std::pow(abs(this->x - crd.x),2) + std::pow(abs(this->y - crd.y),2) + std::pow(abs(this->z - crd.z),2));
152 if (!this->
isValid() || vec.size() < 2)
154 this->x =this->x * vec[0];
155 this->y =this->y * vec[1];
156 if ( vec.size() >= 3 && z != undefined())
157 this->z =this->z * vec[2];
170 this->x =this->x * v;
171 this->y =this->y * v;
172 if ( z != undefined())
173 this->z =this->z * v;
185 if (!this->
isValid() || v == 0){
189 this->x =this->x / v;
190 this->y =this->y / v;
191 if ( z != undefined())
192 this->z =this->z / v;
209 return pnt.x == this->x && pnt.y == this->y && pnt.z == this->z;
220 static double undefined(){
return useDouble ? rUNDEF : iUNDEF;}
221 static quint64 valuetype(){
return useDouble ? itDOUBLE : itINTEGER;}
292 template<
typename CrdType>
295 return std::vector<int>();
296 std::vector<CrdType> v(3,0);
299 if ( p1.z != p1.undefined() && p2.z != p2.undefined())
304 template<
typename CrdType>
306 if (p1.
isValid() ==
false || vec.size() < 2 )
309 p3.x = p1.x + vec[0];
310 p3.y = p1.y + vec[1] ;
311 if ( vec.size() >= 3 && p1.z != p1.undefined())
312 p3.z = p1.z + vec[2];
316 template<
typename CrdType>
318 if (p1.
isValid() ==
false || vec.size() < 2 )
321 p3.x = p1.x - vec[0];
322 p3.y = p1.y - vec[1] ;
324 if ( vec.size() >= 3 && p1.z != p1.undefined())
325 p3.z = p1.z - vec[2];
329 template<
typename CrdType>
332 if ( p1.z != p1.undefined())
337 template<
typename CrdType>
342 if ( p1.z != p1.undefined())
347 typedef Location<int> Pixel;
348 typedef Location<double> Pixeld;
353 Q_DECLARE_METATYPE(Ilwis::Pixeld)