This file is indexed.

/usr/include/Rivet/Math/eigen/projective.h is in librivet-dev 1.8.3-1.1.

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
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra. Eigen itself is part of the KDE project.
//
// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen 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 2 or (at your option) any later version.
//
// Eigen 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 Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.

/** \file projective.h
  * \brief Projective geometry
  */

#ifndef EIGEN_MATRIXP_H
#define EIGEN_MATRIXP_H

#include "matrix.h"

namespace Eigen
{

/** \ingroup projective
  *
  * Converts an "affine" vector into the equivalent "projective" vector.
  * Thus, if the input affine vector is \f$(x_1,\ldots,x_n)\f$, then the
  * output projective vector is \f$(x_1,\ldots,x_n,1)\f$.
  *
  * \sa projToAff()
  */
template< typename T, int Size>
Vector<T, Size+1> & affToProj( const Vector<T, Size> & vector,
                             Vector<T, Size+1> * ret )
{
    for( int i = 0; i < Size; i++ ) (*ret)(i) = vector(i);
    (*ret)(Size) = static_cast<T>(1);
    return *ret;
}

/** \ingroup projective
  *
  * Converts a "projective" vector into the equivalent "affine" vector.
  * Thus, if the input projective vector is \f$(x_1,\ldots,x_{n+1})\f$,
  * then the output affine vector is
  * \f[(\frac{x_1}{x_{n+1}},\ldots,\frac{x_n}{x_{n+1}}).\f]
  *
  * \sa affToProj()
  */
template< typename T, int Size>
Vector<T, Size> & projToAff( const Vector<T, Size+1> & vector,
                             Vector<T, Size> * ret )
{
    for( int i = 0; i < Size; i++ ) (*ret)(i) = vector(i) / vector(Size);
    return *ret;
}

/** \ingroup projective
  *
  * \ingroup matrices
  *
  * \ingroup fixedsize
  *
  * \brief Matrix in projective geometry, fixed-size only
  *
  * It's sometimes useful to add one dimension to the space you're working in.
  * For instance, that allows to represent translations as matrices, which is
  * otherwise impossible.
  *
  * Internally, a MatrixP<T, n> is just a Matrix<T, n+1>. The difference is
  * that it's regarded as a homography acting on the n-dimensional projective
  * space, instead of being regarded as a linear map acting on the n-dimensional
  * vector space.
  *
  * The correspondence between "ordinary" vectors of size n and
  * "projective" vectors of size n+1 is as follows. Given an ordinary vector
  * \f$(x_1,\ldots,x_n)\f$, the corresponding projective vector is
  * \f$(x_1,\ldots,x_n,1)\f$. Conversely, given a projective vector
  * \f$(x_1,\ldots,x_n,x_{n+1})\f$, the corresponding ordinary vector is
  * \f$(\frac{x_1}{x_{n+1}},\ldots,\frac{x_n}{x_{n+1}})\f$. If \f$x_{n+1}=0\f$,
  * then the projective vector doesn't correspond to any ordinary one, and
  * is called a "direction at infinity".
  *
  * The following typedefs are provided to cover the usual cases:
  * @code
    typedef MatrixP<double, 2>               MatrixP2d;
    typedef MatrixP<double, 3>               MatrixP3d;
    typedef MatrixP<double, 4>               MatrixP4d;
    typedef MatrixP<float,  2>               MatrixP2f;
    typedef MatrixP<float,  3>               MatrixP3f;
    typedef MatrixP<float,  4>               MatrixP4f;
    typedef MatrixP<std::complex<double>, 2> MatrixP2cd;
    typedef MatrixP<std::complex<double>, 3> MatrixP3cd;
    typedef MatrixP<std::complex<double>, 4> MatrixP4cd;
    typedef MatrixP<std::complex<float>,  2> MatrixP2cf;
    typedef MatrixP<std::complex<float>,  3> MatrixP3cf;
    typedef MatrixP<std::complex<float>,  4> MatrixP4cf;
  * @endcode
  *
  * For example, in an OpenGL application, the Modelview and Projection matrices
  * can be represented as objects of MatrixP3d or MatrixP3f according to whether
  * one prefers to work over doubles or over floats.
  *
  * Another example is Qt's QMatrix class: it is equivalent to Eigen's MatrixP2d.
  *
  * Tthe meaning of the entries in a MatrixP is as follows:
  * \f[\left(\begin{array}{ccc|c} & & & \\ & L & & T \\ & & & \\ \hline 0 & \cdots & 0 & 1 \end{array}\right).\f]
  * Here,
  *  - \f$L\f$, the topleft (Size x Size) block, is called the "linear component". It is a Matrix<T,Size>.
  *  - \f$T\f$, the last column vector without the last entry, is called the "translation vector". It is a Vector<T,Size>.
  *
  * Note that the last row is supposed to always be equal to 0,...,0,1. Don't alter it unless you know what you're doing.
  * However keeping it is still useful for instance for OpenGL compatibility.
  *
  * When multiplying another Vector<T, Size> V by such a MatrixP, the linear component is first applied, and then the result
  * is translated by the translation vector. Thus, the result is \f[LV+T.\f]
  */
template< typename T, int Size >
class MatrixP
{

protected:

