Skip to content

Commit e6b95de

Browse files
committed
cmake: add option to switch between double and float
1 parent add62a2 commit e6b95de

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ option(
7272
"Make Coal retro-compatible with HPP-FCL."
7373
FALSE
7474
)
75+
option(COAL_USE_DOUBLE_PRECISION "Use double precision (64-bit) instead of single precision (32-bit)" TRUE)
7576

7677
# Check if the submodule cmake have been initialized
7778
set(JRL_CMAKE_MODULES "${CMAKE_CURRENT_LIST_DIR}/cmake")

include/coal/data_types.h

+9
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ namespace coal {
6363
#ifdef COAL_BACKWARD_COMPATIBILITY_WITH_HPP_FCL
6464
// We keep the FCL_REAL typedef and the Vec[..]f typedefs for backward
6565
// compatibility.
66+
#ifdef COAL_USE_DOUBLE_PRECISION
6667
typedef double FCL_REAL;
68+
#else
69+
typedef float FCL_REAL;
70+
#endif
6771
typedef Eigen::Matrix<FCL_REAL, 3, 1> Vec3f;
6872
typedef Eigen::Matrix<FCL_REAL, 2, 1> Vec2f;
6973
typedef Eigen::Matrix<FCL_REAL, 6, 1> Vec6f;
@@ -74,8 +78,13 @@ typedef Eigen::Matrix<FCL_REAL, Eigen::Dynamic, 2, Eigen::RowMajor> Matrixx2f;
7478
typedef Eigen::Matrix<FCL_REAL, Eigen::Dynamic, Eigen::Dynamic> MatrixXf;
7579
#endif
7680

81+
#ifdef COAL_USE_DOUBLE_PRECISION
7782
COAL_DEPRECATED typedef double CoalScalar;
7883
typedef double Scalar;
84+
#else
85+
COAL_DEPRECATED typedef float CoalScalar;
86+
typedef float Scalar;
87+
#endif
7988
typedef Eigen::Matrix<Scalar, 3, 1> Vec3s;
8089
typedef Eigen::Matrix<Scalar, 2, 1> Vec2s;
8190
typedef Eigen::Matrix<Scalar, 6, 1> Vec6s;

src/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ if(COAL_ENABLE_LOGGING)
250250
)
251251
endif()
252252

253+
if (COAL_USE_DOUBLE_PRECISION)
254+
target_compile_definitions(${LIBRARY_NAME} PUBLIC COAL_USE_DOUBLE_PRECISION)
255+
endif()
256+
253257
if(WIN32)
254258
target_link_libraries(
255259
${LIBRARY_NAME}

0 commit comments

Comments
 (0)