Commit 1f8cd9c3 authored by Davis King's avatar Davis King

Added a bunch of voodoo to appease the bugs in visual studio. Also added

promotions to the global operator* overloads for the vector.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402737
parent 5348ed7f
...@@ -52,6 +52,23 @@ namespace dlib ...@@ -52,6 +52,23 @@ namespace dlib
typedef double type; typedef double type;
}; };
// ----------------------------------------------------------------------------------------
// This insanity here is to work around a bug in visual studio 8. These two rebind
// structures are actually declared at a few points in this file because just having the
// one declaration here isn't enough for visual studio. It takes the three spread around
// to avoid all its bugs.
template <typename T, long N>
struct vc_rebind
{
typedef vector<T,N> type;
};
template <typename T, typename U, long N>
struct vc_rebind_promote
{
typedef vector<typename promote<T,U>::type,N> type;
};
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename T, typename U, typename enabled = void> template <typename T, typename U, typename enabled = void>
...@@ -175,6 +192,18 @@ namespace dlib ...@@ -175,6 +192,18 @@ namespace dlib
!*/ !*/
// This insanity here is to work around a bug in visual studio 8.
template <typename T, long N>
struct vc_rebind
{
typedef vector<T,N> type;
};
template <typename T, typename U, long N>
struct vc_rebind_promote
{
typedef vector<typename promote<T,U>::type,N> type;
};
public: public:
typedef T type; typedef T type;
...@@ -312,7 +341,7 @@ namespace dlib ...@@ -312,7 +341,7 @@ namespace dlib
// --------------------------------------- // ---------------------------------------
vector<double,3> normalize ( typename vc_rebind<double,3>::type normalize (
) const ) const
{ {
const double tmp = std::sqrt((double)(x()*x() + y()*y() + z()*z())); const double tmp = std::sqrt((double)(x()*x() + y()*y() + z()*z()));
...@@ -392,7 +421,7 @@ namespace dlib ...@@ -392,7 +421,7 @@ namespace dlib
// --------------------------------------- // ---------------------------------------
template <typename U, long N> template <typename U, long N>
vector<typename promote<T,U>::type,3> cross ( typename vc_rebind_promote<T,U,3>::type cross (
const vector<U,N>& rhs const vector<U,N>& rhs
) const ) const
{ {
...@@ -456,7 +485,7 @@ namespace dlib ...@@ -456,7 +485,7 @@ namespace dlib
// --------------------------------------- // ---------------------------------------
template <typename U, long N> template <typename U, long N>
vector<typename promote<T,U>::type,3> operator + ( typename vc_rebind_promote<T,U,3>::type operator + (
const vector<U,N>& rhs const vector<U,N>& rhs
) const ) const
{ {
...@@ -476,7 +505,7 @@ namespace dlib ...@@ -476,7 +505,7 @@ namespace dlib
// --------------------------------------- // ---------------------------------------
template <typename U, long N> template <typename U, long N>
vector<typename promote<T,U>::type,3> operator - ( typename vc_rebind_promote<T,U,3>::type operator - (
const vector<U,N>& rhs const vector<U,N>& rhs
) const ) const
{ {
...@@ -496,7 +525,7 @@ namespace dlib ...@@ -496,7 +525,7 @@ namespace dlib
// --------------------------------------- // ---------------------------------------
template <typename U> template <typename U>
vector<typename promote<T,U>::type,3> operator / ( typename vc_rebind_promote<T,U,3>::type operator / (
const U& val const U& val
) const ) const
{ {
...@@ -555,6 +584,19 @@ namespace dlib ...@@ -555,6 +584,19 @@ namespace dlib
- z() == 0 - z() == 0
!*/ !*/
// This insanity here is to work around a bug in visual studio 8.
template <typename T, long N>
struct vc_rebind
{
typedef vector<T,N> type;
};
template <typename T, typename U, long N>
struct vc_rebind_promote
{
typedef vector<typename promote<T,U>::type,N> type;
};
public: public:
typedef T type; typedef T type;
...@@ -685,7 +727,8 @@ namespace dlib ...@@ -685,7 +727,8 @@ namespace dlib
// --------------------------------------- // ---------------------------------------
vector<double,2> normalize (
typename vc_rebind<double,2>::type normalize (
) const ) const
{ {
const double tmp = std::sqrt((double)(x()*x() + y()*y())); const double tmp = std::sqrt((double)(x()*x() + y()*y()));
...@@ -809,7 +852,7 @@ namespace dlib ...@@ -809,7 +852,7 @@ namespace dlib
// --------------------------------------- // ---------------------------------------
template <typename U, long N> template <typename U, long N>
vector<typename promote<T,U>::type,N> operator + ( typename vc_rebind_promote<T,U,N>::type operator + (
const vector<U,N>& rhs const vector<U,N>& rhs
) const ) const
{ {
...@@ -829,7 +872,7 @@ namespace dlib ...@@ -829,7 +872,7 @@ namespace dlib
// --------------------------------------- // ---------------------------------------
template <typename U, long N> template <typename U, long N>
vector<typename promote<T,U>::type,N> operator - ( typename vc_rebind_promote<T,U,N>::type operator - (
const vector<U,N>& rhs const vector<U,N>& rhs
) const ) const
{ {
...@@ -840,7 +883,7 @@ namespace dlib ...@@ -840,7 +883,7 @@ namespace dlib
// --------------------------------------- // ---------------------------------------
template <typename U> template <typename U>
vector<typename promote<T,U>::type,2> operator / ( typename vc_rebind_promote<T,U,2>::type operator / (
const U& val const U& val
) const ) const
{ {
...@@ -899,7 +942,7 @@ namespace dlib ...@@ -899,7 +942,7 @@ namespace dlib
// --------------------------------------- // ---------------------------------------
template <typename U, long N> template <typename U, long N>
vector<typename promote<T,U>::type,3> cross ( typename vc_rebind_promote<T,U,3>::type cross (
const vector<U,N>& rhs const vector<U,N>& rhs
) const ) const
{ {
...@@ -921,45 +964,49 @@ namespace dlib ...@@ -921,45 +964,49 @@ namespace dlib
template <typename T, typename U> template <typename T, typename U>
inline typename disable_if<is_matrix<U>, const vector<T,2> >::type operator* ( inline typename disable_if<is_matrix<U>, const typename vc_rebind_promote<T,U,2>::type >::type operator* (
const vector<T,2>& v, const vector<T,2>& v,
const U& s const U& s
) )
{ {
return vector<T,2>(v.x()*s, v.y()*s); typedef typename vc_rebind_promote<T,U,2>::type ret_type;
return ret_type(v.x()*s, v.y()*s);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename T, typename U> template <typename T, typename U>
inline typename disable_if<is_matrix<U>, const vector<T,2> >::type operator* ( inline typename disable_if<is_matrix<U>, const typename vc_rebind_promote<T,U,2>::type >::type operator* (
const U& s, const U& s,
const vector<T,2>& v const vector<T,2>& v
) )
{ {
return vector<T,2>(v.x()*s, v.y()*s); typedef typename vc_rebind_promote<T,U,2>::type ret_type;
return ret_type(v.x()*s, v.y()*s);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename T, typename U> template <typename T, typename U>
inline typename disable_if<is_matrix<U>, const vector<T,3> >::type operator* ( inline typename disable_if<is_matrix<U>, const typename vc_rebind_promote<T,U,3>::type >::type operator* (
const vector<T,3>& v, const vector<T,3>& v,
const U& s const U& s
) )
{ {
return vector<T,3>(v.x()*s, v.y()*s, v.z()*s); typedef typename vc_rebind_promote<T,U,3>::type ret_type;
return ret_type(v.x()*s, v.y()*s, v.z()*s);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename T, typename U> template <typename T, typename U>
inline typename disable_if<is_matrix<U>, const vector<T,3> >::type operator* ( inline typename disable_if<is_matrix<U>, const typename vc_rebind_promote<T,U,3>::type >::type operator* (
const U& s, const U& s,
const vector<T,3>& v const vector<T,3>& v
) )
{ {
return vector<T,3>(v.x()*s, v.y()*s, v.z()*s); typedef typename vc_rebind_promote<T,U,3>::type ret_type;
return ret_type(v.x()*s, v.y()*s, v.z()*s);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -202,6 +202,19 @@ namespace ...@@ -202,6 +202,19 @@ namespace
DLIB_CASSERT(vd3.y() == 4*2 + 5*3 + 6*4,""); DLIB_CASSERT(vd3.y() == 4*2 + 5*3 + 6*4,"");
DLIB_CASSERT(vd3.z() == 7*2 + 8*3 + 9*4,""); DLIB_CASSERT(vd3.z() == 7*2 + 8*3 + 9*4,"");
(vd3*2).dot(vd3);
(vd2*2).dot(vd3);
(vd3*2).dot(vd2);
(vd2*2).dot(vd2);
(2*vd3*2).dot(vd3);
(2*vd2*2).dot(vd3);
(2*vd3*2).dot(vd2);
(2*vd2*2).dot(vd2);
(vd2 + vd3).dot(vd2);
(vd2 - vd3).dot(vd2);
(vd2/2).dot(vd2);
(vd3/2).dot(vd2);
} }
} }
......
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