diff --git a/CMakeLists.txt b/CMakeLists.txt index f7345c74c3..ac98f760b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,9 +142,6 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) add_dependencies(prebuild_targets matrix) include_directories(${CMAKE_BINARY_DIR}/matrix-prefix/src/matrix) - # mathlib only needed in standalone build - add_subdirectory(mathlib) - endif() # santiziers (ASAN) diff --git a/EKF/CMakeLists.txt b/EKF/CMakeLists.txt index b5548bc8ec..7a2f2b7f32 100644 --- a/EKF/CMakeLists.txt +++ b/EKF/CMakeLists.txt @@ -55,7 +55,7 @@ add_library(ecl_EKF add_dependencies(ecl_EKF prebuild_targets) target_compile_definitions(ecl_EKF PRIVATE -DMODULE_NAME="ecl/EKF") target_include_directories(ecl_EKF PUBLIC ${ECL_SOURCE_DIR}) -target_link_libraries(ecl_EKF PRIVATE ecl_geo ecl_geo_lookup mathlib) +target_link_libraries(ecl_EKF PRIVATE ecl_geo ecl_geo_lookup) set_target_properties(ecl_EKF PROPERTIES PUBLIC_HEADER "ekf.h") diff --git a/mathlib/CMakeLists.txt b/mathlib/CMakeLists.txt deleted file mode 100644 index 5fbb4846b8..0000000000 --- a/mathlib/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -############################################################################ -# -# Copyright (c) 2018 ECL Development Team. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name ECL nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -add_library(mathlib - mathlib.cpp - ) -add_dependencies(mathlib prebuild_targets) - -target_include_directories(mathlib INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/mathlib/mathlib.cpp b/mathlib/mathlib.cpp deleted file mode 100644 index 1281af0ad7..0000000000 --- a/mathlib/mathlib.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2012, 2014 PX4 Development Team. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/** - * @file mathlib.cpp - * - * Definition of math namespace function for POSIX SHARED - * - * @author Siddharth Bharat Purohit - */ -#include "mathlib.h" - -#ifdef ECL_STANDALONE - -namespace math { - -float min(float val1, float val2) { return (val1 < val2) ? val1 : val2; } - -float max(float val1, float val2) { return (val1 > val2) ? val1 : val2; } - -float constrain(float val, float min, float max) { return (val < min) ? min : ((val > max) ? max : val); } - -float radians(float degrees) { return (degrees / 180.0f) * M_PI_F; } - -float degrees(float radians) { return (radians * 180.0f) / M_PI_F; } - -} // namespace math - -#endif /* ECL_STANDALONE */ diff --git a/mathlib/mathlib.h b/mathlib/mathlib.h index 42de1c6b4a..0bcbf7f44c 100644 --- a/mathlib/mathlib.h +++ b/mathlib/mathlib.h @@ -51,14 +51,25 @@ #define M_PI_2_F (M_PI / 2.0f) #endif -namespace math { -// using namespace Eigen; +#ifndef M_PI +#define M_PI 3.141592653589793238462643383280 +#endif -float min(float val1, float val2); -float max(float val1, float val2); -float constrain(float val, float min, float max); -float radians(float degrees); -float degrees(float radians); +namespace math { +template +Type min(Type val1, Type val2) { return (val1 < val2) ? val1 : val2; } + +template +Type max(Type val1, Type val2) { return (val1 > val2) ? val1 : val2; } + +template +Type constrain(Type val, Type min, Type max) { return (val < min) ? min : ((val > max) ? max : val); } + +template +Type radians(Type degrees) { return (degrees / Type(180)) * Type(M_PI); } + +template +Type degrees(Type radians) { return (radians * Type(180)) / Type(M_PI); } } // namespace math #else