    /// The matrix itself.
    Matrix<T, Size+1> m_mat;

public:

    /// Returns a reference to the matrix as a Matrix<T, Size+1>
    const Matrix<T, Size+1> & matrix() const { return m_mat; }
    /// Returns a reference to the matrix as a Matrix<T, Size+1>
    Matrix<T, Size+1> & matrix() { return m_mat; }

    /// Has the same meaning as in class Matrix<T, Size+1>.
    const T * array() const { return m_mat.array(); }
    /// Has the same meaning as in class Matrix<T, Size+1>.
    T * array() { return m_mat.array(); }
    /// Has the same meaning as in class Matrix<T, Size+1>.
    const T & operator() ( int row, int col ) const { return m_mat(row,col); }
    /// Has the same meaning as in class Matrix<T, Size+1>.
    T & operator() ( int row, int col ) { return m_mat(row,col); }
    /// Has the same meaning as in class Matrix<T, Size+1>.
    const T & operator[] ( int i) const { return m_mat[i]; }
    /// Has the same meaning as in class Matrix<T, Size+1>.
    T & operator[] ( int i) { return m_mat[i]; }

    /** Sets the last row to be 0,...,0,1. */
    void resetLastRow();

    /** Sets the last column entries to 0, except for the last row which is
      * left unmodified.
      *
      * \sa setTranslationVector(), translationVector(), getTranslationVector()
      */
    void resetTranslationVector();

    /**
      * Copies into *res the Size first entries of the
      * last column of the matrix.
      *
      * \sa setTranslationVector(), translationVector(), resetTranslationVector()
      */
    void getTranslationVector( Vector<T, Size> * res ) const;

    /**
      * Copies v into the Size first entries of the
      * last column of the matrix.
      *
      * \sa getTranslationVector(), translationVector(), resetTranslationVector()
      */
    void setTranslationVector( const Vector<T, Size> & v );

    /**
      * Returns a vector whose coords are the Size first entries of the
      * last column of the matrix.
      *
      * \sa getTranslationVector(), setTranslationVector(), resetTranslationVector()
      */
    Vector<T, Size> translationVector() const
    {
        Vector<T, Size> res;
        getTranslationVector( & res );
        return res;
    }

    /** Loads into *this a MatrixP constructed from a Matrix<T, Size>, by
      * calling setLinearComponent(), and then resetLastRow() and resetTranslationVector().
      * The last row and last column are filled with 0's, except for the
      * bottom-right corner entry which is set to 1. The resulting MatrixP
      * has the same action on vectors as the original Matrix had.
      *
      * \sa setLinearComponent()
      */
    MatrixP & loadMatrix( const Matrix<T, Size> & matrix );

    /** Constructs an uninitialized MatrixP.
      */
    MatrixP() : m_mat() {}

    /** Copy constructor. */
    MatrixP( const MatrixP & other ) : m_mat( other.m_mat ) {}

