From 0f086be8b98dcf1a86e003a0f2177a177ce814db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Br=C3=A9mond?= Date: Thu, 20 Sep 2018 13:27:20 -0700 Subject: [PATCH 1/4] [misc] Set default to build script --- tools/development/helpers/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/development/helpers/build.sh b/tools/development/helpers/build.sh index 7115fe0f..3dae1db2 100755 --- a/tools/development/helpers/build.sh +++ b/tools/development/helpers/build.sh @@ -11,6 +11,6 @@ cmake .. -make -j ${cpu_count} +make -j ${cpu_count:-1} ################################################################################################################################################################ \ No newline at end of file From 77f4d0bb11747263a8d70020909be335bc776e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Br=C3=A9mond?= Date: Thu, 20 Sep 2018 13:28:26 -0700 Subject: [PATCH 2/4] [misc] Improve build script --- tools/development/helpers/build.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/development/helpers/build.sh b/tools/development/helpers/build.sh index 3dae1db2..08d559f5 100755 --- a/tools/development/helpers/build.sh +++ b/tools/development/helpers/build.sh @@ -9,7 +9,15 @@ ################################################################################################################################################################ -cmake .. +if [[ ! -z $1 ]] && [[ $1 == "--debug" ]]; then + + cmake -DCMAKE_BUILD_TYPE=Debug .. + +else + + cmake .. + +fi make -j ${cpu_count:-1} From 86c37aa9249d3735aecaccc1c5d5fbfa5c72a147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Br=C3=A9mond?= Date: Sun, 23 Sep 2018 22:40:58 -0700 Subject: [PATCH 3/4] [feature] Add Array::isNear --- include/Library/Core/Containers/Array.hpp | 15 +++++++ src/Library/Core/Containers/Array.tpp | 24 +++++++++++ test/Library/Core/Containers/Array.test.cpp | 44 +++++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/include/Library/Core/Containers/Array.hpp b/include/Library/Core/Containers/Array.hpp index 0303e67b..4e93be37 100755 --- a/include/Library/Core/Containers/Array.hpp +++ b/include/Library/Core/Containers/Array.hpp @@ -176,6 +176,21 @@ class Array : public std::vector bool contains ( const T& anElement ) const ; + /// @brief Check if array is near another array + /// + /// @code + /// Array firstArray = {1, 2, 3} ; + /// Array secondArray = {1, 2, 3 + 1e-15} ; + /// firstArray.isNear(secondArray, 1e-15) ; // True + /// @endcode + /// + /// @param [in] anArray An array + /// @param [in] aTolerance A tolerance + /// @return True if array is near another array + + bool isNear ( const Array& anArray, + const T& aTolerance ) const ; + /// @brief Access first element /// /// @code diff --git a/src/Library/Core/Containers/Array.tpp b/src/Library/Core/Containers/Array.tpp index 002d5257..3aab4515 100644 --- a/src/Library/Core/Containers/Array.tpp +++ b/src/Library/Core/Containers/Array.tpp @@ -128,6 +128,30 @@ bool Array::isEmpty ( ) bool Array::contains ( const T& anElement ) const { return std::find(this->begin(), this->end(), anElement) != this->end() ; +} + + template +bool Array::isNear ( const Array& anArray, + const T& aTolerance ) const +{ + + if (this->getSize() != anArray.getSize()) + { + return false ; + } + + for (const auto elementTuple : library::core::ctnr::iterators::Zip(*this, anArray)) + { + + if (!std::get<0>(elementTuple).isNear(std::get<1>(elementTuple), aTolerance)) + { + return false ; + } + + } + + return true ; + } template diff --git a/test/Library/Core/Containers/Array.test.cpp b/test/Library/Core/Containers/Array.test.cpp index 25f86515..8190735c 100755 --- a/test/Library/Core/Containers/Array.test.cpp +++ b/test/Library/Core/Containers/Array.test.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -216,6 +217,49 @@ TEST (Library_Core_Containers_Array, Contains) } +TEST (Library_Core_Containers_Array, IsNear) +{ + + using library::core::types::Real ; + using library::core::ctnr::Array ; + + { + + const Array array = { 1.0, 2.0, 3.0 } ; + + EXPECT_TRUE(array.isNear(array, 0.0)) ; + + } + + { + + const Array firstArray = { 1.0, 2.0, 3.0 } ; + const Array secondArray = { 1.0, 2.0, 3.0 } ; + + EXPECT_TRUE(firstArray.isNear(secondArray, 0.0)) ; + + } + + { + + const Array firstArray = { 1.0, 2.0, 3.0 } ; + const Array secondArray = { 1.0, 2.0, 4.0 } ; + + EXPECT_TRUE(firstArray.isNear(secondArray, 1.0)) ; + + } + + { + + const Array firstArray = { 1.0, 2.0, 3.0 } ; + const Array secondArray = { 1.0, 2.0, 3.0, 4.0 } ; + + EXPECT_FALSE(firstArray.isNear(secondArray, 1.0)) ; + + } + +} + TEST (Library_Core_Containers_Array, AccessFirst) { From adc4d0a606d2c35bb58c6b5e2389350607cac507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Br=C3=A9mond?= Date: Sun, 23 Sep 2018 23:06:53 -0700 Subject: [PATCH 4/4] [feature] Improve Array::isNear --- include/Library/Core/Containers/Array.hpp | 21 ++++++++++++++++-- src/Library/Core/Containers/Array.tpp | 24 +++++++++++++++++++++ test/Library/Core/Containers/Array.test.cpp | 19 ++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/include/Library/Core/Containers/Array.hpp b/include/Library/Core/Containers/Array.hpp index 4e93be37..b1dffe94 100755 --- a/include/Library/Core/Containers/Array.hpp +++ b/include/Library/Core/Containers/Array.hpp @@ -179,8 +179,8 @@ class Array : public std::vector /// @brief Check if array is near another array /// /// @code - /// Array firstArray = {1, 2, 3} ; - /// Array secondArray = {1, 2, 3 + 1e-15} ; + /// Array firstArray = {1.0, 2.0, 3.0} ; + /// Array secondArray = {1.0, 2.0, 3.0 + 1e-15} ; /// firstArray.isNear(secondArray, 1e-15) ; // True /// @endcode /// @@ -191,6 +191,23 @@ class Array : public std::vector bool isNear ( const Array& anArray, const T& aTolerance ) const ; + /// @brief Check if array is near another array + /// + /// @code + /// Array firstArray = {1.0, 2.0, 3.0} ; + /// Array secondArray = {1.0, 2.0, 3.0 + 1e-15} ; + /// firstArray.isNear(secondArray, + /// [] (const Real& aFirstValue, const Real& aSecondValue) -> bool + /// { return aFirstValue.isNear(aSecondValue, 1e-15) ; }) ; // True + /// @endcode + /// + /// @param [in] anArray An array + /// @param [in] aComparator A comparator + /// @return True if array is near another array + + bool isNear ( const Array& anArray, + const std::function& aComparator ) const ; + /// @brief Access first element /// /// @code diff --git a/src/Library/Core/Containers/Array.tpp b/src/Library/Core/Containers/Array.tpp index 3aab4515..4389df18 100644 --- a/src/Library/Core/Containers/Array.tpp +++ b/src/Library/Core/Containers/Array.tpp @@ -152,6 +152,30 @@ bool Array::isNear ( return true ; +} + + template +bool Array::isNear ( const Array& anArray, + const std::function& aComparator ) const +{ + + if (this->getSize() != anArray.getSize()) + { + return false ; + } + + for (const auto elementTuple : library::core::ctnr::iterators::Zip(*this, anArray)) + { + + if (!aComparator(std::get<0>(elementTuple), std::get<1>(elementTuple))) + { + return false ; + } + + } + + return true ; + } template diff --git a/test/Library/Core/Containers/Array.test.cpp b/test/Library/Core/Containers/Array.test.cpp index 8190735c..962997c5 100755 --- a/test/Library/Core/Containers/Array.test.cpp +++ b/test/Library/Core/Containers/Array.test.cpp @@ -223,6 +223,8 @@ TEST (Library_Core_Containers_Array, IsNear) using library::core::types::Real ; using library::core::ctnr::Array ; + // Tolerance + { const Array array = { 1.0, 2.0, 3.0 } ; @@ -258,6 +260,23 @@ TEST (Library_Core_Containers_Array, IsNear) } + // Comparator + + { + + const Array firstArray = { 1.0, 2.0, 3.0 } ; + const Array secondArray = { 1.0, 2.0, 4.0 } ; + + EXPECT_TRUE + ( + firstArray.isNear(secondArray, + [] (const Real& aFirstValue, const Real& aSecondValue) -> bool + { return aFirstValue.isNear(aSecondValue, 1.0) ; } + ) + ) ; + + } + } TEST (Library_Core_Containers_Array, AccessFirst)