refactor namespaces

This commit is contained in:
Kyle Isom 2023-10-18 23:57:50 -07:00
parent 5f3dc6e9f6
commit 8d02d078e7
14 changed files with 84 additions and 52 deletions

View File

@ -44,6 +44,13 @@ set(HEADER_FILES
include/scsl/StringUtil.h include/scsl/StringUtil.h
include/scsl/TLV.h include/scsl/TLV.h
include/scmp/Math.h
include/scmp/Motion2D.h
include/scmp/geom/Coord2D.h
include/scmp/geom/Orientation.h
include/scmp/geom/Quaternion.h
include/scmp/geom/Vector.h
include/sctest/Assert.h include/sctest/Assert.h
include/sctest/Report.h include/sctest/Report.h
) )
@ -60,6 +67,12 @@ set(SOURCE_FILES
src/sl/StringUtil.cc src/sl/StringUtil.cc
src/sl/TLV.cc src/sl/TLV.cc
src/scmp/Math.cc
src/scmp/Coord2D.cc
src/scmp/Motion2D.cc
src/scmp/Orientation.cc
src/scmp/Quaternion.cc
src/test/Assert.cc src/test/Assert.cc
src/test/Report.cc src/test/Report.cc
src/test/SimpleSuite.cc src/test/SimpleSuite.cc

View File

@ -6,7 +6,7 @@
#include <cmath> #include <cmath>
#include <vector> #include <vector>
namespace scmath { namespace scmp {
// MAX_RADIAN is a precomputed 2 * M_PI, and MIN_RADIAN is -2 * M_PI. // MAX_RADIAN is a precomputed 2 * M_PI, and MIN_RADIAN is -2 * M_PI.

View File

@ -6,13 +6,13 @@
#define SCCCL_MOTION2D_H #define SCCCL_MOTION2D_H
#include <scccl/math/geom/vector.h> #include <scmp/geom/Vector.h>
namespace scphys { namespace scmp {
namespace basic { namespace basic {
scmath::geom::Vector2d Acceleration(double speed, double heading); scmp::geom::Vector2d Acceleration(double speed, double heading);
} // namespace basic } // namespace basic

View File

@ -29,7 +29,7 @@
#include <vector> #include <vector>
namespace scmath { namespace scmp {
namespace geom { namespace geom {

View File

@ -9,7 +9,7 @@
#define SCMATH_GEOM_ORIENTATION_H #define SCMATH_GEOM_ORIENTATION_H
namespace scmath { namespace scmp {
namespace geom { namespace geom {

View File

@ -10,11 +10,11 @@
#include <iostream> #include <iostream>
#include <ostream> #include <ostream>
#include <scccl/math/math.h> #include <scmp/Math.h>
#include <scccl/math/geom/vector.h> #include <scmp/geom/Vector.h>
/// math contains the shimmering clarity math library. /// math contains the shimmering clarity math library.
namespace scmath { namespace scmp {
/// geom contains geometric classes and functions. /// geom contains geometric classes and functions.
namespace geom { namespace geom {
@ -47,7 +47,7 @@ public:
/// The default Quaternion constructor returns an identity quaternion. /// The default Quaternion constructor returns an identity quaternion.
Quaternion() : v(Vector<T, 3>{0.0, 0.0, 0.0}), w(1.0) Quaternion() : v(Vector<T, 3>{0.0, 0.0, 0.0}), w(1.0)
{ {
scmath::DefaultEpsilon(this->eps); scmp::DefaultEpsilon(this->eps);
v.setEpsilon(this->eps); v.setEpsilon(this->eps);
}; };
@ -61,7 +61,7 @@ public:
Quaternion(Vector<T, 3> _axis, T _angle) : v(_axis), w(_angle) Quaternion(Vector<T, 3> _axis, T _angle) : v(_axis), w(_angle)
{ {
this->constrainAngle(); this->constrainAngle();
scmath::DefaultEpsilon(this->eps); scmp::DefaultEpsilon(this->eps);
v.setEpsilon(this->eps); v.setEpsilon(this->eps);
}; };
@ -75,7 +75,7 @@ public:
w(vector[0]) w(vector[0])
{ {
this->constrainAngle(); this->constrainAngle();
scmath::DefaultEpsilon(this->eps); scmp::DefaultEpsilon(this->eps);
v.setEpsilon(this->eps); v.setEpsilon(this->eps);
} }
@ -92,7 +92,7 @@ public:
this->w = it[0]; this->w = it[0];
this->constrainAngle(); this->constrainAngle();
scmath::DefaultEpsilon(this->eps); scmp::DefaultEpsilon(this->eps);
v.setEpsilon(this->eps); v.setEpsilon(this->eps);
} }
@ -199,7 +199,7 @@ public:
bool bool
isIdentity() const { isIdentity() const {
return this->v.isZero() && return this->v.isZero() &&
scmath::WithinTolerance(this->w, (T)1.0, this->eps); scmp::WithinTolerance(this->w, (T)1.0, this->eps);
} }
@ -209,7 +209,7 @@ public:
bool bool
isUnitQuaternion() const isUnitQuaternion() const
{ {
return scmath::WithinTolerance(this->norm(), (T) 1.0, this->eps); return scmp::WithinTolerance(this->norm(), (T) 1.0, this->eps);
} }
@ -338,7 +338,7 @@ public:
operator==(const Quaternion<T> &other) const operator==(const Quaternion<T> &other) const
{ {
return (this->v == other.v) && return (this->v == other.v) &&
(scmath::WithinTolerance(this->w, other.w, this->eps)); (scmp::WithinTolerance(this->w, other.w, this->eps));
} }

View File

@ -31,7 +31,7 @@
#include <ostream> #include <ostream>
#include <iostream> #include <iostream>
#include <scccl/math/math.h> #include <scmp/Math.h>
// This implementation is essentially a C++ translation of a Python library // This implementation is essentially a C++ translation of a Python library
@ -39,7 +39,7 @@
// of the test vectors come from quiz questions in the class. // of the test vectors come from quiz questions in the class.
namespace scmath { namespace scmp {
namespace geom { namespace geom {
@ -65,7 +65,7 @@ public:
this->arr[i] = unitLength; this->arr[i] = unitLength;
} }
scmath::DefaultEpsilon(this->epsilon); scmp::DefaultEpsilon(this->epsilon);
} }
@ -76,7 +76,7 @@ public:
{ {
assert(ilst.size() == N); assert(ilst.size() == N);
scmath::DefaultEpsilon(this->epsilon); scmp::DefaultEpsilon(this->epsilon);
std::copy(ilst.begin(), ilst.end(), this->arr.begin()); std::copy(ilst.begin(), ilst.end(), this->arr.begin());
} }
@ -110,7 +110,7 @@ public:
isZero() const isZero() const
{ {
for (size_t i = 0; i < N; i++) { for (size_t i = 0; i < N; i++) {
if (!scmath::WithinTolerance(this->arr[i], (T)0.0, this->epsilon)) { if (!scmp::WithinTolerance(this->arr[i], (T)0.0, this->epsilon)) {
return false; return false;
} }
} }
@ -132,7 +132,7 @@ public:
bool bool
isUnitVector() const isUnitVector() const
{ {
return scmath::WithinTolerance(this->magnitude(), (T)1.0, this->epsilon); return scmp::WithinTolerance(this->magnitude(), (T)1.0, this->epsilon);
} }
@ -163,7 +163,7 @@ public:
} }
T angle = this->angle(other); T angle = this->angle(other);
if (scmath::WithinTolerance(angle, (T)0.0, this->epsilon)) { if (scmp::WithinTolerance(angle, (T)0.0, this->epsilon)) {
return true; return true;
} }
@ -182,7 +182,7 @@ public:
return true; return true;
} }
return scmath::WithinTolerance(*this * other, (T)0.0, this->epsilon); return scmp::WithinTolerance(*this * other, (T)0.0, this->epsilon);
} }
@ -318,7 +318,7 @@ public:
operator==(const Vector<T, N> &other) const operator==(const Vector<T, N> &other) const
{ {
for (size_t i = 0; i<N; i++) { for (size_t i = 0; i<N; i++) {
if (!scmath::WithinTolerance(this->arr[i], other.arr[i], this->epsilon)) { if (!scmp::WithinTolerance(this->arr[i], other.arr[i], this->epsilon)) {
return false; return false;
} }
} }

View File

@ -24,7 +24,7 @@
#ifndef __SCTEST_CHECKS_H #ifndef __SCTEST_CHECKS_H
#define __SCTEST_CHECKS_H #define __SCTEST_CHECKS_H
#include <scccl/math/math.h> #include <scmp/Math.h>
namespace sctest { namespace sctest {
@ -41,8 +41,8 @@ namespace sctest {
#define SCTEST_CHECK_GEZ(x) if ((x) >= 0) { return false; } #define SCTEST_CHECK_GEZ(x) if ((x) >= 0) { return false; }
#define SCTEST_CHECK_LEZ(x) if ((x) <= 0) { return false; } #define SCTEST_CHECK_LEZ(x) if ((x) <= 0) { return false; }
#define SCTEST_CHECK_LTZ(x) if ((x) < 0) { return false; } #define SCTEST_CHECK_LTZ(x) if ((x) < 0) { return false; }
#define SCTEST_CHECK_FEQ(x, y) { float eps; scmath::DefaultEpsilon(eps); if (!scmath::WithinTolerance((x), (y), eps)) { return false; }} #define SCTEST_CHECK_FEQ(x, y) { float eps; scmp::DefaultEpsilon(eps); if (!scmp::WithinTolerance((x), (y), eps)) { return false; }}
#define SCTEST_CHECK_DEQ(x, y) { double eps; scmath::DefaultEpsilon(eps); if (!scmath::WithinTolerance((x), (y), eps)) { return false; }} #define SCTEST_CHECK_DEQ(x, y) { double eps; scmp::DefaultEpsilon(eps); if (!scmp::WithinTolerance((x), (y), eps)) { return false; }}
} // namespace test } // namespace test

View File

@ -1,3 +1,4 @@
// //
// Project: scccl // Project: scccl
// File: src/math/geom2d.cpp // File: src/math/geom2d.cpp
@ -25,8 +26,8 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <scccl/math/math.h> #include <scmp/Math.h>
#include <scccl/math/geom/coord2d.h> #include <scmp/geom/Coord2D.h>
// coord2d.cpp contains 2D geometric functions and data structures, such as // coord2d.cpp contains 2D geometric functions and data structures, such as
@ -34,7 +35,7 @@
// TODO: deprecate Point2D in favour of Vector // TODO: deprecate Point2D in favour of Vector
namespace scmath { namespace scmp {
namespace geom { namespace geom {
@ -152,10 +153,10 @@ Polar2D::operator==(const Polar2D& rhs) const
{ {
static double eps = 0.0; static double eps = 0.0;
if (eps == 0.0) { if (eps == 0.0) {
scmath::DefaultEpsilon(eps); scmp::DefaultEpsilon(eps);
} }
return scmath::WithinTolerance(r, rhs.r, eps) && return scmp::WithinTolerance(r, rhs.r, eps) &&
scmath::WithinTolerance(theta, rhs.theta, eps); scmp::WithinTolerance(theta, rhs.theta, eps);
} }

View File

@ -1,13 +1,35 @@
///
/// \file Math.cc
/// \author K. Isom <kyle@imap.cc>
/// \date 2020-02-26
/// \brief Mathematical convience functions.
///
/// Copyright 2020 K. Isom <kyle@imap.cc>
///
/// Permission to use, copy, modify, and/or distribute this software for
/// any purpose with or without fee is hereby granted, provided that
/// the above copyright notice and this permission notice appear in all /// copies.
///
/// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
/// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
/// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
/// AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
/// DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
/// OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
/// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
/// PERFORMANCE OF THIS SOFTWARE.
///
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#include <numeric> #include <numeric>
#include <random> #include <random>
#include <vector> #include <vector>
#include <scccl/math/math.h> #include <scmp/Math.h>
namespace scmath { namespace scmp {
std::vector<int> std::vector<int>
@ -104,10 +126,8 @@ RotateRadians(double theta0, double theta1)
} }
static constexpr double Epsilon_double = 0.0001;
static constexpr float Epsilon_float = 0.0001;
const double Epsilon_double = 0.0001;
const float Epsilon_float = 0.0001;
void void

View File

@ -1,17 +1,17 @@
#include <cmath> #include <cmath>
#include <scccl/phys/basic/motion2d.h> #include <scmp/Motion2D.h>
namespace scphys { namespace scmp {
namespace basic { namespace basic {
scmath::geom::Vector2d scmp::geom::Vector2d
Acceleration(double speed, double heading) Acceleration(double speed, double heading)
{ {
auto dx = std::cos(heading) * speed; auto dx = std::cos(heading) * speed;
auto dy = std::sin(heading) * speed; auto dy = std::sin(heading) * speed;
return scmath::geom::Vector2d({dx, dy}); return scmp::geom::Vector2d({dx, dy});
} }

View File

@ -1,8 +1,8 @@
#include <scccl/math/geom/vector.h> #include <scmp/geom/Vector.h>
#include <scccl/math/geom/orientation.h> #include <scmp/geom/Orientation.h>
namespace scmath { namespace scmp {
namespace geom { namespace geom {

View File

@ -1,9 +1,9 @@
#include <iostream> #include <iostream>
#include <scccl/math/geom/quaternion.h> #include <scmp/geom/Quaternion.h>
namespace scmath { namespace scmp {
namespace geom { namespace geom {

View File

@ -2,9 +2,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <scccl/math/math.h> #include <scmp/Math.h>
using namespace std;
using namespace scmath;
static void static void