Reorg util/math -> math.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
//
|
||||
// Created by kyle on 8/3/19.
|
||||
//
|
||||
/**
|
||||
* orientation.h concerns itself with computing the orientation of some
|
||||
* vector with respect to a reference plane that is assumed to be the
|
||||
* of the Earth.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __WRMATH_GEOM_ORIENTATION_H
|
||||
#define __WRMATH_GEOM_ORIENTATION_H
|
||||
@@ -13,12 +16,6 @@ namespace wr {
|
||||
namespace geom {
|
||||
|
||||
|
||||
float RadiansToDegreesF(float rads);
|
||||
double RadiansToDegreesD(double rads);
|
||||
float DegreesToRadiansF(float degrees);
|
||||
double DegreesToRadiansD(double degrees);
|
||||
|
||||
|
||||
constexpr uint8_t Basis_i = 0;
|
||||
constexpr uint8_t Basis_j = 1;
|
||||
constexpr uint8_t Basis_k = 2;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <ostream>
|
||||
#include <iostream>
|
||||
|
||||
#include <wrmath/util/math.h>
|
||||
#include <wrmath/math.h>
|
||||
|
||||
|
||||
namespace wr {
|
||||
@@ -29,18 +29,18 @@ public:
|
||||
* The default constructor creates a zero vector for a given
|
||||
* type and size.
|
||||
*/
|
||||
Vector() { wr::util::DefaultEpsilon(this->epsilon); }
|
||||
Vector() { wr::math::DefaultEpsilon(this->epsilon); }
|
||||
|
||||
/**
|
||||
* If given an initializer_list, the vector is created with
|
||||
* those values. There must be exactly N elements in the list.
|
||||
* @param ilst
|
||||
* @param ilstutil
|
||||
*/
|
||||
Vector(std::initializer_list<T> ilst)
|
||||
{
|
||||
assert(ilst.size() == N);
|
||||
|
||||
wr::util::DefaultEpsilon(this->epsilon);
|
||||
wr::math::DefaultEpsilon(this->epsilon);
|
||||
std::copy(ilst.begin(), ilst.end(), this->arr.begin());
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
isZero() const
|
||||
{
|
||||
for (size_t i = 0; i < N; i++) {
|
||||
if (!wr::util::WithinTolerance(this->arr[i], (T)0.0, this->epsilon)) {
|
||||
if (!wr::math::WithinTolerance(this->arr[i], (T)0.0, this->epsilon)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public:
|
||||
bool
|
||||
isUnitVector() const
|
||||
{
|
||||
return wr::util::WithinTolerance(this->magnitude(), (T)1.0, this->epsilon);
|
||||
return wr::math::WithinTolerance(this->magnitude(), (T)1.0, this->epsilon);
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ public:
|
||||
}
|
||||
|
||||
T angle = this->angle(other);
|
||||
if (wr::util::WithinTolerance(angle, (T)0.0, this->epsilon)) {
|
||||
if (wr::math::WithinTolerance(angle, (T)0.0, this->epsilon)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
return wr::util::WithinTolerance(*this * other, (T)0.0, this->epsilon);
|
||||
return wr::math::WithinTolerance(*this * other, (T)0.0, this->epsilon);
|
||||
}
|
||||
|
||||
|
||||
@@ -287,7 +287,7 @@ public:
|
||||
*/
|
||||
bool operator==(const Vector<T, N> &other) const {
|
||||
for (size_t i = 0; i<N; i++) {
|
||||
if (!wr::util::WithinTolerance(this->arr[i], other.arr[i], this->epsilon)) {
|
||||
if (!wr::math::WithinTolerance(this->arr[i], other.arr[i], this->epsilon)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
43
include/wrmath/math.h
Normal file
43
include/wrmath/math.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef __WRMATH_UTIL_MATH_H
|
||||
#define __WRMATH_UTIL_MATH_H
|
||||
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
||||
namespace wr {
|
||||
namespace math {
|
||||
|
||||
|
||||
/**
|
||||
* Convert radians to degrees.
|
||||
* @param rads the angle in radians
|
||||
* @return the angle in degrees,
|
||||
*/
|
||||
float RadiansToDegreesF(float rads);
|
||||
double RadiansToDegreesD(double rads);
|
||||
float DegreesToRadiansF(float degrees);
|
||||
double DegreesToRadiansD(double degrees);
|
||||
|
||||
|
||||
|
||||
const double Epsilon_double = 0.0001;
|
||||
const float Epsilon_float = 0.0001;
|
||||
|
||||
|
||||
void DefaultEpsilon(double &epsilon);
|
||||
void DefaultEpsilon(float &epsilon);
|
||||
|
||||
template <typename T>
|
||||
static T
|
||||
WithinTolerance(T a, T b, T epsilon)
|
||||
{
|
||||
return std::abs(a - b) < epsilon;
|
||||
}
|
||||
|
||||
|
||||
} // namespace math
|
||||
} // namespace wr
|
||||
|
||||
|
||||
#endif // __WRMATH_UTIL_MATH_H
|
||||
@@ -1,39 +0,0 @@
|
||||
#ifndef __WRMATH_UTIL_MATH_H
|
||||
#define __WRMATH_UTIL_MATH_H
|
||||
|
||||
|
||||
namespace wr {
|
||||
namespace util {
|
||||
|
||||
|
||||
const double Epsilon_double = 0.0001;
|
||||
const float Epsilon_float = 0.0001;
|
||||
|
||||
|
||||
static void
|
||||
DefaultEpsilon(double &epsilon)
|
||||
{
|
||||
epsilon = Epsilon_double;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
DefaultEpsilon(float &epsilon)
|
||||
{
|
||||
epsilon = Epsilon_float;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
static T
|
||||
WithinTolerance(T a, T b, T epsilon)
|
||||
{
|
||||
return std::abs(a - b) < epsilon;
|
||||
}
|
||||
|
||||
|
||||
} // namespace util
|
||||
} // namespace wr
|
||||
|
||||
|
||||
#endif // __WRMATH_UTIL_MATH_H
|
||||
Reference in New Issue
Block a user