Added more operators + tests
This commit is contained in:
parent
5f1d070547
commit
682202825e
4 changed files with 68 additions and 10 deletions
|
|
@ -35,6 +35,7 @@ namespace rotgen
|
|||
matrix_impl64& operator*=(double d);
|
||||
|
||||
friend std::ostream& operator<<(std::ostream&,matrix_impl64 const&);
|
||||
friend bool operator==(matrix_impl64 const& lhs, matrix_impl64 const& rhs);
|
||||
|
||||
private:
|
||||
struct payload;
|
||||
|
|
|
|||
|
|
@ -11,14 +11,21 @@
|
|||
|
||||
namespace rotgen
|
||||
{
|
||||
template<typename Scalar, int Rows = -1, int Cols = -1>
|
||||
template< typename Scalar, int Rows = -1 , int Cols = -1
|
||||
, int Options = 0, int MaxRows = Rows, int MaxCols = Cols
|
||||
>
|
||||
class matrix : public matrix_impl64
|
||||
{
|
||||
using parent = matrix_impl64;
|
||||
|
||||
public:
|
||||
matrix() : parent(Rows==-1?0:Rows,Cols==-1?0:Cols) {}
|
||||
matrix(std::size_t r, std::size_t c) : parent(r,c) {}
|
||||
matrix() : parent(Rows==-1?0:Rows,Cols==-1?0:Cols) {}
|
||||
matrix(std::size_t r, std::size_t c) : parent(r,c) {}
|
||||
|
||||
friend bool operator==(matrix const& lhs, matrix const& rhs)
|
||||
{
|
||||
return static_cast<parent const&>(lhs) == static_cast<parent const&>(rhs);
|
||||
}
|
||||
|
||||
matrix& operator+=(matrix const& rhs)
|
||||
{
|
||||
|
|
@ -31,19 +38,38 @@ namespace rotgen
|
|||
static_cast<parent&>(*this) *= static_cast<parent const&>(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
matrix& operator*=(double rhs)
|
||||
{
|
||||
static_cast<parent&>(*this) *= rhs;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename S, int R, int C>
|
||||
matrix<S,R,C> operator+(matrix<S,R,C> const& lhs, matrix<S,R,C> const& rhs)
|
||||
template<typename S, int R, int C, int O, int MR, int MC>
|
||||
matrix<S,R,C,O,MR,MC> operator+(matrix<S,R,C,O,MR,MC> const& lhs, matrix<S,R,C,O,MR,MC> const& rhs)
|
||||
{
|
||||
matrix<S,R,C> that(lhs);
|
||||
matrix<S,R,C,O,MR,MC> that(lhs);
|
||||
return that += rhs;
|
||||
}
|
||||
|
||||
template<typename S, int R, int C>
|
||||
matrix<S,R,C> operator*(matrix<S,R,C> const& lhs, matrix<S,R,C> const& rhs)
|
||||
template<typename S, int R, int C, int O, int MR, int MC>
|
||||
matrix<S,R,C,O,MR,MC> operator*(matrix<S,R,C,O,MR,MC> const& lhs, matrix<S,R,C,O,MR,MC> const& rhs)
|
||||
{
|
||||
matrix<S,R,C> that(lhs);
|
||||
matrix<S,R,C,O,MR,MC> that(lhs);
|
||||
return that *= rhs;
|
||||
}
|
||||
|
||||
template<typename S, int R, int C, int O, int MR, int MC>
|
||||
matrix<S,R,C,O,MR,MC> operator*(matrix<S,R,C,O,MR,MC> const& lhs, double rhs)
|
||||
{
|
||||
matrix<S,R,C,O,MR,MC> that(lhs);
|
||||
return that *= rhs;
|
||||
}
|
||||
|
||||
template<typename S, int R, int C, int O, int MR, int MC>
|
||||
matrix<S,R,C,O,MR,MC> operator*(double lhs, matrix<S,R,C,O,MR,MC> const& rhs)
|
||||
{
|
||||
return rhs * lhs;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue