Skip to content

Commit d820fe1

Browse files
authored
Refactored and cleaned up code (#3)
* Refactor CMake and moved to FetchContent * Update clang-format * Added separate folder and sub-namespace for rational functions * Renamed namespace `inclusion_ccd` -> `ticcd` to be more compact * Renamed `edgeEdgeCCD_double` -> `edgeEdgeCCC` and same for `vertexFaceCCD` * Renamed `inclusion_ccd.hpp` -> `ccd.hpp` * Removed unused functions from `interval_root_finder.cpp` * Added structs for NumCCD and Interval for readability compared to std::pairs * Moved related function into these structs for better encapsulation (including limited operator definitions) * Use Eigen::Array3d more to reduce the number of for loops and unrolled loops in the code (more easily maintained) * I benchmarked this changed and it was faster to use Eigen::Array3d over std::array<double, 3> * Renamed interval root finding methods * normalCCD -> depth first search (DFS) * horizontal_tree -> breadth first search (BFS) * replaced CCD_TYPE int with an enum * WARNING: changed order of no_zero_toi and ccd_method parameters
1 parent 7a5cc47 commit d820fe1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2547
-3802
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ColumnLimit: 80
55
UseTab: Never
66
IndentWidth: 4
77
TabWidth: 4
8-
BreakBeforeBraces: Allman
8+
BreakBeforeBraces: WebKit
99
AllowShortIfStatementsOnASingleLine: false
1010
IndentCaseLabels: false
1111
SortIncludes: false

.github/workflows/continuous.yml

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ name: Build
33
on:
44
push:
55
branches:
6-
- master
6+
- main
77
pull_request:
88
branches:
9-
- master
9+
- main
1010

1111
env:
1212
CTEST_OUTPUT_ON_FAILURE: ON
@@ -23,12 +23,12 @@ jobs:
2323
strategy:
2424
fail-fast: false
2525
matrix:
26-
os: [ubuntu-18.04, macos-latest]
26+
os: [ubuntu-20.04, macos-latest]
2727
config: [Debug, Release]
2828
include:
2929
- os: macos-latest
3030
name: macOS
31-
- os: ubuntu-18.04
31+
- os: ubuntu-20.04
3232
name: Linux
3333
steps:
3434
- name: Checkout repository
@@ -41,11 +41,12 @@ jobs:
4141
run: |
4242
sudo apt-get update
4343
sudo apt-get -o Acquire::Retries=3 install \
44-
ccache
44+
ccache \
45+
libgmp-dev
4546
4647
- name: Dependencies (macOS)
4748
if: runner.os == 'macOS'
48-
run: brew install ccache
49+
run: brew install ccache gmp
4950

5051
- name: Cache Build
5152
id: cache-build
@@ -59,26 +60,40 @@ jobs:
5960
ccache --max-size=1.0G
6061
ccache -V && ccache --show-stats && ccache --zero-stats
6162
62-
- name: Configure
63+
- name: Configure (Debug)
64+
if: matrix.config == 'Debug'
6365
run: |
6466
mkdir -p build
6567
cd build
6668
cmake .. \
6769
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
6870
-DCMAKE_BUILD_TYPE=${{ matrix.config }} \
71+
-DTIGHT_INCLUSION_SUPPRESS_PROGRESS_OUTPUT=ON
72+
73+
- name: Configure (Release)
74+
if: matrix.config == 'Release'
75+
run: |
76+
mkdir -p build
77+
cd build
78+
cmake .. \
79+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
80+
-DCMAKE_BUILD_TYPE=${{ matrix.config }} \
81+
-DTIGHT_INCLUSION_WITH_GMP=ON \
82+
-DTIGHT_INCLUSION_WITH_TESTS=ON \
83+
-DTIGHT_INCLUSION_SUPPRESS_PROGRESS_OUTPUT=ON
6984
7085
- name: Build
7186
run: cd build; make -j2; ccache --show-stats
7287

7388
- name: Tests
74-
run: cd build; make -j2; ./Tight_Inclusion_bin #ctest --verbose --output-on-failure
89+
run: cd build; ./Tight_Inclusion_bin
7590

7691
####################
7792
# Windows
7893
####################
7994

8095
Windows:
81-
runs-on: windows-2019
96+
runs-on: windows-latest
8297
env:
8398
CC: cl.exe
8499
CXX: cl.exe
@@ -120,6 +135,7 @@ jobs:
120135
cmake -G Ninja ^
121136
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache ^
122137
-DCMAKE_BUILD_TYPE=${{ matrix.config }} ^
138+
-DTIGHT_INCLUSION_SUPPRESS_PROGRESS_OUTPUT=ON ^
123139
-B build ^
124140
-S .
125141
cd build
@@ -129,4 +145,3 @@ jobs:
129145
run: |
130146
cd build
131147
./Tight_Inclusion_bin
132-
#ctest --verbose --output-on-failure

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ docs
227227

228228
## External dependancies
229229
external
230+
sample-queries
230231

231232
*.nosync
232233
###############################################################################

CMakeLists.txt

Lines changed: 128 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,161 @@
1-
cmake_minimum_required(VERSION 3.8)
2-
project(TI_CCD)
3-
4-
################################################################################
5-
set(CMAKE_CXX_STANDARD 11)
6-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1+
# Detects whether this is a top-level project
2+
get_directory_property(HAS_PARENT PARENT_DIRECTORY)
3+
if(HAS_PARENT)
4+
set(TIGHT_INCLUSION_TOPLEVEL_PROJECT OFF)
5+
else()
6+
set(TIGHT_INCLUSION_TOPLEVEL_PROJECT ON)
7+
endif()
78

8-
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
9-
set(TIGHT_INCLUSION_TOPLEVEL_PROJECT ON)
10-
message(STATUS "Tight-Inclusion CCD top-level project")
9+
# Check required CMake version
10+
set(REQUIRED_CMAKE_VERSION "3.14.0")
11+
if(TIGHT_INCLUSION_TOPLEVEL_PROJECT)
12+
cmake_minimum_required(VERSION ${REQUIRED_CMAKE_VERSION})
1113
else()
12-
set(TIGHT_INCLUSION_TOPLEVEL_PROJECT OFF)
13-
message(STATUS "Tight-Inclusion CCD bottom-level project")
14-
# message(STATUS "${CMAKE_CURRENT_SOURCE_DIR}")
15-
# message(STATUS "${CMAKE_SOURCE_DIR}")
14+
# Don't use cmake_minimum_required here to avoid implicitly overriding parent policies
15+
if(${CMAKE_VERSION} VERSION_LESS ${REQUIRED_CMAKE_VERSION})
16+
message(FATAL_ERROR "CMake required version to build Tight Inclusion is ${REQUIRED_CMAKE_VERSION}")
17+
endif()
1618
endif()
1719

18-
### Configuration
19-
set(TIGHT_INCLUSION_EXTERNAL "${CMAKE_CURRENT_SOURCE_DIR}/external")
20-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
20+
# Include user-provided default options if available. We do that before the main
21+
# `project()` so that we can define the C/C++ compilers from the option file.
22+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/TightInclusionOptions.cmake)
23+
message(STATUS "Using local options file: ${CMAKE_CURRENT_SOURCE_DIR}/TightInclusionOptions.cmake")
24+
include(${CMAKE_CURRENT_SOURCE_DIR}/TightInclusionOptions.cmake)
25+
endif()
2126

22-
include(Warnings)
23-
include(UseColors)
24-
include(TI_CCDUtils)
27+
################################################################################
28+
29+
project(TightInclusion
30+
DESCRIPTION "Tight Inclusion CCD"
31+
LANGUAGES CXX)
2532

26-
OPTION(TIGHT_INCLUSION_WITH_GMP "Enable rational based predicates, for debug" OFF)
27-
OPTION(TIGHT_INCLUSION_WITH_TESTS "Enable test functions" OFF)
28-
OPTION(TIGHT_INCLUSION_WITH_TIMER "Enable profiling timers, for debug" OFF)
29-
OPTION(TIGHT_INCLUSION_WITH_NO_ZERO_TOI "Enable refinement if CCD produces a zero ToI" OFF)
33+
OPTION(TIGHT_INCLUSION_WITH_TESTS "Enable test functions" OFF)
34+
OPTION(TIGHT_INCLUSION_WITH_GMP "Enable rational based predicates, for debug" OFF)
35+
OPTION(TIGHT_INCLUSION_WITH_TIMER "Enable profiling timers, for debug" OFF)
3036
OPTION(TIGHT_INCLUSION_WITH_DOUBLE_PRECISION "Enable double precision floating point numbers as input" ON)
31-
OPTION(TIGHT_INCLUSION_LIMIT_QUEUE_SIZE "Enable limitation of maximal queue size" OFF)
37+
OPTION(TIGHT_INCLUSION_LIMIT_QUEUE_SIZE "Enable limitation of maximal queue size" OFF)
38+
39+
# Option to supress progress output when on GH actions.
40+
OPTION(TIGHT_INCLUSION_SUPPRESS_PROGRESS_OUTPUT "Enable limitation of maximal queue size" OFF)
41+
mark_as_advanced(TIGHT_INCLUSION_SUPPRESS_PROGRESS_OUTPUT)
42+
43+
include(CMakeDependentOption)
44+
cmake_dependent_option(TIGHT_INCLUSION_FLOAT_WITH_DOUBLE_INPUT "Enable converting double queries to float" OFF "TIGHT_INCLUSION_WITH_DOUBLE_PRECISION" OFF)
3245

