// L============================================================================= // L This software is distributed under the MIT license. // L Copyright 2021 Péter Kardos // L============================================================================= #pragma once #include "../Matrix/MatrixImpl.hpp" #include "../Quaternion/QuaternionImpl.hpp" #include "ZeroBuilder.hpp" namespace mathter { class IdentityBuilder { public: IdentityBuilder() = default; IdentityBuilder& operator=(const IdentityBuilder&) = delete; template operator Matrix() const { Matrix m; Set(m); return m; } template operator Quaternion() const { return Quaternion{ 1, 0, 0, 0 }; } private: template void Set(Matrix& m) const { m = Zero(); for (int i = 0; i < std::min(Rows, Columns); ++i) { m(i, i) = T(1); } } }; /// Creates an identity matrix or identity quaternion. /// If the matrix is not square, it will look like a truncated larger square identity matrix. inline auto Identity() { return IdentityBuilder{}; } } // namespace mathter