    /** Constructs a MatrixP from a Matrix<T, Size+1>. Simply copies the
      * entries.
      */
    MatrixP( const Matrix<T, Size+1> & other ) : m_mat( other ) {}

    /** Constructs a MatrixP from a Matrix<T, Size> by calling loadMatrix().
      */
    MatrixP( const Matrix<T, Size> & other )
    {
        loadMatrix( other );
    }

    /** Calls Matrix::operator=(). */
    MatrixP & operator = ( const MatrixP & other )
    { m_mat = other.m_mat; return *this; }

    /** Matrix-matrix product. Calls Matrix::multiply(). This stores in *res
      * the product (*this) * other. This method is faster than operator*=
      * and operator* because it doesn't perform useless copies.
      *
      * \sa linearMultiply()
      */
    void multiply( const MatrixP & other, MatrixP * res ) const
    { m_mat.multiply( other.m_mat, &( res->m_mat ) ); }

    /** Matrix-matrix product. Calls Matrix::operator*=(). */
    MatrixP & operator *= ( const MatrixP & other )
    { m_mat *= other.m_mat; return *this; }

    /** Matrix-matrix product. Calls Matrix::operator*(). For better performance use
      * multiply(const MatrixP &, MatrixP *) const instead.
      *
      * \sa multiply(const MatrixP &, MatrixP *) const
      */
    MatrixP operator * ( const MatrixP & other ) const
    { return MatrixP( m_mat * other.m_mat ); }

    /** Applies the homography represented by *this to \a vector,
      * and stores the result in *res. Thus the linear component of
      * *this is applied to \a vector, and then \a vector is translated
      * by the translation coefficients of *this. This method is faster than
      * operator* because it doesn't perform useless copies.*/
    void multiply( const Vector<T, Size> & vector,
                   Vector<T, Size> * res ) const;

    /** Returns the product of \a vector by *this, as computed by
      * multiply( const Vector<T, Size> &, Vector<T, Size> * ).
      *
      * \sa multiply(const Vector<T, Size> &, Vector<T, Size> *) const
      */
    Vector<T, Size> operator * ( const Vector<T, Size> & vector ) const
    {
        Vector<T, Size> res;
        multiply( vector, & res );
        return res;
    }

    /** Calls Matrix::multiply(). Thus, for vectors of size \a Size+1,
      * the multiplication is done as if *this were an ordinary matrix. This method is faster than
      * operator* because it doesn't perform useless copies.*/
    void multiply( const Vector<T, Size+1> & vector,
                   Vector<T, Size+1> * res ) const
    { m_mat.multiply( vector, res ); }

    /** Calls Matrix::operator*(). Thus, for vectors of size \a Size+1,
      * the multiplication is done as if *this were an ordinary matrix.
      *
      * \sa multiply(const Vector<T, Size+1> &, Vector<T, Size+1> *) const
      */
    Vector<T, Size+1> operator * ( const Vector<T, Size+1> & vector ) const
    { return m_mat * vector; }

    /** Applies the linear component of the homography represented by *this
      * to \a vector,
      * and stores the result in *res. This is the same thing as
      * multiply( const Vector<T,Size> &, Vector<T, Size> *) const,
      * except that the translation coefficients of *this are ignored.
      * In other words the last column of *this is ignored and the
      * computation is done as if it were 0,...0,1.
      *
      * \sa multiply(const MatrixP &, MatrixP *) const
      */
    void linearMultiply( const Vector<T, Size> & vector,
                   Vector<T, Size> * res ) const;

    /**
      * Stores into *res the linear component, i.e. the (Size x Size) topleft block.
      *
      * \sa setLinearComponent(), linearComponent()
      */
    void getLinearComponent( Matrix<T, Size> * res ) const;

    /**
      * Sets the linear component of *this, i.e. the (Size x Size) topleft block.
      * The last row and column are unaffected
      *
      * \sa loadMatrix(), getLinearComponent(), linearComponent()
      */
    void setLinearComponent( const Matrix<T, Size> & matrix );

