This file is indexed.

/usr/include/mia-2.2/mia/2d/vector.hh is in libmia-2.2-dev 2.2.2-1+b1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
/* -*- mia-c++  -*-
 *
 * This file is part of MIA - a toolbox for medical image analysis 
 * Copyright (c) Leipzig, Madrid 1999-2014 Gert Wollny
 *
 * MIA is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MIA; if not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef MIA_2D_VECTOR_HH
#define MIA_2D_VECTOR_HH
 
#include <cmath>
#include <cassert>
#include <stdexcept>
#include <ostream>
#include <istream>
#include <iomanip>
#include <type_traits>

// MIA specific
#include <mia/core/type_traits.hh>
#include <mia/core/errormacro.hh>
#include <mia/core/attributetype.hh>

NS_MIA_BEGIN

/**
   \ingroup basic
   \brief a 2D vector 
   
   A 2D vector that provides the usual set of operations required to handle such objects. 
   \tparam type of the elements 
 */
template <class T > class T2DVector {
public:	

	/// typedef for generic access to the element type 
	typedef T value_type; 
	
	/// first element 
	T x;
	
	/// second element 
	T y;
	
	/// a static for the value <1,1>. 
	static const T2DVector<T> _1; 

	/// a static for the value <0,0>. 
	static const T2DVector<T> _0; 
		
	T2DVector():x(T()),y(T()){}

	/** this constructor is required for some generic code 
	    It is explicit to avoid some problems with automatic assigment 
	 */ 
	explicit T2DVector(int dim):x(T()),y(T()){
		assert(dim ==2);
	}

	/**
	   Contruct the vector with the according elements 
	   \param _x 
	   \param _y 
	 */
	T2DVector(T _x, T _y):x(_x),y(_y){};

	
	/**
	   Automatically convert a 2D vector from another element type 
	 */
	template <typename In>
	T2DVector(const T2DVector<In>& in):
		x(in.x), 
		y(in.y)
		{
		}
	
	// Functions


	///@returns square norm of the vector 
	T norm2() const {
		return T(x * x + y * y);
	}

	///@returns norm of the vector 
	T norm() const {
		return T(sqrt(norm2()));
	}
	
	///@returns product of the elements of the vector  
	double product() const {
		return x * y; 
	}

	// Operators 

	/// in place addition 
	T2DVector& operator += (const T2DVector& a){
		x += a.x; y += a.y;
		return *this;
	}

	/// in place subtraction 
	T2DVector& operator -= (const T2DVector& a){
		x -= a.x; y -= a.y;
		return *this;
	}

	/// in place multiplication with a scalar 
	T2DVector& operator *= (double a){
		x *= a; y *= a;
		return *this;
	}

	/// in place element wise multiplication of two 2D vectors 
	T2DVector& operator *= (const T2DVector& a){
		x *= a.x; y *= a.y;
		return *this;
	}

	/// in place element wise division of two 2D vectors 
	T2DVector& operator /= (const T2DVector& a){
		if ( a.x == 0.0 || a.y == 0.0)
			throw std::invalid_argument("T2DVector<T>::operator /=: division by zero not allowed"); 
		x /= a.x; y /= a.y;
		return *this;
	}

	/// in place division by a scalar  
	T2DVector& operator /= (double a){
		if ( a == 0.0 )
			throw std::invalid_argument("T2DVector<T>::operator /=: division by zero not allowed"); 
		x /= a; y /= a;
		return *this;
	}

	T2DVector operator -() const {
		return 	T2DVector<T>(-x, -y); 
	}

	/// returns the size of this vector, always 2
	size_t size() const {
		return 2;
	}
	
	/** Array access operator for some generic code 
	    One should have a look how expensive this function is 
	 */ 
	T& operator [](int i) {
		switch (i) {
		case 0:return x; 
		case 1:return y; 
		default: {
			DEBUG_ASSERT_RELEASE_THROW(false, "access to value at (", i, ") outside of range (0-1)"); 
		}
		}
	}
	
	/** Array access operator for some generic code 
	    One should have a look how expensive this function is 
	 */ 
	const T& operator [](int i) const {
		switch (i) {
		case 0:return x; 
		case 1:return y; 
		default: {
			DEBUG_ASSERT_RELEASE_THROW(false, "access to value at (", i, ") outside of range (0-1)");
		}
		}
	}
	
	/// fill all the elements with the given value
	void fill(T v) {
		x = y = v; 
	}
	
	/// Equal operator 
	bool operator == (const T2DVector& a)const{
		return (x == a.x && y == a.y);
	}
	
	/// not equal operator 
	bool operator != (const T2DVector& a)const{
		return (! (*this == a));
	}

	/// print the vector to a stream with special formatting 
	void print(std::ostream& os) const {
		os  << x << "," << y; 
	}
	
	/// read the properly formatted 2D vector from a stream 
	void read(std::istream& is) {
		char c; 
		
		T r,s; 
		is >> c;
		// if we get the opening delimiter '<' then we also expect the closing '>'
		// otherwise just read two coma separated values. 
		// could use the BOOST lexicel cast for better error handling
		if (c == '<') {
			is >> r;
			is >> c; 
			if (c != ',') {
				is.clear(std::ios::badbit);
				return; 
			}
			is >> s; 
			is >> c; 
			if (c != '>') {
				is.clear(std::ios::badbit);
				return; 
			}
			x = r; 
			y = s; 
		}else {
			is.putback(c); 
			is >> r;
			is >> c; 
			if (c != ',') {
				is.clear(std::ios::badbit);
				return; 
			}
			is >> s; 
			x = r; 
			y = s; 
		}
		
	}

};