33-
if(NOT TIGHT_INCLUSION_WITH_DOUBLE_PRECISION)
34-
OPTION(TIGHT_INCLUSION_FLOAT_WITH_DOUBLE_INPUT "Enable converting double queries to float" OFF)
46+
# Set default minimum C++ standard
47+
if(TIGHT_INCLUSION_TOPLEVEL_PROJECT)
48+
set(CMAKE_CXX_STANDARD 17)
49+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
50+
set(CMAKE_CXX_EXTENSIONS OFF)
3551
endif()
3652

37-
include(${PROJECT_NAME}Dependencies)
53+
### Configuration
54+
set(TIGHT_INCLUSION_SOURCE_DIR "${PROJECT_SOURCE_DIR}/src")
55+
56+
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/tight_inclusion/")
57+
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/recipes/")
58+
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/find/")
3859

60+
# Tight Inclusion utils
61+
include(tight_inclusion_utils)
62+
63+
################################################################################
64+
# Tight Inclusion Library
65+
################################################################################
66+
67+
# Add an empty library and fill in the list of sources in `src/CMakeLists.txt`.
68+
add_library(tight_inclusion)
69+
add_library(tight_inclusion::tight_inclusion ALIAS tight_inclusion)
3970

40-
# inclusion CCD
4171
add_subdirectory(tight_inclusion)
42-
prepend_current_path(INCLUSION_SOURCES)
43-
inclusionCCD_copy_headers(${INCLUSION_SOURCES})
44-
CCD_set_source_group(${INCLUSION_SOURCES})
45-
add_library(tight_inclusion ${INCLUSION_SOURCES})
72+
73+
# Public include directory for Tight Inclusion
4674
target_include_directories(tight_inclusion PUBLIC ${PROJECT_BINARY_DIR}/include)
75+
76+
################################################################################
77+
# Optional Definitions
78+
################################################################################
79+
80+
# For MSVC, do not use the min and max macros.
81+
target_compile_definitions(tight_inclusion PUBLIC NOMINMAX)
82+
83+
################################################################################
84+
# Dependencies
85+
################################################################################
86+
87+
# Extra warnings
88+
include(tight_inclusion_warnings)
89+
target_link_libraries(tight_inclusion PRIVATE tight_inclusion::warnings)
90+
91+
# libigl
92+
include(eigen)
4793
target_link_libraries(tight_inclusion PUBLIC Eigen3::Eigen)
48-
target_link_libraries(tight_inclusion PRIVATE warnings::all)
49-
50-
#Optional
51-
#GMP
52-
if(TIGHT_INCLUSION_WITH_GMP)
53-
message(STATUS "TIGHT_INCLUSION_WITH_GMP is defined, now using rational root finder")
54-
target_link_libraries(tight_inclusion PUBLIC gmp::gmp)
55-
target_compile_definitions(tight_inclusion PUBLIC TIGHT_INCLUSION_USE_GMP)
56-
endif()
5794

58-
if(TIGHT_INCLUSION_WITH_TIMER)
59-
target_compile_definitions(tight_inclusion PRIVATE TIGHT_INCLUSION_USE_TIMER)
95+
# GMP (optional)
96+
if(TIGHT_INCLUSION_WITH_GMP OR TIGHT_INCLUSION_WITH_TESTS)
97+
find_package(GMP REQUIRED)
98+
target_link_libraries(tight_inclusion PUBLIC gmp::gmp)
99+
target_compile_definitions(tight_inclusion PUBLIC TIGHT_INCLUSION_USE_GMP)
60100
endif()
61101

62-
# Figure out AVX level support
63-
message(STATUS "Searching for AVX...")
64-
find_package(AVX)
65-
# Add SSE, AVX, and FMA flags to compiler flags
66-
string(REPLACE " " ";" SIMD_FLAGS "${AVX_FLAGS}")
67-
target_compile_options(tight_inclusion PRIVATE ${SIMD_FLAGS})
68-
if (TIGHT_INCLUSION_WITH_NO_ZERO_TOI)
69-
target_compile_definitions(tight_inclusion PRIVATE TIGHT_INCLUSION_NO_ZERO_TOI)
102+
################################################################################
103+
# Definitions
104+
################################################################################
105+
106+
if(TIGHT_INCLUSION_WITH_TIMER)
107+
target_compile_definitions(tight_inclusion PRIVATE TIGHT_INCLUSION_USE_TIMER)
70108
endif()
71109

