round.hpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /// @ref gtc_round
  2. /// @file glm/gtc/round.hpp
  3. ///
  4. /// @see core (dependence)
  5. /// @see gtc_round (dependence)
  6. ///
  7. /// @defgroup gtc_round GLM_GTC_round
  8. /// @ingroup gtc
  9. ///
  10. /// Include <glm/gtc/round.hpp> to use the features of this extension.
  11. ///
  12. /// Rounding value to specific boundings
  13. #pragma once
  14. // Dependencies
  15. #include "../detail/setup.hpp"
  16. #include "../detail/qualifier.hpp"
  17. #include "../detail/_vectorize.hpp"
  18. #include "../vector_relational.hpp"
  19. #include "../common.hpp"
  20. #include <limits>
  21. #if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
  22. # pragma message("GLM: GLM_GTC_integer extension included")
  23. #endif
  24. namespace glm
  25. {
  26. /// @addtogroup gtc_round
  27. /// @{
  28. /// Return true if the value is a power of two number.
  29. ///
  30. /// @see gtc_round
  31. template<typename genIUType>
  32. GLM_FUNC_DECL bool isPowerOfTwo(genIUType v);
  33. /// Return true if the value is a power of two number.
  34. ///
  35. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  36. /// @tparam T Floating-point or integer scalar types
  37. /// @tparam Q Value from qualifier enum
  38. ///
  39. /// @see gtc_round
  40. template<length_t L, typename T, qualifier Q>
  41. GLM_FUNC_DECL vec<L, bool, Q> isPowerOfTwo(vec<L, T, Q> const& v);
  42. /// Return the power of two number which value is just higher the input value,
  43. /// round up to a power of two.
  44. ///
  45. /// @see gtc_round
  46. template<typename genIUType>
  47. GLM_FUNC_DECL genIUType ceilPowerOfTwo(genIUType v);
  48. /// Return the power of two number which value is just higher the input value,
  49. /// round up to a power of two.
  50. ///
  51. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  52. /// @tparam T Floating-point or integer scalar types
  53. /// @tparam Q Value from qualifier enum
  54. ///
  55. /// @see gtc_round
  56. template<length_t L, typename T, qualifier Q>
  57. GLM_FUNC_DECL vec<L, T, Q> ceilPowerOfTwo(vec<L, T, Q> const& v);
  58. /// Return the power of two number which value is just lower the input value,
  59. /// round down to a power of two.
  60. ///
  61. /// @see gtc_round
  62. template<typename genIUType>
  63. GLM_FUNC_DECL genIUType floorPowerOfTwo(genIUType v);
  64. /// Return the power of two number which value is just lower the input value,
  65. /// round down to a power of two.
  66. ///
  67. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  68. /// @tparam T Floating-point or integer scalar types
  69. /// @tparam Q Value from qualifier enum
  70. ///
  71. /// @see gtc_round
  72. template<length_t L, typename T, qualifier Q>
  73. GLM_FUNC_DECL vec<L, T, Q> floorPowerOfTwo(vec<L, T, Q> const& v);
  74. /// Return the power of two number which value is the closet to the input value.
  75. ///
  76. /// @see gtc_round
  77. template<typename genIUType>
  78. GLM_FUNC_DECL genIUType roundPowerOfTwo(genIUType v);
  79. /// Return the power of two number which value is the closet to the input value.
  80. ///
  81. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  82. /// @tparam T Floating-point or integer scalar types
  83. /// @tparam Q Value from qualifier enum
  84. ///
  85. /// @see gtc_round
  86. template<length_t L, typename T, qualifier Q>
  87. GLM_FUNC_DECL vec<L, T, Q> roundPowerOfTwo(vec<L, T, Q> const& v);
  88. /// Return true if the 'Value' is a multiple of 'Multiple'.
  89. ///
  90. /// @see gtc_round
  91. template<typename genIUType>
  92. GLM_FUNC_DECL bool isMultiple(genIUType v, genIUType Multiple);
  93. /// Return true if the 'Value' is a multiple of 'Multiple'.
  94. ///
  95. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  96. /// @tparam T Floating-point or integer scalar types
  97. /// @tparam Q Value from qualifier enum
  98. ///
  99. /// @see gtc_round
  100. template<length_t L, typename T, qualifier Q>
  101. GLM_FUNC_DECL vec<L, bool, Q> isMultiple(vec<L, T, Q> const& v, T Multiple);
  102. /// Return true if the 'Value' is a multiple of 'Multiple'.
  103. ///
  104. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  105. /// @tparam T Floating-point or integer scalar types
  106. /// @tparam Q Value from qualifier enum
  107. ///
  108. /// @see gtc_round
  109. template<length_t L, typename T, qualifier Q>
  110. GLM_FUNC_DECL vec<L, bool, Q> isMultiple(vec<L, T, Q> const& v, vec<L, T, Q> const& Multiple);
  111. /// Higher multiple number of Source.
  112. ///
  113. /// @tparam genType Floating-point or integer scalar or vector types.
  114. ///
  115. /// @param v Source value to which is applied the function
  116. /// @param Multiple Must be a null or positive value
  117. ///
  118. /// @see gtc_round
  119. template<typename genType>
  120. GLM_FUNC_DECL genType ceilMultiple(genType v, genType Multiple);
  121. /// Higher multiple number of Source.
  122. ///
  123. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  124. /// @tparam T Floating-point or integer scalar types
  125. /// @tparam Q Value from qualifier enum
  126. ///
  127. /// @param v Source values to which is applied the function
  128. /// @param Multiple Must be a null or positive value
  129. ///
  130. /// @see gtc_round
  131. template<length_t L, typename T, qualifier Q>
  132. GLM_FUNC_DECL vec<L, T, Q> ceilMultiple(vec<L, T, Q> const& v, vec<L, T, Q> const& Multiple);
  133. /// Lower multiple number of Source.
  134. ///
  135. /// @tparam genType Floating-point or integer scalar or vector types.
  136. ///
  137. /// @param v Source value to which is applied the function
  138. /// @param Multiple Must be a null or positive value
  139. ///
  140. /// @see gtc_round
  141. template<typename genType>
  142. GLM_FUNC_DECL genType floorMultiple(genType v, genType Multiple);
  143. /// Lower multiple number of Source.
  144. ///
  145. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  146. /// @tparam T Floating-point or integer scalar types
  147. /// @tparam Q Value from qualifier enum
  148. ///
  149. /// @param v Source values to which is applied the function
  150. /// @param Multiple Must be a null or positive value
  151. ///
  152. /// @see gtc_round
  153. template<length_t L, typename T, qualifier Q>
  154. GLM_FUNC_DECL vec<L, T, Q> floorMultiple(vec<L, T, Q> const& v, vec<L, T, Q> const& Multiple);
  155. /// Lower multiple number of Source.
  156. ///
  157. /// @tparam genType Floating-point or integer scalar or vector types.
  158. ///
  159. /// @param v Source value to which is applied the function
  160. /// @param Multiple Must be a null or positive value
  161. ///
  162. /// @see gtc_round
  163. template<typename genType>
  164. GLM_FUNC_DECL genType roundMultiple(genType v, genType Multiple);
  165. /// Lower multiple number of Source.
  166. ///
  167. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  168. /// @tparam T Floating-point or integer scalar types
  169. /// @tparam Q Value from qualifier enum
  170. ///
  171. /// @param v Source values to which is applied the function
  172. /// @param Multiple Must be a null or positive value
  173. ///
  174. /// @see gtc_round
  175. template<length_t L, typename T, qualifier Q>
  176. GLM_FUNC_DECL vec<L, T, Q> roundMultiple(vec<L, T, Q> const& v, vec<L, T, Q> const& Multiple);
  177. /// @}
  178. } //namespace glm
  179. #include "round.inl"