Skip to content

Commit

Permalink
2 -> default
Browse files Browse the repository at this point in the history
  • Loading branch information
scpeters committed Feb 10, 2016
2 parents d75d997 + 5f5a531 commit 1a0288f
Show file tree
Hide file tree
Showing 12 changed files with 282 additions and 44 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ filter_valid_compiler_warnings(${WARN_LEVEL} -Wextra -Wno-long-long
-Wfloat-equal -Wshadow -Winit-self -Wswitch-default
-Wmissing-include-dirs -pedantic)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}${WARNING_CXX_FLAGS}")
if (DEFINED EXTRA_CMAKE_CXX_FLAGS)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CMAKE_CXX_FLAGS}")
endif()

#################################################
# OS Specific initialization
Expand Down
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ configuration:
build_script:
- md build
- cd build
- cmake ..
- cmake .. -DEXTRA_CMAKE_CXX_FLAGS="-WX"
- cmake --build . --config %CONFIGURATION%

test_script:
- cmake --build . --config %CONFIGURATION% --target RUN_TESTS

after_build:
- cmake --build . --config %CONFIGURATION% --target INSTALL
- cmake --build . --config %CONFIGURATION% --target INSTALL
144 changes: 111 additions & 33 deletions include/ignition/math/Helpers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <string>
#include <iostream>
#include <vector>
#include <tuple>
#include <cstdint>

/// \brief Double maximum value. This value will be similar to 1.79769e+308
#define IGN_DBL_MAX std::numeric_limits<double>::max()
Expand All @@ -49,6 +51,26 @@
/// \brief Float lowest value, equivalent to -IGN_FLT_MAX
#define IGN_FLT_LOW std::numeric_limits<float>::lowest()

/// \brief 16bit unsigned integer maximum value
#define IGN_UINT16_MAX std::numeric_limits<uint16_t>::max()

/// \brief 16bit unsigned integer minimum value
#define IGN_UINT16_MIN std::numeric_limits<uint16_t>::min()

/// \brief 16bit unsigned integer lowest value. This is equivalent to
/// IGN_UINT16_MIN, and is defined here for completeness.
#define IGN_UINT16_LOW std::numeric_limits<uint16_t>::lowest()

/// \brief 16bit integer maximum value
#define IGN_INT16_MAX std::numeric_limits<int16_t>::max()

/// \brief 16bit integer minimum value
#define IGN_INT16_MIN std::numeric_limits<int16_t>::min()

/// \brief 16bit integer lowest value. This is equivalent to IGN_INT16_MIN,
/// and is defined here for completeness.
#define IGN_INT16_LOW std::numeric_limits<int16_t>::lowest()

/// \brief 32bit unsigned integer maximum value
#define IGN_UINT32_MAX std::numeric_limits<uint32_t>::max()

Expand All @@ -69,6 +91,26 @@
/// and is defined here for completeness.
#define IGN_INT32_LOW std::numeric_limits<int32_t>::lowest()

/// \brief 64bit unsigned integer maximum value
#define IGN_UINT64_MAX std::numeric_limits<uint64_t>::max()

/// \brief 64bit unsigned integer minimum value
#define IGN_UINT64_MIN std::numeric_limits<uint64_t>::min()

/// \brief 64bit unsigned integer lowest value. This is equivalent to
/// IGN_UINT64_MIN, and is defined here for completeness.
#define IGN_UINT64_LOW std::numeric_limits<uint64_t>::lowest()

/// \brief 64bit integer maximum value
#define IGN_INT64_MAX std::numeric_limits<int64_t>::max()

/// \brief 64bit integer minimum value
#define IGN_INT64_MIN std::numeric_limits<int64_t>::min()

/// \brief 64bit integer lowest value. This is equivalent to IGN_INT64_MIN,
/// and is defined here for completeness.
#define IGN_INT64_LOW std::numeric_limits<int64_t>::lowest()

/// \brief Define IGN_PI, IGN_PI_2, and IGN_PI_4.
/// This was put here for Windows support.
#ifdef M_PI
Expand Down Expand Up @@ -109,6 +151,39 @@
/// \param[in] _v Vector3d that contains the box's dimensions.
#define IGN_BOX_VOLUME_V(_v) (_v.X() *_v.Y() * _v.Z())

/** \def IGNITION_VISIBLE
* Use to represent "symbol visible" if supported
*/

/** \def IGNITION_HIDDEN
* Use to represent "symbol hidden" if supported
*/

#if defined _WIN32 || defined __CYGWIN__
#ifdef BUILDING_DLL
#ifdef __GNUC__
#define IGNITION_VISIBLE __attribute__ ((dllexport))
#else
#define IGNITION_VISIBLE __declspec(dllexport)
#endif
#else
#ifdef __GNUC__
#define IGNITION_VISIBLE __attribute__ ((dllimport))
#else
#define IGNITION_VISIBLE __declspec(dllimport)
#endif
#endif
#define IGNITION_HIDDEN
#else
#if __GNUC__ >= 4
#define IGNITION_VISIBLE __attribute__ ((visibility ("default")))
#define IGNITION_HIDDEN __attribute__ ((visibility ("hidden")))
#else
#define IGNITION_VISIBLE
#define IGNITION_HIDDEN
#endif
#endif

