clang-tidy fixes, documentation, refactoring.

This commit is contained in:
2023-10-21 02:07:59 -07:00
parent 4e83da345f
commit aee337f2e9
26 changed files with 325 additions and 238 deletions

View File

@@ -30,11 +30,6 @@
#include <scmp/geom/Vector.h>
// coord2d.cpp contains 2D geometric functions and data structures, such as
// cartesian and polar coordinates and rotations.
// TODO: deprecate Point2D in favour of Vector
namespace scmp {
namespace geom {
@@ -60,7 +55,7 @@ Point2D::Point2D(const Polar2D &pol)
int
Point2D::X() const
{
return this->At(0);
return this->At(BasisX);
}
@@ -74,21 +69,21 @@ Point2D::X(int _x)
int
Point2D::Y() const
{
return this->At(1);
return this->At(BasisY);
}
void
Point2D::Y(int _y)
{
this->Set(1, _y);
this->Set(BasisY, _y);
}
std::ostream &
operator<<(std::ostream &outs, const Point2D &pt)
{
outs << "(" << std::to_string(pt[0]) << ", " << std::to_string(pt[1]) << ")";
outs << "(" << std::to_string(pt.X()) << ", " << std::to_string(pt.Y()) << ")";
return outs;
}
@@ -192,8 +187,8 @@ Polar2D::Theta(const double _theta)
void
Polar2D::ToPoint(Point2D &point)
{
point.Y(std::rint(std::sin(this->Theta()) * this->R()));
point.X(std::rint(std::cos(this->Theta()) * this->R()));
point.Y(static_cast<int>(std::rint(std::sin(this->Theta()) * this->R())));
point.X(static_cast<int>(std::rint(std::cos(this->Theta()) * this->R())));
}
@@ -232,4 +227,4 @@ operator<<(std::ostream &outs, const Polar2D &pol)
} // end namespace geom
} // end namespace math
} // end namespace scmp

View File

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

View File

@@ -1,3 +1,26 @@
///
/// \file src/scmp/geom/Orientation.cc
/// \author K. Isom <kyle@imap.cc>
/// \date 2017-06-05
/// \brief Orientation of vectors w.r.t. a reference plane, assumed to
/// be the Earth.
///
/// Copyright 2017 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 <scmp/geom/Vector.h>
#include <scmp/geom/Orientation.h>
@@ -14,25 +37,25 @@ Heading2F(Vector2F vec)
float
Heading3f(Vector3F vec)
Heading3F(Vector3F vec)
{
Vector2F vec2f {vec[0], vec[1]};
const Vector2F vec2f {vec.At(BasisX), vec.At(BasisY)};
return Heading2F(vec2f);
}
double
Heading2d(Vector2D vec)
Heading2D(Vector2D vec)
{
return vec.Angle(Basis2D[BasisX]);
}
double
Heading3d(Vector3D vec)
Heading3D(Vector3D vec)
{
Vector2D vec2d {vec[0], vec[1]};
return Heading2d(vec2d);
const Vector2D vec2d {vec.At(BasisX), vec.At(BasisY)};
return Heading2D(vec2d);
}