Skip to content

Commit

Permalink
WIP (Fixing type issues)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoeurjo committed Dec 6, 2024
1 parent 2670b95 commit dddd8be
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 42 deletions.
74 changes: 37 additions & 37 deletions src/DGtal/kernel/ArithmeticConversionTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

namespace DGtal
{

/////////////////////////////////////////////////////////////////////////////
// template class ArithmeticConversionTraits
/**
Expand Down Expand Up @@ -92,23 +92,23 @@ namespace DGtal
struct ArithmeticConversionTraits
{
};

/** @brief Specialization in order to remove const specifiers and references from given types
*
* @see ArithmeticConversionTraits
*/
template <typename T, typename U>
struct ArithmeticConversionTraits< T, U,
typename std::enable_if<
! std::is_same< T, typename std::remove_cv< typename std::remove_reference<T>::type >::type >::value
|| ! std::is_same< U, typename std::remove_cv< typename std::remove_reference<U>::type >::type >::value >::type >
: ArithmeticConversionTraits<
typename std::remove_cv< typename std::remove_reference<T>::type >::type,
typename std::remove_cv< typename std::remove_reference<U>::type >::type >
typename std::enable_if<
! std::is_same< T, typename std::remove_cv< typename std::remove_reference<T>::type >::type >::value
|| ! std::is_same< U, typename std::remove_cv< typename std::remove_reference<U>::type >::type >::value >::type >
: ArithmeticConversionTraits<
typename std::remove_cv< typename std::remove_reference<T>::type >::type,
typename std::remove_cv< typename std::remove_reference<U>::type >::type >
{
};


/** @brief Specialization for (fundamental) arithmetic types.
*
* Resulting type is deduced from usual arithmetic conversion using
Expand All @@ -118,12 +118,12 @@ namespace DGtal
*/
template <typename T, typename U>
struct ArithmeticConversionTraits< T, U,
typename std::enable_if< std::is_arithmetic<T>::value
&& std::is_arithmetic<U>::value >::type >
typename std::enable_if< std::is_arithmetic<T>::value
&& std::is_arithmetic<U>::value >::type >
{
using type = typename std::common_type<T, U>::type; //! Arithmetic operation result type.
};

/** @brief Result type of arithmetic binary operators between two given types.
*
* @tparam T First operand type.
Expand All @@ -133,7 +133,7 @@ namespace DGtal
*/
template <typename T, typename U>
using ArithmeticConversionType = typename ArithmeticConversionTraits<T, U>::type;

/** @brief Helper to determine if an arithmetic operation between two given
* types has a valid result type (ie is valid).
*
Expand All @@ -143,10 +143,10 @@ namespace DGtal
*/
template <typename T, typename U, typename Enable = void>
struct IsArithmeticConversionValid
: std::false_type
: std::false_type
{
};

/** @brief Specialization when arithmetic operation between the two given
* type is valid.
*
Expand All @@ -157,12 +157,12 @@ namespace DGtal
*/
template <typename T, typename U>
struct IsArithmeticConversionValid<T, U,
typename std::conditional<false, ArithmeticConversionType<T, U>, void>::type >
: std::true_type
typename std::conditional<false, ArithmeticConversionType<T, U>, void>::type >
: std::true_type
{
};


/** @brief Call constructor for the result type of an arithmetic operation.
*
* @tparam LHS First operand type.
Expand All @@ -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<LHS, RHS>
constructFromArithmeticConversion( LHS const& lhs, RHS const& rhs, Args &&... args )
{
boost::ignore_unused_variable_warning(lhs);
boost::ignore_unused_variable_warning(rhs);

return ArithmeticConversionType<LHS, RHS>( std::forward<Args>(args)... );
}

#ifdef WITH_BIGINTEGER
{
boost::ignore_unused_variable_warning(lhs);
boost::ignore_unused_variable_warning(rhs);

return ArithmeticConversionType<LHS, RHS>( std::forward<Args>(args)... );
}

#ifdef WITH_GMP
/** @brief Specialization when first operand is a @ref BigInteger.
*
Expand All @@ -198,12 +197,12 @@ namespace DGtal
*/
template <typename T, typename GMP1, typename GMP2>
struct ArithmeticConversionTraits<T, __gmp_expr<GMP1, GMP2>,
typename std::enable_if< std::is_integral<T>::value >::type >
typename std::enable_if< std::is_integral<T>::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.
Expand All @@ -212,11 +211,11 @@ namespace DGtal
*/
template <typename GMP1, typename GMP2, typename U>
struct ArithmeticConversionTraits<__gmp_expr<GMP1, GMP2>, U,
typename std::enable_if< std::is_integral<U>::value >::type >
typename std::enable_if< std::is_integral<U>::value >::type >
{
using type = BigInteger;
};

/** @brief Specialization when both operands are @ref BigInteger.
*
* @warning result type if set to BigInteger instead of the possible
Expand All @@ -230,9 +229,10 @@ namespace DGtal
using type = BigInteger;
};
#endif
#endif
} // namespace DGtal


#endif // !defined ArithmeticConversionTraits_h

#undef ArithmeticConversionTraits_RECURSES
Expand Down
9 changes: 7 additions & 2 deletions src/DGtal/kernel/PointVector.ih
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include <cstdlib>
#include <cmath>
#include <DGtal/base/BasicFunctors.h>
#include "DGtal/io/Color.h"
//////////////////////////////////////////////////////////////////////////////


Expand Down Expand Up @@ -1042,7 +1041,13 @@ inline
typename DGtal::PointVector<dim, double, std::array<double,dim> >
DGtal::PointVector<dim, TComponent, TContainer>::getNormalized() const
{
PointVector<dim,double,std::array<double,dim> > normalized =(*this);
// Orginal: PointVector<dim,double,std::array<double,dim> > normalized(*this);
// Not workling too: PointVector<dim,double,std::array<double,dim> > normalized(*this, [](const auto v){return NumberTraits<TComponent>::castToDouble(v);}););
PointVector<dim,double,std::array<double,dim> > normalized;
for ( DGtal::Dimension i = 0; i < dim; ++i )
normalized[i] = NumberTraits<TComponent>::castToDouble( this->operator[](i));
///FIXME: HERE
///TODO: HERE
normalized /= normalized.norm();
return normalized;
}
Expand Down
15 changes: 12 additions & 3 deletions tests/kernel/testInteger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,20 @@ TEST_CASE( "Checking CInteger models")
trace.info() << " - digits unsigned int = " << NumberTraits<unsigned int>::digits()<< std::endl;
trace.info() << " - digits long int = " << NumberTraits<long int>::digits()<< std::endl;
trace.endBlock();
}

TEST_CASE("DGal::BigInteger tests")
{
trace.beginBlock ( "Checking CUnsignedInteger models ..." );
BOOST_CONCEPT_ASSERT(( concepts::CInteger<DGtal::BigInteger> ));
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);
}

// //
Expand Down

0 comments on commit dddd8be

Please sign in to comment.