namespace ignition
{
/// \brief Math classes and function useful in robot applications.
Expand Down Expand Up @@ -268,8 +343,8 @@ namespace ignition
template<typename T>
inline T precision(const T &_a, const unsigned int &_precision)
{
return std::round(_a * std::pow(10, _precision))
/ std::pow(10, _precision);
auto p = std::pow(10, _precision);
return static_cast<T>(std::round(_a * p) / p);
}

/// \brief Sort two numbers, such that _a <= _b
Expand Down Expand Up @@ -420,40 +495,43 @@ namespace ignition
}
return s * acc;
}
}
}

/** \def IGNITION_VISIBLE
* Use to represent "symbol visible" if supported
*/

/** \def IGNITION_HIDDEN
* Use to represent "symbol hidden" if supported
*/

#if defined _WIN32 || defined __CYGWIN__
#ifdef BUILDING_DLL
#ifdef __GNUC__
#define IGNITION_VISIBLE __attribute__ ((dllexport))
#else
#define IGNITION_VISIBLE __declspec(dllexport)
#endif
#else
#ifdef __GNUC__
#define IGNITION_VISIBLE __attribute__ ((dllimport))
#else
#define IGNITION_VISIBLE __declspec(dllimport)
#endif
#endif
#define IGNITION_HIDDEN
// Degrade precision on Windows, which cannot handle 'long double'
// values properly. See the implementation of Unpair.
#ifdef _MSC_VER
using PairInput = uint16_t;
using PairOutput = uint32_t;
#else
#if __GNUC__ >= 4
#define IGNITION_VISIBLE __attribute__ ((visibility ("default")))
#define IGNITION_HIDDEN __attribute__ ((visibility ("hidden")))
#else
#define IGNITION_VISIBLE
#define IGNITION_HIDDEN
#endif
using PairInput = uint32_t;
using PairOutput = uint64_t;
#endif

/// \brief A pairing function that maps two values to a unique third
/// value. This is an implement of Szudzik's function.
/// \param[in] _a First value, must be a non-negative integer. On
/// Windows this value is uint16_t. On Linux/OSX this value is uint32_t.
/// \param[in] _b Second value, must be a non-negative integer. On
/// Windows this value is uint16_t. On Linux/OSX this value is uint32_t.
/// \return A unique non-negative integer value. On Windows the return
/// value is uint32_t. On Linux/OSX the return value is uint64_t
/// \sa Unpair
PairOutput IGNITION_VISIBLE Pair(const PairInput _a, const PairInput _b);

/// \brief The reverse of the Pair function. Accepts a key, produced
/// from the Pair function, and returns a tuple consisting of the two
/// non-negative integer values used to create the _key.
/// \param[in] _key A non-negative integer generated from the Pair
/// function. On Windows this value is uint32_t. On Linux/OSX, this
/// value is uint64_t.
/// \return A tuple that consists of the two non-negative integers that
/// will generate _key when used with the Pair function. On Windows the
/// tuple contains two uint16_t values. On Linux/OSX the tuple contains
/// two uint32_t values.
/// \sa Pair
std::tuple<PairInput, PairInput> IGNITION_VISIBLE Unpair(
const PairOutput _key);
}
}

#endif
9 changes: 9 additions & 0 deletions include/ignition/math/Vector3.hh
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ namespace ignition
return *this;
}

/// \brief Return a normalized vector
/// \return unit length vector
public: Vector3 Normalized() const
{
Vector3<T> result = *this;
result.Normalize();
return result;
}

/// \brief Round to near whole number, return the result.
/// \return the result
public: Vector3 Round()
Expand Down
9 changes: 9 additions & 0 deletions src/Angle_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,12 @@ TEST(AngleTest, StreamExtraction)
stream >> angle;
EXPECT_NEAR(*angle, 1.25, 1e-2);
}

/////////////////////////////////////////////////
TEST(AngleTest, OperatorStreamOut)
{
math::Angle a(0.1);
std::ostringstream stream;
stream << a;
EXPECT_EQ(stream.str(), "0.1");
}
1 change: 0 additions & 1 deletion src/Box_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*
*/

#include <gtest/gtest.h>

#include "ignition/math/Box.hh"
Expand Down
31 changes: 27 additions & 4 deletions src/Helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,32 @@
*/
#include "ignition/math/Helpers.hh"

namespace ignition
/////////////////////////////////////////////
ignition::math::PairOutput ignition::math::Pair(
const ignition::math::PairInput _a, const ignition::math::PairInput _b)
{
namespace math
{
}
// Store in 64bit local variable so that we don't overflow.
uint64_t a = _a;
uint64_t b = _b;

// Szudzik's function
return _a >= _b ?
static_cast<PairOutput>(a * a + a + b) :
static_cast<PairOutput>(a + b * b);
}

/////////////////////////////////////////////
std::tuple<ignition::math::PairInput, ignition::math::PairInput>
ignition::math::Unpair(const ignition::math::PairOutput _key)
{
// Must explicitly cast so that the _key is not auto cast to a double
uint64_t sqrt = static_cast<uint64_t>(
std::floor(std::sqrt(static_cast<long double>(_key))));
uint64_t sq = sqrt * sqrt;

return ((_key - sq) >= sqrt) ?
std::make_tuple(static_cast<PairInput>(sqrt),
static_cast<PairInput>(_key - sq - sqrt)) :
std::make_tuple(static_cast<PairInput>(_key - sq),
static_cast<PairInput>(sqrt));
}
Loading

0 comments on commit 1a0288f

Please sign in to comment.