From: Mikko Rasa Date: Mon, 20 May 2013 16:12:24 +0000 (+0300) Subject: Give Vector constructors from one higher/lower dimension X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=204db1dfb803a97481f2a8b3bbaf6e20be6e0980;p=libs%2Fmath.git Give Vector constructors from one higher/lower dimension These replace the augment/reduce_vector functions, which were in a rather odd place. --- diff --git a/source/geometry/affinetransformation.h b/source/geometry/affinetransformation.h index 430619e..0e377ba 100644 --- a/source/geometry/affinetransformation.h +++ b/source/geometry/affinetransformation.h @@ -168,46 +168,16 @@ inline AffineTransformation invert(const AffineTransformation &at) return r.invert(); } - -template -inline LinAl::Vector augment_vector(const LinAl::Vector &v, T s) -{ - LinAl::Vector r; - for(unsigned i=0; i -inline LinAl::Vector reduce_vector(const LinAl::Vector &v) -{ - LinAl::Vector r; - for(unsigned i=0; i -inline LinAl::Vector divide_vector(const LinAl::Vector &v) -{ - LinAl::Vector r; - for(unsigned i=0; i inline LinAl::Vector AffineTransformation::transform(const LinAl::Vector &v) const { - return reduce_vector(matrix*augment_vector(v, T(1))); + return LinAl::Vector(matrix*LinAl::Vector(v, T(1))); } template inline LinAl::Vector AffineTransformation::transform_linear(const LinAl::Vector &v) const { - return reduce_vector(matrix*augment_vector(v, T(0))); + return LinAl::Vector(matrix*LinAl::Vector(v, T(0))); } } // namespace Geometry diff --git a/source/linal/vector.h b/source/linal/vector.h index 369e3ff..a5c9a26 100644 --- a/source/linal/vector.h +++ b/source/linal/vector.h @@ -81,6 +81,10 @@ public: Vector(T, T, T, T); template Vector(const Vector &); + template + Vector(const Vector &, U); + template + explicit Vector(const Vector &); Vector &operator*=(T); Vector &operator/=(T); @@ -140,6 +144,23 @@ inline Vector::Vector(const Vector &v) (*this)[i] = v[i]; } +template +template +inline Vector::Vector(const Vector &v, U s) +{ + for(unsigned i=0; i +template +inline Vector::Vector(const Vector &v) +{ + for(unsigned i=0; i inline Vector &Vector::operator*=(T s) {