diff --git a/.clang-tidy.yml b/.clang-tidy.yml new file mode 100644 index 0000000..8bad240 --- /dev/null +++ b/.clang-tidy.yml @@ -0,0 +1,46 @@ +--- +Checks: 'clang-diagnostic-*,clang-analyzer-*' +WarningsAsErrors: '' +HeaderFilterRegex: '' +AnalyzeTemporaryDtors: false +FormatStyle: none +User: crvs +CheckOptions: + - key: llvm-else-after-return.WarnOnConditionVariables + value: 'false' + - key: modernize-loop-convert.MinConfidence + value: reasonable + - key: modernize-replace-auto-ptr.IncludeStyle + value: llvm + - key: cert-str34-c.DiagnoseSignedUnsignedCharComparisons + value: 'false' + - key: google-readability-namespace-comments.ShortNamespaceLines + value: '10' + - key: cert-err33-c.CheckedFunctions + value: '::aligned_alloc;::asctime_s;::at_quick_exit;::atexit;::bsearch;::bsearch_s;::btowc;::c16rtomb;::c32rtomb;::calloc;::clock;::cnd_broadcast;::cnd_init;::cnd_signal;::cnd_timedwait;::cnd_wait;::ctime_s;::fclose;::fflush;::fgetc;::fgetpos;::fgets;::fgetwc;::fopen;::fopen_s;::fprintf;::fprintf_s;::fputc;::fputs;::fputwc;::fputws;::fread;::freopen;::freopen_s;::fscanf;::fscanf_s;::fseek;::fsetpos;::ftell;::fwprintf;::fwprintf_s;::fwrite;::fwscanf;::fwscanf_s;::getc;::getchar;::getenv;::getenv_s;::gets_s;::getwc;::getwchar;::gmtime;::gmtime_s;::localtime;::localtime_s;::malloc;::mbrtoc16;::mbrtoc32;::mbsrtowcs;::mbsrtowcs_s;::mbstowcs;::mbstowcs_s;::memchr;::mktime;::mtx_init;::mtx_lock;::mtx_timedlock;::mtx_trylock;::mtx_unlock;::printf_s;::putc;::putwc;::raise;::realloc;::remove;::rename;::scanf;::scanf_s;::setlocale;::setvbuf;::signal;::snprintf;::snprintf_s;::sprintf;::sprintf_s;::sscanf;::sscanf_s;::strchr;::strerror_s;::strftime;::strpbrk;::strrchr;::strstr;::strtod;::strtof;::strtoimax;::strtok;::strtok_s;::strtol;::strtold;::strtoll;::strtoul;::strtoull;::strtoumax;::strxfrm;::swprintf;::swprintf_s;::swscanf;::swscanf_s;::thrd_create;::thrd_detach;::thrd_join;::thrd_sleep;::time;::timespec_get;::tmpfile;::tmpfile_s;::tmpnam;::tmpnam_s;::tss_create;::tss_get;::tss_set;::ungetc;::ungetwc;::vfprintf;::vfprintf_s;::vfscanf;::vfscanf_s;::vfwprintf;::vfwprintf_s;::vfwscanf;::vfwscanf_s;::vprintf_s;::vscanf;::vscanf_s;::vsnprintf;::vsnprintf_s;::vsprintf;::vsprintf_s;::vsscanf;::vsscanf_s;::vswprintf;::vswprintf_s;::vswscanf;::vswscanf_s;::vwprintf_s;::vwscanf;::vwscanf_s;::wcrtomb;::wcschr;::wcsftime;::wcspbrk;::wcsrchr;::wcsrtombs;::wcsrtombs_s;::wcsstr;::wcstod;::wcstof;::wcstoimax;::wcstok;::wcstok_s;::wcstol;::wcstold;::wcstoll;::wcstombs;::wcstombs_s;::wcstoul;::wcstoull;::wcstoumax;::wcsxfrm;::wctob;::wctrans;::wctype;::wmemchr;::wprintf_s;::wscanf;::wscanf_s;' + - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField + value: 'false' + - key: cert-dcl16-c.NewSuffixes + value: 'L;LL;LU;LLU' + - key: google-readability-braces-around-statements.ShortStatementLines + value: '1' + - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic + value: 'true' + - key: google-readability-namespace-comments.SpacesBeforeComments + value: '2' + - key: modernize-loop-convert.MaxCopySize + value: '16' + - key: modernize-pass-by-value.IncludeStyle + value: llvm + - key: modernize-use-nullptr.NullMacros + value: 'NULL' + - key: llvm-qualified-auto.AddConstToQualified + value: 'false' + - key: modernize-loop-convert.NamingStyle + value: CamelCase + - key: llvm-else-after-return.WarnOnUnfixable + value: 'false' + - key: google-readability-function-size.StatementThreshold + value: '800' +... + diff --git a/CMakeLists.txt b/CMakeLists.txt index bede954..90b966a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.9) +cmake_minimum_required(VERSION 3.6) project(KDTree CXX) #set(CMAKE_CXX_COMPILER "/usr/bin/g++") @@ -23,6 +23,7 @@ set(CMAKE_RANLIB "/usr/bin/gcc-ranlib") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_EXPORT_COMPILE_COMMANDS 1) include_directories(.) add_library(KDTree SHARED KDTree.cpp) @@ -31,3 +32,8 @@ target_include_directories(KDTree PUBLIC .) include(CTest) enable_testing() add_subdirectory(tests) + +file(GLOB ALL_SOURCE_FILES *.cpp *.hpp **/*.cpp **/*.hpp) +add_custom_target(check_clang_tidy clang-tidy-14 -p ${CMAKE_CURRENT_BINARY_DIR} --config-file=${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy.yml ${ALL_SOURCE_FILES}) +add_custom_target(check_clang_format clang-format-14 --style=file:${CMAKE_CURRENT_SOURCE_DIR}/.clang-format.yml --dry-run -Werror ${ALL_SOURCE_FILES}) +add_custom_target(run_clang_format clang-format-14 --style=file:${CMAKE_CURRENT_SOURCE_DIR}/.clang-format.yml -i ${ALL_SOURCE_FILES}) diff --git a/KDTree.cpp b/KDTree.cpp index d683dea..36dc254 100644 --- a/KDTree.cpp +++ b/KDTree.cpp @@ -167,7 +167,8 @@ void KDTree::knearest_( node_query_(close_branch, pt, next_level, num_nearest, k_nearest_buffer); // only check the other branch if it makes sense to do so - if (dx2 < k_nearest_buffer.back().second || k_nearest_buffer.size() < num_nearest) { + if (dx2 < k_nearest_buffer.back().second || + k_nearest_buffer.size() < num_nearest) { node_query_(far_branch, pt, next_level, num_nearest, k_nearest_buffer); } }; diff --git a/README.md b/README.md index 1543aa3..650c7ca 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,9 @@ Simple C++ static KD-Tree implementation with minimal functionality. - builds the tree in one go (does not support adding nodes, the tree is built from a list of points and cannot be altered afterwards) - points are assumed to be STL vectors - it provides the following queries: - - nearest neighbor - - neighbors within a given distance + - nearest neighbor + - neighbors within a given distance + - k nearest neighbours ## License and copyright