From 8d02d078e70cf8e543d57cb238c9f76b9383c02a Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Wed, 18 Oct 2023 23:57:50 -0700 Subject: [PATCH] refactor namespaces --- CMakeLists.txt | 13 ++++++++ include/scmp/{math.h => Math.h} | 2 +- include/scmp/{motion2d.h => Motion2D.h} | 6 ++-- include/scmp/geom/{coord2d.h => Coord2D.h} | 2 +- .../geom/{orientation.h => Orientation.h} | 2 +- .../scmp/geom/{quaternion.h => Quaternion.h} | 20 ++++++------ include/scmp/geom/{vector.h => Vector.h} | 18 +++++------ include/sctest/checks.h | 6 ++-- src/scmp/{coord2d.cc => Coord2D.cc} | 13 ++++---- src/scmp/{math.cc => Math.cc} | 32 +++++++++++++++---- src/scmp/{motion2d.cc => Motion2D.cc} | 8 ++--- src/scmp/{orientation.cc => Orientation.cc} | 6 ++-- src/scmp/{quaternion.cc => Quaternion.cc} | 4 +-- src/sl/Roll.cc | 4 +-- 14 files changed, 84 insertions(+), 52 deletions(-) rename include/scmp/{math.h => Math.h} (99%) rename include/scmp/{motion2d.h => Motion2D.h} (60%) rename include/scmp/geom/{coord2d.h => Coord2D.h} (99%) rename include/scmp/geom/{orientation.h => Orientation.h} (99%) rename include/scmp/geom/{quaternion.h => Quaternion.h} (96%) rename include/scmp/geom/{vector.h => Vector.h} (95%) rename src/scmp/{coord2d.cc => Coord2D.cc} (93%) rename src/scmp/{math.cc => Math.cc} (58%) rename src/scmp/{motion2d.cc => Motion2D.cc} (56%) rename src/scmp/{orientation.cc => Orientation.cc} (80%) rename src/scmp/{quaternion.cc => Quaternion.cc} (97%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a70c35..0eea2aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,13 @@ set(HEADER_FILES include/scsl/StringUtil.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/Report.h ) @@ -60,6 +67,12 @@ set(SOURCE_FILES src/sl/StringUtil.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/Report.cc src/test/SimpleSuite.cc diff --git a/include/scmp/math.h b/include/scmp/Math.h similarity index 99% rename from include/scmp/math.h rename to include/scmp/Math.h index 3c5861c..014964a 100644 --- a/include/scmp/math.h +++ b/include/scmp/Math.h @@ -6,7 +6,7 @@ #include #include -namespace scmath { +namespace scmp { // MAX_RADIAN is a precomputed 2 * M_PI, and MIN_RADIAN is -2 * M_PI. diff --git a/include/scmp/motion2d.h b/include/scmp/Motion2D.h similarity index 60% rename from include/scmp/motion2d.h rename to include/scmp/Motion2D.h index fb2a184..c1abbf4 100644 --- a/include/scmp/motion2d.h +++ b/include/scmp/Motion2D.h @@ -6,13 +6,13 @@ #define SCCCL_MOTION2D_H -#include +#include -namespace scphys { +namespace scmp { namespace basic { -scmath::geom::Vector2d Acceleration(double speed, double heading); +scmp::geom::Vector2d Acceleration(double speed, double heading); } // namespace basic diff --git a/include/scmp/geom/coord2d.h b/include/scmp/geom/Coord2D.h similarity index 99% rename from include/scmp/geom/coord2d.h rename to include/scmp/geom/Coord2D.h index 1b2e77f..f0cf251 100755 --- a/include/scmp/geom/coord2d.h +++ b/include/scmp/geom/Coord2D.h @@ -29,7 +29,7 @@ #include -namespace scmath { +namespace scmp { namespace geom { diff --git a/include/scmp/geom/orientation.h b/include/scmp/geom/Orientation.h similarity index 99% rename from include/scmp/geom/orientation.h rename to include/scmp/geom/Orientation.h index 53284ce..adfd0bd 100644 --- a/include/scmp/geom/orientation.h +++ b/include/scmp/geom/Orientation.h @@ -9,7 +9,7 @@ #define SCMATH_GEOM_ORIENTATION_H -namespace scmath { +namespace scmp { namespace geom { diff --git a/include/scmp/geom/quaternion.h b/include/scmp/geom/Quaternion.h similarity index 96% rename from include/scmp/geom/quaternion.h rename to include/scmp/geom/Quaternion.h index 423a0ab..7499cd9 100644 --- a/include/scmp/geom/quaternion.h +++ b/include/scmp/geom/Quaternion.h @@ -10,11 +10,11 @@ #include #include -#include -#include +#include +#include /// math contains the shimmering clarity math library. -namespace scmath { +namespace scmp { /// geom contains geometric classes and functions. namespace geom { @@ -47,7 +47,7 @@ public: /// The default Quaternion constructor returns an identity quaternion. Quaternion() : v(Vector{0.0, 0.0, 0.0}), w(1.0) { - scmath::DefaultEpsilon(this->eps); + scmp::DefaultEpsilon(this->eps); v.setEpsilon(this->eps); }; @@ -61,7 +61,7 @@ public: Quaternion(Vector _axis, T _angle) : v(_axis), w(_angle) { this->constrainAngle(); - scmath::DefaultEpsilon(this->eps); + scmp::DefaultEpsilon(this->eps); v.setEpsilon(this->eps); }; @@ -75,7 +75,7 @@ public: w(vector[0]) { this->constrainAngle(); - scmath::DefaultEpsilon(this->eps); + scmp::DefaultEpsilon(this->eps); v.setEpsilon(this->eps); } @@ -92,7 +92,7 @@ public: this->w = it[0]; this->constrainAngle(); - scmath::DefaultEpsilon(this->eps); + scmp::DefaultEpsilon(this->eps); v.setEpsilon(this->eps); } @@ -199,7 +199,7 @@ public: bool isIdentity() const { 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 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 &other) const { return (this->v == other.v) && - (scmath::WithinTolerance(this->w, other.w, this->eps)); + (scmp::WithinTolerance(this->w, other.w, this->eps)); } diff --git a/include/scmp/geom/vector.h b/include/scmp/geom/Vector.h similarity index 95% rename from include/scmp/geom/vector.h rename to include/scmp/geom/Vector.h index be699a1..79395bf 100644 --- a/include/scmp/geom/vector.h +++ b/include/scmp/geom/Vector.h @@ -31,7 +31,7 @@ #include #include -#include +#include // 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. -namespace scmath { +namespace scmp { namespace geom { @@ -65,7 +65,7 @@ public: this->arr[i] = unitLength; } - scmath::DefaultEpsilon(this->epsilon); + scmp::DefaultEpsilon(this->epsilon); } @@ -76,7 +76,7 @@ public: { assert(ilst.size() == N); - scmath::DefaultEpsilon(this->epsilon); + scmp::DefaultEpsilon(this->epsilon); std::copy(ilst.begin(), ilst.end(), this->arr.begin()); } @@ -110,7 +110,7 @@ public: isZero() const { 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; } } @@ -132,7 +132,7 @@ public: bool 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); - if (scmath::WithinTolerance(angle, (T)0.0, this->epsilon)) { + if (scmp::WithinTolerance(angle, (T)0.0, this->epsilon)) { return true; } @@ -182,7 +182,7 @@ public: 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 &other) const { for (size_t i = 0; iarr[i], other.arr[i], this->epsilon)) { + if (!scmp::WithinTolerance(this->arr[i], other.arr[i], this->epsilon)) { return false; } } diff --git a/include/sctest/checks.h b/include/sctest/checks.h index b9293be..827603d 100755 --- a/include/sctest/checks.h +++ b/include/sctest/checks.h @@ -24,7 +24,7 @@ #ifndef __SCTEST_CHECKS_H #define __SCTEST_CHECKS_H -#include +#include namespace sctest { @@ -41,8 +41,8 @@ namespace sctest { #define SCTEST_CHECK_GEZ(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_FEQ(x, y) { float eps; scmath::DefaultEpsilon(eps); if (!scmath::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_FEQ(x, y) { float eps; scmp::DefaultEpsilon(eps); if (!scmp::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 diff --git a/src/scmp/coord2d.cc b/src/scmp/Coord2D.cc similarity index 93% rename from src/scmp/coord2d.cc rename to src/scmp/Coord2D.cc index f8021fa..88723ba 100755 --- a/src/scmp/coord2d.cc +++ b/src/scmp/Coord2D.cc @@ -1,3 +1,4 @@ + // // Project: scccl // File: src/math/geom2d.cpp @@ -25,8 +26,8 @@ #include #include -#include -#include +#include +#include // coord2d.cpp contains 2D geometric functions and data structures, such as @@ -34,7 +35,7 @@ // TODO: deprecate Point2D in favour of Vector -namespace scmath { +namespace scmp { namespace geom { @@ -152,10 +153,10 @@ Polar2D::operator==(const Polar2D& rhs) const { static double eps = 0.0; if (eps == 0.0) { - scmath::DefaultEpsilon(eps); + scmp::DefaultEpsilon(eps); } - return scmath::WithinTolerance(r, rhs.r, eps) && - scmath::WithinTolerance(theta, rhs.theta, eps); + return scmp::WithinTolerance(r, rhs.r, eps) && + scmp::WithinTolerance(theta, rhs.theta, eps); } diff --git a/src/scmp/math.cc b/src/scmp/Math.cc similarity index 58% rename from src/scmp/math.cc rename to src/scmp/Math.cc index 0dd0980..9d04ac3 100644 --- a/src/scmp/math.cc +++ b/src/scmp/Math.cc @@ -1,13 +1,35 @@ +/// +/// \file Math.cc +/// \author K. Isom +/// \date 2020-02-26 +/// \brief Mathematical convience functions. +/// +/// Copyright 2020 K. Isom +/// +/// 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 #include #include #include #include -#include +#include -namespace scmath { +namespace scmp { std::vector @@ -104,10 +126,8 @@ RotateRadians(double theta0, double theta1) } - - -const double Epsilon_double = 0.0001; -const float Epsilon_float = 0.0001; +static constexpr double Epsilon_double = 0.0001; +static constexpr float Epsilon_float = 0.0001; void diff --git a/src/scmp/motion2d.cc b/src/scmp/Motion2D.cc similarity index 56% rename from src/scmp/motion2d.cc rename to src/scmp/Motion2D.cc index 8582ae3..cbd0d3d 100644 --- a/src/scmp/motion2d.cc +++ b/src/scmp/Motion2D.cc @@ -1,17 +1,17 @@ #include -#include +#include -namespace scphys { +namespace scmp { namespace basic { -scmath::geom::Vector2d +scmp::geom::Vector2d Acceleration(double speed, double heading) { auto dx = std::cos(heading) * speed; auto dy = std::sin(heading) * speed; - return scmath::geom::Vector2d({dx, dy}); + return scmp::geom::Vector2d({dx, dy}); } diff --git a/src/scmp/orientation.cc b/src/scmp/Orientation.cc similarity index 80% rename from src/scmp/orientation.cc rename to src/scmp/Orientation.cc index 4232616..26f3523 100644 --- a/src/scmp/orientation.cc +++ b/src/scmp/Orientation.cc @@ -1,8 +1,8 @@ -#include -#include +#include +#include -namespace scmath { +namespace scmp { namespace geom { diff --git a/src/scmp/quaternion.cc b/src/scmp/Quaternion.cc similarity index 97% rename from src/scmp/quaternion.cc rename to src/scmp/Quaternion.cc index 6cf5a61..e9fe7aa 100644 --- a/src/scmp/quaternion.cc +++ b/src/scmp/Quaternion.cc @@ -1,9 +1,9 @@ #include -#include +#include -namespace scmath { +namespace scmp { namespace geom { diff --git a/src/sl/Roll.cc b/src/sl/Roll.cc index 4755c22..ddaf66a 100644 --- a/src/sl/Roll.cc +++ b/src/sl/Roll.cc @@ -2,9 +2,7 @@ #include #include -#include -using namespace std; -using namespace scmath; +#include static void