Commit 5348ed7f authored by Davis King's avatar Davis King

- Made the vector class inherit from matrix

  - Added code to make sure the vector class does the
    appropriate type promotion when vector objects
    with different types are used together.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402736
parent 8c9d6c12
This diff is collapsed.
...@@ -14,7 +14,7 @@ namespace dlib ...@@ -14,7 +14,7 @@ namespace dlib
typename T, typename T,
long NR = 3 long NR = 3
> >
class vector class vector : public matrix<T,NR,1>
{ {
/*! /*!
REQUIREMENTS ON T REQUIREMENTS ON T
...@@ -129,21 +129,6 @@ namespace dlib ...@@ -129,21 +129,6 @@ namespace dlib
- #z() == 0 - #z() == 0
!*/ !*/
operator matrix<T> (
) const;
/*!
ensures
- provides automatic conversions from a vector object to a column
matrix
- returns a matrix object m such that:
- m.nr() == NR
- m.nc() == 1
- m(0) == x()
- m(1) == y()
- if (NR == 3) then
- m(2) == z()
!*/
~vector ( ~vector (
); );
/*! /*!
......
...@@ -186,6 +186,22 @@ namespace ...@@ -186,6 +186,22 @@ namespace
DLIB_CASSERT(vl2.cross(vl3).length() == 12,""); DLIB_CASSERT(vl2.cross(vl3).length() == 12,"");
DLIB_CASSERT(vl3.cross(vl2).length() == 12,""); DLIB_CASSERT(vl3.cross(vl2).length() == 12,"");
matrix<double> m(3,3);
m = 1,2,3,
4,5,6,
7,8,9;
vd3.x() = 2;
vd3.y() = 3;
vd3.z() = 4;
vd3 = m*vd3;
DLIB_CASSERT(vd3.x() == 1*2 + 2*3 + 3*4,vd3.x() << " == " << (1*2 + 2*3 + 3*4));
DLIB_CASSERT(vd3.y() == 4*2 + 5*3 + 6*4,"");
DLIB_CASSERT(vd3.z() == 7*2 + 8*3 + 9*4,"");
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment