diff --git a/CMakeLists.txt b/CMakeLists.txt index d380fdb2..9c484fa1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,11 @@ if(PSEMEK_BUILD_TYPE STREQUAL "DEBUG") list(APPEND PSEMEK_DEFINITIONS "-DPSEMEK_DEBUG=1") endif() +option(PSEMEK_ROBUST_PREDICATES "Turn on robust geometric predicates" OFF) +if(PSEMEK_ROBUST_PREDICATES) + list(APPEND PSEMEK_DEFINITIONS "-DPSEMEK_ROBUST_PREDICATES=1") +endif() + set(PSEMEK_CXX_FLAGS) if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")) list(APPEND PSEMEK_CXX_FLAGS -Wall -Werror -Wextra -pedantic -Wno-narrowing -Wno-sign-compare) diff --git a/libs/geom/CMakeLists.txt b/libs/geom/CMakeLists.txt index af0efa85..e71c70f6 100644 --- a/libs/geom/CMakeLists.txt +++ b/libs/geom/CMakeLists.txt @@ -1,13 +1,18 @@ option(PSEMEK_GEOM_ROBUST_PREDICATES "Use robust geometric predicates" OFF) find_package(Boost REQUIRED) -find_package(GMP REQUIRED) +if(PSEMEK_ROBUST_PREDICATES) + find_package(GMP REQUIRED) +endif() file(GLOB_RECURSE PSEMEK_GEOM_HEADERS "include/*.hpp") file(GLOB_RECURSE PSEMEK_GEOM_SOURCES "source/*.cpp") psemek_add_library(psemek-geom ${PSEMEK_GEOM_HEADERS} ${PSEMEK_GEOM_SOURCES}) target_include_directories(psemek-geom PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") -target_link_libraries(psemek-geom PUBLIC psemek-util Boost::boost GMP) +target_link_libraries(psemek-geom PUBLIC psemek-util Boost::boost) +if(PSEMEK_ROBUST_PREDICATES) + target_link_libraries(psemek-geom PUBLIC gmp) +endif() psemek_glob_tests(psemek-geom tests) diff --git a/libs/geom/include/psemek/geom/incircle.hpp b/libs/geom/include/psemek/geom/incircle.hpp index 604c5dca..0fee0e11 100644 --- a/libs/geom/include/psemek/geom/incircle.hpp +++ b/libs/geom/include/psemek/geom/incircle.hpp @@ -5,7 +5,7 @@ #include #include -#ifdef PSEMEK_GEOM_ROBUST_PREDICATES +#ifdef PSEMEK_ROBUST_PREDICATES #include #endif @@ -40,6 +40,7 @@ namespace psemek::geom std::enable_if_t, sign_t> in_circle(robust_predicate_tag, point const & p0, point const & p1, point const & p2, point const & p3) { +#ifdef PSEMEK_ROBUST_PREDICATES constexpr T error = std::numeric_limits::epsilon() * T(29) / T(2); T const m01 = (p0[0] - p3[0]) * (p1[1] - p3[1]); @@ -77,6 +78,9 @@ namespace psemek::geom return in_circle(cast(p0), cast(p1), cast(p2), cast(p3)); } +#else + return in_circle(fast_predicate_tag{}, p0, p1, p2, p3); +#endif } template diff --git a/libs/geom/include/psemek/geom/orientation.hpp b/libs/geom/include/psemek/geom/orientation.hpp index 9b1ee544..acc06c73 100644 --- a/libs/geom/include/psemek/geom/orientation.hpp +++ b/libs/geom/include/psemek/geom/orientation.hpp @@ -5,7 +5,9 @@ #include #include +#ifdef PSEMEK_ROBUST_PREDICATES #include +#endif #include #include @@ -30,6 +32,7 @@ namespace psemek::geom std::enable_if_t, sign_t> orientation(robust_predicate_tag, point const & p0, point const & p1, point const & p2) { +#ifdef PSEMEK_ROBUST_PREDICATES constexpr T error = std::numeric_limits::epsilon() * T(5) / T(2); T const d = (p1[0] - p0[0]) * (p2[1] - p0[1]) @@ -48,6 +51,9 @@ namespace psemek::geom return orientation(cast(p0), cast(p1), cast(p2)); } +#else + return orientation(fast_predicate_tag{}, p0, p1, p2); +#endif } template