#ifndef Magnum_DimensionTraits_h #define Magnum_DimensionTraits_h /* This file is part of Magnum. Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025 Vladimír Vondruš Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /** @file * @brief Class @ref Magnum::DimensionTraits, alias @ref Magnum::VectorTypeFor, @ref Magnum::RangeTypeFor, @ref Magnum::MatrixTypeFor */ #include "Magnum/Math/Math.h" #include "Magnum/Types.h" namespace Magnum { /** @brief Matrix and vector specializations for given dimension count @see @ref VectorTypeFor, @ref RangeTypeFor, @ref MatrixTypeFor */ template struct DimensionTraits { DimensionTraits() = delete; #ifdef DOXYGEN_GENERATING_OUTPUT /** * @brief Vector type * * @ref Math::Vector, @ref Math::Vector2 or @ref Math::Vector3 based on * dimension count. */ typedef U VectorType; /** * @brief Range type * * @ref Math::Range1D, @ref Math::Range2D or @ref Math::Range3D based on * dimension count. */ typedef U RangeType; /** * @brief Matrix type * * Floating-point @ref Math::Matrix3 or @ref Math::Matrix4 for 2D or 3D. No * matrix type defined for one dimension and integral types. */ typedef U MatrixType; #endif }; /** @brief Vector type for given dimension count and type Convenience alternative to @cpp typename DimensionTraits::VectorType @ce. See @ref DimensionTraits::VectorType for more information. */ template using VectorTypeFor = typename DimensionTraits::VectorType; /** @brief Range type for given dimension count and type Convenience alternative to @cpp typename DimensionTraits::RangeType @ce. See @ref DimensionTraits::RangeType for more information. */ template using RangeTypeFor = typename DimensionTraits::RangeType; /** @brief Matrix type for given dimension count and type Convenience alternative to @cpp typename DimensionTraits::MatrixType @ce. See @ref DimensionTraits::MatrixType for more information. */ template using MatrixTypeFor = typename DimensionTraits::MatrixType; #ifndef DOXYGEN_GENERATING_OUTPUT /* One dimension */ template struct DimensionTraits<1, T> { DimensionTraits() = delete; typedef Math::Vector<1, T> VectorType; typedef Math::Range1D RangeType; }; /* Two dimensions - integral */ template struct DimensionTraits<2, T> { DimensionTraits() = delete; typedef Math::Vector2 VectorType; typedef Math::Range2D RangeType; }; /* Two dimensions - floating-point */ template<> struct DimensionTraits<2, Float> { DimensionTraits() = delete; typedef Math::Vector2 VectorType; typedef Math::Range2D RangeType; typedef Math::Matrix3 MatrixType; }; template<> struct DimensionTraits<2, Double> { DimensionTraits() = delete; typedef Math::Vector2 VectorType; typedef Math::Range2D RangeType; typedef Math::Matrix3 MatrixType; }; /* Three dimensions - integral */ template struct DimensionTraits<3, T> { DimensionTraits() = delete; typedef Math::Vector3 VectorType; typedef Math::Range3D RangeType; }; /* Three dimensions - floating-point */ template<> struct DimensionTraits<3, Float> { DimensionTraits() = delete; typedef Math::Vector3 VectorType; typedef Math::Range3D RangeType; typedef Math::Matrix4 MatrixType; }; template<> struct DimensionTraits<3, Double> { DimensionTraits() = delete; typedef Math::Vector3 VectorType; typedef Math::Range3D RangeType; typedef Math::Matrix4 MatrixType; }; #endif } #endif