struct EAttributeType_2d : public EAttributeType {
	
	static const int vector_2d_bit = 0x20000; 
	
	static bool is_vector2d(int type) {
		return type & vector_2d_bit; 
        }
}; 

template <typename T> 
struct attribute_type<T2DVector<T>> : public EAttributeType_2d {
        static const int value = attribute_type<T>::value | vector_2d_bit;
}; 


/// @cond NEVER  

template <typename T> 
struct atomic_data<T2DVector<T> > {
	typedef T type;
	static const int size; 
}; 

template <typename T> 
const int atomic_data<T2DVector<T> >::size = 2; 

/// @endcond 

template <typename T> 
const T2DVector<T> T2DVector<T>::_1 = T2DVector<T>(1,1); 

template <typename T> 
const T2DVector<T> T2DVector<T>::_0 = T2DVector<T>(0,0); 

/**
   operator to write a 2D vector to a stream 
   \tparam type of the vector values 
   \param os output stream 
   \param a vector 
   \returns reference to stream to allow chaining of the operator 
 */
template <typename T>
std::ostream& operator << (std::ostream& os, const T2DVector<T>& a)
{
	a.print(os); 
	return os; 
}

/**
   operator to read a 2D vector from a stream 
   \tparam type of the vector values 
   \param is input stream 
   \param a vector 
   \returns reference to stream to allow chaining of the operator 
 */
template <typename T>
std::istream& operator >> (std::istream& is, T2DVector<T>& a)
{
	a.read(is); 
	return is; 
}

/**
   Add operator for two 2D vectors that hold the same data type 
   \tparam type of the vector values 
   \param a 
   \param b
   \returns a+b
 */
template <typename  T>
T2DVector<T> operator +(const T2DVector<T>& a, const T2DVector<T>& b)
{
	T2DVector<T> r(a); 
	r += b; 
	return r; 
}

/**
   Add operator for two 2D vectors that hold different data types 
   Target type is taken from the lhs operator 
   \tparam type of the vector values 
   \param a 
   \param b
   \returns a+b
 */
template <typename  T, typename  S>
T2DVector<T> operator +(const T2DVector<T>& a, const T2DVector<S>& b)
{
	return T2DVector<T>(a.x + b.x, a.y + b.y); 
}

/**
   Element wise multiplication  operator for two 2D vectors that hold the same data type 
   \tparam type of the vector values 
   \param a 
   \param b
   \returns <a.x*b.x, a.y*b.y>
 */