72110
if (TIGHT_INCLUSION_WITH_DOUBLE_PRECISION)
73-
target_compile_definitions(tight_inclusion PUBLIC TIGHT_INCLUSION_DOUBLE)
74-
message(STATUS "Using Double Precision Floating Points")
111+
message(STATUS "Tight Inclusion: Using Double Precision Floating Points")
112+
target_compile_definitions(tight_inclusion PUBLIC TIGHT_INCLUSION_DOUBLE)
75113
else()
76-
message(STATUS "Using Single Precision Floating Points")
114+
message(STATUS "Tight Inclusion: Using Single Precision Floating Points")
77115
endif()
116+
78117
if(TIGHT_INCLUSION_LIMIT_QUEUE_SIZE)
79-
target_compile_definitions(tight_inclusion PUBLIC TI_LIMIT_QUEUE_SIZE)
80-
message(STATUS "TICCD limiting maximal queue size")
118+
message(STATUS "Tight Inclusion: Limiting maximal queue size")
119+
target_compile_definitions(tight_inclusion PUBLIC TIGHT_INCLUSION_LIMIT_QUEUE_SIZE)
81120
endif()
82121

83122
if(TIGHT_INCLUSION_FLOAT_WITH_DOUBLE_INPUT)
84-
target_compile_definitions(tight_inclusion PUBLIC TIGHT_INCLUSION_FWDI)
85-
message(STATUS "Converting double inputs to float for tests")
123+
message(STATUS "Tight Inclusion: Converting double inputs to float for tests")
124+
target_compile_definitions(tight_inclusion PUBLIC TIGHT_INCLUSION_FWDI)
86125
endif()
87-
target_compile_definitions(tight_inclusion PUBLIC NOMINMAX)
88126

89-
if(TIGHT_INCLUSION_TOPLEVEL_PROJECT)
90-
#message(STATUS "Tight-Inclusion CCD top-level project")
91-
if (TIGHT_INCLUSION_WITH_TESTS)
92-
add_executable(Tight_Inclusion_bin
93-
app/main.cpp
94-
app/read_rational_csv.cpp
95-
)
96-
else()
97-
add_executable(Tight_Inclusion_bin app/main.cpp)
98-
endif()
127+
################################################################################
128+
# Compiler options
129+
################################################################################
130+
131+
# Figure out AVX level support
132+
message(STATUS "Searching for AVX...")
133+
find_package(AVX)
134+
string(REPLACE " " ";" SIMD_FLAGS "${AVX_FLAGS}")
135+
target_compile_options(tight_inclusion PRIVATE ${SIMD_FLAGS})
99136

100-
target_link_libraries(Tight_Inclusion_bin PUBLIC tight_inclusion)
137+
# Use C++17
138+
target_compile_features(tight_inclusion PUBLIC cxx_std_17)
101139

102-
ticcd_download_sample_queries()
140+
################################################################################
141+
# App
142+
################################################################################
103143

104-
if (NOT TIGHT_INCLUSION_WITH_GMP AND TIGHT_INCLUSION_WITH_TESTS)
105-
target_link_libraries(tight_inclusion PUBLIC gmp::gmp)
106-
target_compile_definitions(tight_inclusion PUBLIC TIGHT_INCLUSION_RUN_EXAMPLES)
107-
target_compile_definitions(Tight_Inclusion_bin PUBLIC
108-
TICCD_EXAMPLE_QUERIES_DIR="${CMAKE_CURRENT_SOURCE_DIR}/external/Sample-Queries/")
109-
endif()
144+
if(TIGHT_INCLUSION_TOPLEVEL_PROJECT)
145+
add_executable(Tight_Inclusion_bin "app/main.cpp")
146+
target_link_libraries(Tight_Inclusion_bin PUBLIC tight_inclusion)
147+
148+
set(TIGHT_INCLUSION_SAMPLE_QUERIES_DIR "${PROJECT_SOURCE_DIR}/sample-queries")
149+
include(sample_queries)
150+
151+
if(TIGHT_INCLUSION_SUPPRESS_PROGRESS_OUTPUT)
152+
target_compile_definitions(Tight_Inclusion_bin PUBLIC TIGHT_INCLUSION_SUPPRESS_PROGRESS_OUTPUT)
153+
endif()
154+
155+
if (TIGHT_INCLUSION_WITH_TESTS)
156+
target_sources(Tight_Inclusion_bin PUBLIC "app/read_rational_csv.cpp")
157+
target_compile_definitions(Tight_Inclusion_bin PUBLIC TIGHT_INCLUSION_RUN_EXAMPLES)
158+
target_compile_definitions(Tight_Inclusion_bin PUBLIC
159+
TIGHT_INCLUSION_SAMPLE_QUERIES_DIR="${TIGHT_INCLUSION_SAMPLE_QUERIES_DIR}/")
160+
endif()
110161
endif()

0 commit comments

Comments
 (0)