    /**
      * Returns the linear component, i.e. the (Size x Size) topleft block.
      *
      *  \sa setLinearComponent(), getLinearComponent()
      */
    Matrix<T, Size> linearComponent() const
    {
        Matrix<T, Size> res;
        getLinearComponent( & res );
        return res;
    }

    /** Calls Matrix::loadZero(). */
    MatrixP & loadZero() { m_mat.loadZero(); return *this;}

    /** Calls Matrix::loadIdentity(). */
    MatrixP & loadIdentity() { m_mat.loadIdentity(); return *this;}

    /** Sets *this to be a translation matrix, with translation vector given
      * by \a v.
      *
      * \sa translate(), pretranslate(), setTranslationVector()
      */
    MatrixP & loadTranslation( const Vector<T, Size> & v );

    /** Multiplies *this on the right by the translation matrix
      * with translation vector given by \a v.
      *
      * \sa pretranslate(), loadTranslation(), setTranslationVector()
      */
    MatrixP & translate( const Vector<T, Size> & v );

    /** Multiplies *this on the left by the translation matrix
      * with translation vector given by \a v.
      *
      * \sa translate(), loadTranslation(), setTranslationVector()
      */
    MatrixP & pretranslate( const Vector<T, Size> & v );

    /** Sets *this to be the scaling matrix with given homogeneous
      * scaling coefficient.
      *
      * \sa loadScaling(const Vector<T,Size>&), scale(const T &), prescale(const T &)
      */
    MatrixP & loadScaling( const T & coeff )
    {
        Matrix<T, Size> m;
        return loadMatrix( m.loadScaling( coeff ) );
    }

    /** Multiplies *this on the right by the scaling matrix
      * with given homogeneous scaling coefficient.
      *
      * \sa scale(const Vector<T,Size>&), prescale(const T &), loadScaling(const T &) */
    MatrixP & scale( const T & coeff )
    {
        MatrixP<T, Size> m;
        return *this *= m.loadScaling( coeff );
    }

    /** Multiplies *this on the left by the scaling matrix
      * with given homogeneous scaling coefficient.
      *
      * \sa prescale(const Vector<T,Size>&), scale(const T &), loadScaling(const T &)
      */
    MatrixP & prescale( const T & coeff )
    {
        MatrixP<T, Size> m;
        return( *this = m.loadScaling( coeff ) * (*this) );
    }

    /** Sets *this to be the scaling matrix with given vector of
      * scaling coefficients.
      *
      * \sa loadScaling(const T&), scale(const Vector<T, Size> &), prescale(const Vector<T, Size> &)
      */
    MatrixP & loadScaling( const Vector<T, Size> & coeffs )
    {
        Matrix<T, Size> m;
        return loadMatrix( m.loadScaling( coeffs ) );
    }

    /** Multiplies *this on the right by the scaling matrix
      * with given vector of scaling coefficients.
      *
      * \sa scale(const T&), prescale(const Vector<T, Size> &), loadScaling(const Vector<T, Size> &)
      */
    MatrixP & scale( const Vector<T, Size> & coeffs )
    {
        MatrixP<T, Size> m;
        return *this *= m.loadScaling( coeffs );
    }

    /** Multiplies *this on the left by the scaling matrix
      * with given vector of scaling coefficients.
      *
      * \sa prescale( const T&), scale(const Vector<T, Size> &), loadScaling(const Vector<T, Size> &)
      */
    MatrixP & prescale( const Vector<T, Size> & coeffs )
    {
        MatrixP<T, Size> m;
        return( *this = m.loadScaling( coeffs ) * (*this) );
    }

    /** Sets *this to be the rotation matrix of given angle in radians.
      * See Matrix::loadRotation2(). The template parameter Size must equal 2.
      *
      * \sa rotate2(), prerotate2()
      */
    MatrixP & loadRotation2( const T & angle )
    {
        Matrix<T, Size> m;
        return loadMatrix( m.loadRotation2( angle ) );
    }