template <typename  T>
T2DVector<T> operator *(const T2DVector<T>& a, const T2DVector<T>& b)
{
	T2DVector<T> r(a); 
	r *= b; 
	return r; 
}

/**
   Element wise division  operator for two 2D vectors that hold the same data type. 
   Throws a std::invalid_argument exception if b.x=== or b.y==0. 
   \tparam type of the vector values 
   \param a 
   \param b
   \returns <a.x/b.x, a.y/b.y>
 */
template <typename  T>
T2DVector<T> operator /(const T2DVector<T>& a, const T2DVector<T>& b)
{
	T2DVector<T> r(a); 
	r /= b; 
	return r; 
}

/**
   Element wise subtraction operator for two 2D vectors that hold the same data type. 
   \tparam type of the vector values 
   \param a 
   \param b
   \returns a-b
 */

template <typename  T>
T2DVector<T> operator -(const T2DVector<T>& a, const T2DVector<T>& b)
{
	T2DVector<T> r(a); 
	r -= b; 
	return r; 
}

/**
   dot product for two 2D vectors that hold the same data type. 
   \tparam type of the vector values 
   \param a 
   \param b
   \returns a.x*b.x + a.y*b.y 
*/

template <typename  T>
T dot(const T2DVector<T>& a, const T2DVector<T>& b)
{
	return b.x * a.x + b.y * a.y; 
}

/**
   Division of a vector by a scalar. 
   Throws a std::invalid_argument exception if f==0. 
   \tparam type of the vector values 
   \param a 
   \param f
   \returns <a.x/f, b.y/f>
*/

template <typename  T>
T2DVector<T> operator / (const T2DVector<T>& a, double f)
{
	T2DVector<T> r(a); 
	r /= f; 
	return r; 
}

/**
   Multiplication of a vector with a scalar. 
   \tparam type of the vector values 
   \param a  vector 
   \param f scalar 
   \returns <a.x*f, b.y*f>
*/
template <typename  T>
T2DVector<T> operator * (const T2DVector<T>& a, double f)
{
	T2DVector<T> r(a); 
	r *= f; 
	return r; 
}

/**
   Multiplication of a scalar with a vector. 
   \tparam type of the vector values 
   \param f scalar 
   \param a vector 
   \returns <a.x*f, b.y*f>
*/
template <typename  T>
T2DVector<T> operator * (double f, const T2DVector<T>& a)
{
	return a * f; 
}

/**
   Comparison of a vector. Not the this less operator does not define 
   an order, since it is possible that a =/= b and !a<b && !b<a. 
   \param a 
   \param b 
   \returns true if both elements in a are less the the corresponding elements in b. 
 */
template <typename T, typename S>
bool operator < (const T2DVector<T>& a, const T2DVector<S>& b) 
{
	return a.x < b.x && a.y < b.y; 
}

template <typename T, template <typename> class Vector> 
struct cross_product {
	typedef T return_type; 
	static return_type apply(const Vector<T>& a, const Vector<T>& b) {
		return a.x * b.y - a.y * b.x;
	}; 
}; 

/**
   Cross product of two 2D vectors. Technically it's the 3D cross product with 
   the z-elements set to zero and ignoring all zero elements of the output vector 
   \param a
   \param b 
   \returns 2D cross product 
   \todo Check why does it use indirection to the apply-function? 
 */
template <typename  T>
T cross(const T2DVector<T>& a, const T2DVector<T>& b)
{
	return cross_product<T, T2DVector>::apply(a,b); 
}


template <typename T>
struct less_then<T2DVector<T> > {
	bool operator() (const T2DVector<T>& a, const T2DVector<T>& b) const {
		return a.y < b.y || (a.y == b.y && a.x < b.x);
	}
}; 


/// float valued 2D vector
typedef T2DVector<float>    C2DFVector;

/// double valued 2D vector
typedef T2DVector<double>   C2DDVector;

/// unsigned int valued 2D vector - used as 2D size parameter
typedef T2DVector<unsigned int>   C2DBounds;


NS_MIA_END

#endif