Commit 7ae1d3a3 authored by Davis King's avatar Davis King

Clarified the vector spec and added some more tests.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402739
parent 77e55423
...@@ -34,6 +34,14 @@ namespace dlib ...@@ -34,6 +34,14 @@ namespace dlib
this object is limited to representing points on the XY plane where this object is limited to representing points on the XY plane where
Z is set to 0. Z is set to 0.
Also note that this object performs the appropriate integer and
floating point conversions and promotions when vectors of mixed
type are used together. For example:
vector<int,3> vi;
vector<double,2> vd;
vd + vi == a vector<double,3> object type since that is what
is needed to contain the result of vi+vd without
any loss of information.
!*/ !*/
public: public:
...@@ -317,6 +325,37 @@ namespace dlib ...@@ -317,6 +325,37 @@ namespace dlib
}; };
// ----------------------------------------------------------------------------------------
template<typename T, typename U, long NR>
vector operator* (
const vector<T,NR> & lhs,
const U rhs
);
/*!
ensures
- returns the result of multiplying the scalar rhs by lhs
!*/
template<typename T, typename U, long NR>
vector operator* (
const U lhs,
const vector<T,NR> & rhs
);
/*!
ensures
- returns the result of multiplying the scalar lhs by rhs
!*/
template<typename T, long NR>
inline void swap (
vector<T,NR> & a,
vector<T,NR> & b
) { a.swap(b); }
/*!
provides a global swap function
!*/
template<typename T, long NR> template<typename T, long NR>
inline void swap ( inline void swap (
vector<T,NR> & a, vector<T,NR> & a,
......
...@@ -217,6 +217,27 @@ namespace ...@@ -217,6 +217,27 @@ namespace
(vd3/2).dot(vd2); (vd3/2).dot(vd2);
} }
{
dlib::vector<double,2> vd2;
dlib::vector<long,3> vl3;
vl3.x() = 1;
vl3.y() = 2;
vl3.z() = 3;
vd2.x() = 6.5;
vd2.y() = 7.5;
DLIB_CASSERT((vl3 + vd2).x() == 1+6.5,"");
DLIB_CASSERT((vl3 + vd2).y() == 2+7.5,"");
DLIB_CASSERT((vl3 + vd2).z() == 3+0,"");
DLIB_CASSERT((vl3 - vd2).x() == 1-6.5,"");
DLIB_CASSERT((vl3 - vd2).y() == 2-7.5,"");
DLIB_CASSERT((vl3 - vd2).z() == 3-0,"");
}
} }
......
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