    /** Multiplies *this on the right by the rotation matrix of given angle
      * in radians.
      * See Matrix::loadRotation2(). The template parameter Size must equal 2.
      *
      * \sa prerotate2(), loadRotation2()
      */
    MatrixP & rotate2( const T & angle )
    {
        MatrixP<T, Size> m;
        return *this *= m.loadRotation2( angle );
    }

    /** Multiplies *this on the left by the rotation matrix of given angle
      * in radians.
      * See Matrix::loadRotation2(). The template parameter Size must equal 2.
      *
      * \sa rotate2(), loadRotation2()
      */
    MatrixP & prerotate2( const T & angle )
    {
        MatrixP<T, Size> m;
        return( *this = m.loadRotation2( angle ) * (*this) );
    }

    /** Sets *this to be the rotation matrix of given angle in radians
      * around given axis vector. See Matrix::loadRotation3(). The
      * template parameter Size must equal 3.
      *
      * \sa rotate3(), prerotate3()
      */
    MatrixP & loadRotation3( const T & angle, const Vector<T, Size> & axis )
    {
        Matrix<T, Size> m;
        return loadMatrix( m.loadRotation3( angle, axis ) );
    }

    /** Multiplies *this on the right by the rotation matrix of given angle
      * in radians around given axis vector. See Matrix::loadRotation3(). The
      * template parameter Size must equal 3.
      *
      * \sa prerotate3(), loadRotation3()
      */
    MatrixP & rotate3( const T & angle, const Vector<T, Size> & axis )
    {
        MatrixP<T, Size> m;
        return *this *= m.loadRotation3( angle, axis );
    }

