//          Copyright Carl Philipp Reh 2009 - 2021.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

#ifndef FCPPT_MATH_MATRIX_IDENTITY_HPP_INCLUDED
#define FCPPT_MATH_MATRIX_IDENTITY_HPP_INCLUDED

#include <fcppt/literal.hpp>
#include <fcppt/math/size_type.hpp>
#include <fcppt/math/matrix/index.hpp>
#include <fcppt/math/matrix/init.hpp>
#include <fcppt/math/matrix/is_matrix.hpp>
#include <fcppt/math/matrix/to_static.hpp>
#include <fcppt/type_traits/value_type.hpp>

namespace fcppt::math::matrix
{
/**
\brief Returns the identity matrix;

\ingroup fcpptmathmatrix
*/
template <typename Matrix>
fcppt::math::matrix::to_static<Matrix> identity()
  requires fcppt::math::matrix::is_matrix<Matrix>::value
{
  using result_type = fcppt::math::matrix::to_static<Matrix>;

  using value_type = fcppt::type_traits::value_type<result_type>;

  return fcppt::math::matrix::init<result_type>(
      []<fcppt::math::size_type Row, fcppt::math::size_type Col>(
          fcppt::math::matrix::index<Row, Col>)
      { return Row == Col ? fcppt::literal<value_type>(1) : fcppt::literal<value_type>(0); });
}
}

#endif
