diff --git a/src/DGtal/kernel/ArithmeticConversionTraits.h b/src/DGtal/kernel/ArithmeticConversionTraits.h index 84ec33f7f3..9f39c66196 100644 --- a/src/DGtal/kernel/ArithmeticConversionTraits.h +++ b/src/DGtal/kernel/ArithmeticConversionTraits.h @@ -44,7 +44,7 @@ namespace DGtal { - + ///////////////////////////////////////////////////////////////////////////// // template class ArithmeticConversionTraits /** @@ -92,23 +92,23 @@ namespace DGtal struct ArithmeticConversionTraits { }; - + /** @brief Specialization in order to remove const specifiers and references from given types * * @see ArithmeticConversionTraits */ template struct ArithmeticConversionTraits< T, U, - typename std::enable_if< - ! std::is_same< T, typename std::remove_cv< typename std::remove_reference::type >::type >::value - || ! std::is_same< U, typename std::remove_cv< typename std::remove_reference::type >::type >::value >::type > - : ArithmeticConversionTraits< - typename std::remove_cv< typename std::remove_reference::type >::type, - typename std::remove_cv< typename std::remove_reference::type >::type > + typename std::enable_if< + ! std::is_same< T, typename std::remove_cv< typename std::remove_reference::type >::type >::value + || ! std::is_same< U, typename std::remove_cv< typename std::remove_reference::type >::type >::value >::type > + : ArithmeticConversionTraits< + typename std::remove_cv< typename std::remove_reference::type >::type, + typename std::remove_cv< typename std::remove_reference::type >::type > { }; - - + + /** @brief Specialization for (fundamental) arithmetic types. * * Resulting type is deduced from usual arithmetic conversion using @@ -118,12 +118,12 @@ namespace DGtal */ template struct ArithmeticConversionTraits< T, U, - typename std::enable_if< std::is_arithmetic::value - && std::is_arithmetic::value >::type > + typename std::enable_if< std::is_arithmetic::value + && std::is_arithmetic::value >::type > { using type = typename std::common_type::type; //! Arithmetic operation result type. }; - + /** @brief Result type of arithmetic binary operators between two given types. * * @tparam T First operand type. @@ -133,7 +133,7 @@ namespace DGtal */ template using ArithmeticConversionType = typename ArithmeticConversionTraits::type; - + /** @brief Helper to determine if an arithmetic operation between two given * types has a valid result type (ie is valid). * @@ -143,10 +143,10 @@ namespace DGtal */ template struct IsArithmeticConversionValid - : std::false_type + : std::false_type { }; - + /** @brief Specialization when arithmetic operation between the two given * type is valid. * @@ -157,12 +157,12 @@ namespace DGtal */ template struct IsArithmeticConversionValid, void>::type > - : std::true_type + typename std::conditional, void>::type > + : std::true_type { }; - - + + /** @brief Call constructor for the result type of an arithmetic operation. * * @tparam LHS First operand type. @@ -174,20 +174,19 @@ namespace DGtal * @param args Parameters forwarded to the constructor. */ template < - typename LHS, - typename RHS, - typename... Args > + typename LHS, + typename RHS, + typename... Args > inline ArithmeticConversionType constructFromArithmeticConversion( LHS const& lhs, RHS const& rhs, Args &&... args ) - { - boost::ignore_unused_variable_warning(lhs); - boost::ignore_unused_variable_warning(rhs); - - return ArithmeticConversionType( std::forward(args)... ); - } - -#ifdef WITH_BIGINTEGER + { + boost::ignore_unused_variable_warning(lhs); + boost::ignore_unused_variable_warning(rhs); + + return ArithmeticConversionType( std::forward(args)... ); + } + #ifdef WITH_GMP /** @brief Specialization when first operand is a @ref BigInteger. * @@ -198,12 +197,12 @@ namespace DGtal */ template struct ArithmeticConversionTraits, - typename std::enable_if< std::is_integral::value >::type > + typename std::enable_if< std::is_integral::value >::type > { using type = BigInteger; }; - - /** @brief Specialization when second operand is a @ref BigInteger. + + /** @brief Specialization when second operand is a @ref BigInteger with GMP. * * @warning result type if set to BigInteger instead of the possible * more complex __gmp_expr. @@ -212,11 +211,11 @@ namespace DGtal */ template struct ArithmeticConversionTraits<__gmp_expr, U, - typename std::enable_if< std::is_integral::value >::type > + typename std::enable_if< std::is_integral::value >::type > { using type = BigInteger; }; - + /** @brief Specialization when both operands are @ref BigInteger. * * @warning result type if set to BigInteger instead of the possible @@ -230,9 +229,10 @@ namespace DGtal using type = BigInteger; }; #endif -#endif + } // namespace DGtal + #endif // !defined ArithmeticConversionTraits_h #undef ArithmeticConversionTraits_RECURSES diff --git a/src/DGtal/kernel/PointVector.ih b/src/DGtal/kernel/PointVector.ih index ab39cc4857..49d2a5bac8 100644 --- a/src/DGtal/kernel/PointVector.ih +++ b/src/DGtal/kernel/PointVector.ih @@ -35,7 +35,6 @@ #include #include #include -#include "DGtal/io/Color.h" ////////////////////////////////////////////////////////////////////////////// @@ -1042,7 +1041,13 @@ inline typename DGtal::PointVector > DGtal::PointVector::getNormalized() const { - PointVector > normalized =(*this); + // Orginal: PointVector > normalized(*this); + // Not workling too: PointVector > normalized(*this, [](const auto v){return NumberTraits::castToDouble(v);});); + PointVector > normalized; + for ( DGtal::Dimension i = 0; i < dim; ++i ) + normalized[i] = NumberTraits::castToDouble( this->operator[](i)); + ///FIXME: HERE + ///TODO: HERE normalized /= normalized.norm(); return normalized; } diff --git a/tests/kernel/testInteger.cpp b/tests/kernel/testInteger.cpp index f6991a2e90..fd8294d513 100644 --- a/tests/kernel/testInteger.cpp +++ b/tests/kernel/testInteger.cpp @@ -91,11 +91,20 @@ TEST_CASE( "Checking CInteger models") trace.info() << " - digits unsigned int = " << NumberTraits::digits()<< std::endl; trace.info() << " - digits long int = " << NumberTraits::digits()<< std::endl; trace.endBlock(); +} + +TEST_CASE("DGal::BigInteger tests") +{ + trace.beginBlock ( "Checking CUnsignedInteger models ..." ); + BOOST_CONCEPT_ASSERT(( concepts::CInteger )); + trace.endBlock(); + DGtal::BigInteger big(425); + CHECK(big == (int)425); - int a = 42; - DGtal::BigInteger b(42); - CHECK(a == b); + DGtal::BigInteger anotherbig(5); + DGtal::BigInteger res = big + anotherbig; + CHECK(res == (int)430); } // //