    /** Multiplies *this on the left by the rotation matrix of given angle
      * in radians around given axis vector. See Matrix::loadRotation3(). The
      * template parameter Size must equal 3.
      *
      * \sa rotate3(), loadRotation3()
      */
    MatrixP & prerotate3( const T & angle, const Vector<T, Size> & axis )
    {
        MatrixP<T, Size> m;
        return( *this = m.loadRotation3( angle, axis ) * (*this) );
    }
};

template< typename T, int Size >
void MatrixP<T, Size>::getLinearComponent( Matrix<T, Size> * res ) const
{
    if( Size > 3 )
        for( int i = 0; i < Size; i++ )
            for( int j = 0; j < Size; j++ )
                (*res)( j, i ) = m_mat( j, i );
    else
    {
        (*res)(0, 0) = m_mat(0, 0);
        if( Size >= 2 )
        {
            (*res)(1, 0) = m_mat(1, 0);
            (*res)(0, 1) = m_mat(0, 1);
            (*res)(1, 1) = m_mat(1, 1);
        }
        if( Size == 3 )
        {
            (*res)(2, 0) = m_mat(2, 0);
            (*res)(2, 1) = m_mat(2, 1);
            (*res)(0, 2) = m_mat(0, 2);
            (*res)(1, 2) = m_mat(1, 2);
            (*res)(2, 2) = m_mat(2, 2);
        }
    }
}

template< typename T, int Size >
void MatrixP<T, Size>::setLinearComponent( const Matrix<T, Size> & matrix )
{
    if( Size > 3 )
        for( int i = 0; i < Size; i++ )
            for( int j = 0; j < Size; j++ )
                m_mat( j, i ) = matrix( j, i );
    else
    {
        m_mat(0, 0) = matrix(0, 0);
        if( Size >= 2 )
        {
            m_mat(1, 0) = matrix(1, 0);
            m_mat(0, 1) = matrix(0, 1);
            m_mat(1, 1) = matrix(1, 1);
        }
        if( Size == 3 )
        {
            m_mat(2, 0) = matrix(2, 0);
            m_mat(2, 1) = matrix(2, 1);
            m_mat(0, 2) = matrix(0, 2);
            m_mat(1, 2) = matrix(1, 2);
            m_mat(2, 2) = matrix(2, 2);
        }
    }
}

template< typename T, int Size >
void MatrixP<T, Size>::resetLastRow()
{
    for( int i = 0; i < Size; i++ )
        m_mat( Size, i ) = static_cast<T>(0);
    m_mat( Size, Size ) = static_cast<T>(1);
}

template< typename T, int Size >
void MatrixP<T, Size>::resetTranslationVector()
{
    for( int i = 0; i < Size; i++ )
        m_mat( i, Size ) = static_cast<T>(0);
}

template< typename T, int Size >
void MatrixP<T, Size>::setTranslationVector( const Vector<T, Size> & v )
{
    for( int i = 0; i < Size; i++ )
        m_mat( i, Size ) = v(i);
}

template< typename T, int Size >
void MatrixP<T, Size>::getTranslationVector( Vector<T, Size> * res ) const
{
    for( int i = 0; i < Size; i++ )
        (*res)(i) = m_mat( i, Size );
}

template< typename T, int Size >
MatrixP<T, Size> &
MatrixP<T, Size>::loadMatrix( const Matrix<T, Size> & matrix )
{
    setLinearComponent(matrix);
    resetTranslationVector();
    resetLastRow();
    return *this;
}

template< typename T, int Size >
void MatrixP<T, Size>::multiply( const Vector<T, Size> & vector,
               Vector<T, Size> * res ) const
{
    if( Size > 3 )
        for( int i = 0; i < Size; i++ )
        {
            (*res)[i] = static_cast<T>(0);
            for( int j = 0; j < Size; j++ )
                (*res)[i] += m_mat(i, j) * vector(j);
            (*res)[i] += m_mat( i, Size );
        }
    else
    {
        if( Size == 1 )
            (*res)(0) = m_mat(0, 0) * vector(0) + m_mat(0, 1);
        else if( Size == 2 )
        {
            (*res)(0) = m_mat(0, 0) * vector(0)
                      + m_mat(0, 1) * vector(1)
                      + m_mat(0, 2);
            (*res)(1) = m_mat(1, 0) * vector(0)
                      + m_mat(1, 1) * vector(1)
                      + m_mat(1, 2);
        }
        else // Size == 3
        {
            (*res)(0) = m_mat(0, 0) * vector(0)
                      + m_mat(0, 1) * vector(1)
                      + m_mat(0, 2) * vector(2)
                      + m_mat(0, 3);
            (*res)(1) = m_mat(1, 0) * vector(0)
                      + m_mat(1, 1) * vector(1)
                      + m_mat(1, 2) * vector(2)
                      + m_mat(1, 3);
            (*res)(2) = m_mat(2, 0) * vector(0)
                      + m_mat(2, 1) * vector(1)
                      + m_mat(2, 2) * vector(2)
                      + m_mat(2, 3);
        }
    }
}

template< typename T, int Size >
void MatrixP<T, Size>::linearMultiply( const Vector<T, Size> & vector,
               Vector<T, Size> * res ) const
{
    if( Size > 3 )
        for( int i = 0; i < Size; i++ )
        {
            (*res)[i] = static_cast<T>(0);
            for( int j = 0; j < Size; j++ )
                (*res)[i] += m_mat(i, j) * vector(j);
        }
    else
    {
        if( Size == 1 )
            (*res)(0) = m_mat(0, 0) * vector(0);
        else if( Size == 2 )
        {
            (*res)(0) = m_mat(0, 0) * vector(0)
                      + m_mat(0, 1) * vector(1);
            (*res)(1) = m_mat(1, 0) * vector(0)
                      + m_mat(1, 1) * vector(1);
        }
        else // Size == 3
        {
            (*res)(0) = m_mat(0, 0) * vector(0)
                      + m_mat(0, 1) * vector(1)
                      + m_mat(0, 2) * vector(2);
            (*res)(1) = m_mat(1, 0) * vector(0)
                      + m_mat(1, 1) * vector(1)
                      + m_mat(1, 2) * vector(2);
            (*res)(2) = m_mat(2, 0) * vector(0)
                      + m_mat(2, 1) * vector(1)
                      + m_mat(2, 2) * vector(2);
        }
    }
}

template< typename T, int Size >
MatrixP<T, Size> &
MatrixP<T, Size>::loadTranslation( const Vector<T, Size> & v )
{
    resetLastRow();
    if( Size > 3 )
    {
        for( int i = 0; i < Size; i++ )
        {
            m_mat( i, i ) = static_cast<T>(1);
            m_mat( i, Size ) = v(i);
            for( int j = 0; j < i; j++ )
            {
                m_mat( j, i ) = static_cast<T>(0);
                m_mat( i, j ) = static_cast<T>(0);
            }
        }
    }
    else
    {
        if( Size == 1 )
        {
            m_mat( 0, 0 ) = static_cast<T>(1);
            m_mat( 0, 1 ) = v(0);
        }
        else if( Size == 2 )
        {
            m_mat( 0, 0 ) = static_cast<T>(1);
            m_mat( 1, 1 ) = static_cast<T>(1);
            m_mat( 1, 0 ) = static_cast<T>(0);
            m_mat( 0, 1 ) = static_cast<T>(0);
            m_mat( 0, 2 ) = v(0);
            m_mat( 1, 2 ) = v(1);
        }
        else // Size == 3
        {
            m_mat( 0, 0 ) = static_cast<T>(1);
            m_mat( 1, 1 ) = static_cast<T>(1);
            m_mat( 2, 2 ) = static_cast<T>(1);
            m_mat( 1, 0 ) = static_cast<T>(0);
            m_mat( 2, 0 ) = static_cast<T>(0);
            m_mat( 0, 1 ) = static_cast<T>(0);
            m_mat( 2, 1 ) = static_cast<T>(0);
            m_mat( 0, 2 ) = static_cast<T>(0);
            m_mat( 1, 2 ) = static_cast<T>(0);
            m_mat( 0, 3 ) = v(0);
            m_mat( 1, 3 ) = v(1);
            m_mat( 2, 3 ) = v(2);
        }
    }
    return *this;
}

template< typename T, int Size >
MatrixP<T, Size> &
MatrixP<T, Size>::translate( const Vector<T, Size> & v )
{
    if( Size > 3 )
    {
        MatrixP<T, Size> m;
        return *this *= m.loadTranslation(v);
    }
    else
    {
        if( Size == 1 )
            m_mat( 0, 1 ) += m_mat( 0, 0 ) * v(0);
        else if( Size == 2 )
        {
            m_mat( 0, 2 ) += m_mat( 0, 0 ) * v(0)
                           + m_mat( 0, 1 ) * v(1);
            m_mat( 1, 2 ) += m_mat( 1, 0 ) * v(0)
                           + m_mat( 1, 1 ) * v(1);
        }
        else // Size == 3
        {
            m_mat( 0, 3 ) += m_mat( 0, 0 ) * v(0)
                           + m_mat( 0, 1 ) * v(1)
                           + m_mat( 0, 2 ) * v(2);
            m_mat( 1, 3 ) += m_mat( 1, 0 ) * v(0)
                           + m_mat( 1, 1 ) * v(1)
                           + m_mat( 1, 2 ) * v(2);
            m_mat( 2, 3 ) += m_mat( 2, 0 ) * v(0)
                           + m_mat( 2, 1 ) * v(1)
                           + m_mat( 2, 2 ) * v(2);
        }
    }
    return *this;
}

template< typename T, int Size >
MatrixP<T, Size> &
MatrixP<T, Size>::pretranslate( const Vector<T, Size> & v )
{
    if( Size > 3 )
    {
        MatrixP<T, Size> m;
        return( *this = m.loadTranslation(v) * (*this) );
    }
    else
    {
        if( Size == 1 )
            m_mat( 0, 1 ) += v(0);
        else if( Size == 2 )
        {
            m_mat( 0, 2 ) += v(0);
            m_mat( 1, 2 ) += v(1);
        }
        else // Size == 3
        {
            m_mat( 0, 3 ) += v(0);
            m_mat( 1, 3 ) += v(1);
            m_mat( 2, 3 ) += v(2);
        }
    }
    return *this;
}

EIGEN_MAKE_FIXEDSIZE_TYPEDEFS(MatrixP)

} // namespace Eigen

#endif // EIGEN_MATRIXP_H