Document and refactor geom code.

- Doxygenate headers.
- Rename to bring methods and functions in line with everything else.
This commit is contained in:
2023-10-20 20:45:39 -07:00
parent 4b1007123a
commit 6a421d6adf
27 changed files with 802 additions and 680 deletions

View File

@@ -49,26 +49,26 @@ int BestDie(int k, int m, int n);
/// \brief Convert radians to degrees.
///
/// \param rads the angle in radians
/// \return the angle in degrees.
/// \param rads the Angle in radians
/// \return the Angle in degrees.
float RadiansToDegreesF(float rads);
/// \brief Convert radians to degrees.
///
/// \param rads the angle in radians
/// \return the angle in degrees.
/// \param rads the Angle in radians
/// \return the Angle in degrees.
double RadiansToDegreesD(double rads);
/// \brief Convert degrees to radians.
///
/// \param degrees the angle in degrees
/// \return the angle in radians.
/// \param degrees the Angle in degrees
/// \return the Angle in radians.
float DegreesToRadiansF(float degrees);
/// \brief Convert degrees to radians.
///
/// \param degrees the angle in degrees
/// \return the angle in radians.
/// \param degrees the Angle in degrees
/// \return the Angle in radians.
double DegreesToRadiansD(double degrees);
/// \brief RotateRadians rotates theta0 by theta1 radians, wrapping

View File

@@ -12,7 +12,7 @@ namespace scmp {
namespace basic {
scmp::geom::Vector2d Acceleration(double speed, double heading);
scmp::geom::Vector2D Acceleration(double speed, double heading);
} // namespace basic

View File

@@ -40,8 +40,8 @@ namespace filter {
/// @brief Madgwick implements an efficient Orientation filter for IMUs.
///
/// Madgwick is a novel Orientation filter applicable to IMUs
/// consisting of tri-axis gyroscopes and accelerometers, and MARG
/// sensor arrays that also include tri-axis magnetometers. The MARG
/// consisting of tri-Axis gyroscopes and accelerometers, and MARG
/// sensor arrays that also include tri-Axis magnetometers. The MARG
/// implementation incorporates magnetic distortionand gyroscope bias
/// drift compensation.
///
@@ -51,24 +51,24 @@ namespace filter {
template <typename T>
class Madgwick {
public:
/// \brief The Madgwick filter is initialised with an identity quaternion.
/// \brief The Madgwick filter is initialised with an identity MakeQuaternion.
Madgwick() : deltaT(0.0), previousSensorFrame(), sensorFrame()
{};
/// \brief The Madgwick filter is initialised with a sensor frame.
///
/// \param sf A sensor frame; if zero, the sensor frame will be
/// initialised as an identity quaternion.
/// initialised as an identity MakeQuaternion.
Madgwick(scmp::geom::Vector<T, 3> sf) : deltaT(0.0), previousSensorFrame()
{
if (!sf.isZero()) {
sensorFrame = scmp::geom::quaternion<T>(sf, 0.0);
if (!sf.IsZero()) {
sensorFrame = scmp::geom::MakeQuaternion<T>(sf, 0.0);
}
}
/// \brief Initialise the filter with a sensor frame quaternion.
/// \brief Initialise the filter with a sensor frame MakeQuaternion.
///
/// \param sf A quaternion representing the current Orientation.
/// \param sf A MakeQuaternion representing the current Orientation.
Madgwick(scmp::geom::Quaternion<T> sf) :
deltaT(0.0), previousSensorFrame(), sensorFrame(sf)
{};
@@ -91,7 +91,7 @@ public:
///
/// \param gyro A three-dimensional vector containing gyro readings
/// as w_x, w_y, w_z.
/// \return A quaternion representing the rate of angular change.
/// \return A MakeQuaternion representing the rate of angular change.
scmp::geom::Quaternion<T>
AngularRate(const scmp::geom::Vector<T, 3> &gyro) const
{
@@ -166,7 +166,7 @@ public:
scmp::geom::Vector<T, 3>
Euler()
{
return this->sensorFrame.euler();
return this->sensorFrame.Euler();
}
/// \brief Set the default Δt.

View File

@@ -2,7 +2,7 @@
/// \file include/scmp/geom.h
/// \author K. Isom <kyle@imap.cc>
/// \date 2023-10-20
/// \brief 2D point and polar coordinate systems.
/// \brief Vector-based geometry code.
///
/// Copyright 2023 K. Isom <kyle@imap.cc>
///

View File

@@ -46,7 +46,7 @@ public:
/// \brief A Point2D defaults to (0,0).
Point2D();
/// \brief Initialize a Point2D at (_x, _y).
/// \brief Initialize a Point2D At (_x, _y).
Point2D(int _x, int _y);
/// \brief Initialize a Point2D from a Polar2D coordinate.
@@ -74,13 +74,13 @@ public:
/// \brief Rotate rotates the point by theta radians.
///
/// \param rotated Stores the rotated point.
/// \param theta The angle (in radians) to rotate the point.
/// \param theta The Angle (in radians) to Rotate the point.
void Rotate(Point2D& rotated, double theta);
/// \brief Rotate this point around a series of vertices.
///
/// \param vertices A series of vertices to rotate this point around.
/// \param theta The angle to rotate by.
/// \param vertices A series of vertices to Rotate this point around.
/// \param theta The Angle to Rotate by.
/// \return A series of rotated points.
std::vector<Point2D> Rotate(std::vector<Polar2D> vertices, double theta);
@@ -98,12 +98,12 @@ public:
};
// A Polar2D is a 2D polar coordinate, specified in terms of the radius from
// some origin and the angle from the positive X axis of a cartesian coordinate
// some origin and the Angle from the positive X Axis of a cartesian coordinate
// system.
class Polar2D : public Vector<double, 2> {
public:
// A Polar2D can be initialised as a zeroised polar coordinate, by specifying
// the radius and angle directly, or via conversion from a Point2D.
// the radius and Angle directly, or via conversion from a Point2D.
Polar2D();
Polar2D(double _r, double _theta);
Polar2D(const Point2D &);

View File

@@ -1,11 +1,31 @@
/**
* 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.
*/
///
/// \file include/scmp/geom/Orientation.h
/// \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 2023 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 <cstdint>
#include <scmp/geom/Vector.h>
#ifndef SCMATH_GEOM_ORIENTATION_H
#define SCMATH_GEOM_ORIENTATION_H
@@ -19,71 +39,75 @@ namespace geom {
/// and three-dimensional vectors.
/// \ingroup basis
/// Convenience constant for the x index.
constexpr uint8_t Basis_x = 0;
/// \brief Convenience constant for the x index.
constexpr uint8_t BasisX = 0;
/// \ingroup basis
/// Convenience constant for the y index.
constexpr uint8_t Basis_y = 1;
/// \brief Convenience constant for the y index.
constexpr uint8_t BasisY = 1;
/// \ingroup basis
/// Convenience constant for the z index.
constexpr uint8_t Basis_z = 2;
/// \brief Convenience constant for the z index.
constexpr uint8_t BasisZ = 2;
/// @brief Basis2d provides basis vectors for Vector2ds.
static const Vector2d Basis2d[] = {
Vector2d{1, 0},
Vector2d{0, 1},
/// \brief Basis2D provides basis vectors for Vector2ds.
static const Vector2D Basis2D[] = {
Vector2D{1, 0},
Vector2D{0, 1},
};
/// @brief Basis2d provides basis vectors for Vector2fs.
static const Vector2f Basis2f[] = {
Vector2f{1, 0},
Vector2f{0, 1},
/// \brief Basis2D provides basis vectors for Vector2fs.
static const Vector2F Basis2F[] = {
Vector2F{1, 0},
Vector2F{0, 1},
};
/// @brief Basis2d provides basis vectors for Vector3ds.
static const Vector3d Basis3d[] = {
Vector3d{1, 0, 0},
Vector3d{0, 1, 0},
Vector3d{0, 0, 1},
/// \brief Basis2D provides basis vectors for Vector3ds.
static const Vector3D Basis3D[] = {
Vector3D{1, 0, 0},
Vector3D{0, 1, 0},
Vector3D{0, 0, 1},
};
/// @brief Basis2d provides basis vectors for Vector3fs.
static const Vector3f Basis3f[] = {
Vector3f{1, 0, 0},
Vector3f{0, 1, 0},
Vector3f{0, 0, 1},
/// \brief Basis2D provides basis vectors for Vector3fs.
static const Vector3F Basis3F[] = {
Vector3F{1, 0, 0},
Vector3F{0, 1, 0},
Vector3F{0, 0, 1},
};
/// Heading2f returns a compass heading for a Vector2f.
/// @param vec A vector Orientation.
/// @return The compass heading of the vector in radians.
float Heading2f(Vector2f vec);
/// \brief Compass heading for a Vector2F.
///
/// \param vec A vector Orientation.
/// \return The compass heading of the vector in radians.
float Heading2F(Vector2F vec);
/// Heading2d returns a compass heading for a Vector2d.
/// @param vec A vector Orientation.
/// @return The compass heading of the vector in radians.
double Heading2d(Vector2d vec);
/// \brief Compass heading for a Vector2D.
///
/// \param vec A vector Orientation.
/// \return The compass heading of the vector in radians.
double Heading2d(Vector2D vec);
/// Heading3f returns a compass heading for a Vector2f.
/// @param vec A vector Orientation.
/// @return The compass heading of the vector in radians.
float Heading3f(Vector3f vec);
/// \brief Compass heading for a Vector2F.
///
/// \param vec A vector Orientation.
/// \return The compass heading of the vector in radians.
float Heading3f(Vector3F vec);
/// Heading3d returns a compass heading for a Vector2f.
/// @param vec A vector Orientation.
/// @return The compass heading of the vector in radians.
double Heading3d(Vector3d vec);
/// Heading3d returns a compass heading for a Vector2F.
///
/// \param vec A vector Orientation.
/// \return The compass heading of the vector in radians.
double Heading3d(Vector3D vec);
} // namespace geom
} // namespace scmp
#endif // __WRMATH_ORIENTATION_H
#endif // SCMATH_GEOM_ORIENTATION_H

View File

@@ -1,7 +1,27 @@
/// quaternion.h contains an implementation of quaternions suitable
/// for navigation in R3.
#ifndef SCMATH_QUATERNION_H
#define SCMATH_QUATERNION_H
///
/// \file include/scmp/geom/Quaternion.h
/// \author K. Isom <kyle@imap.cc>
/// \date 2019-08-05
/// \brief Quaternion implementation suitable for navigation in R3.
///
/// Copyright 2019 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.
///
#ifndef SCMATH_GEOM_QUATERNION_H
#define SCMATH_GEOM_QUATERNION_H
#include <cassert>
@@ -13,77 +33,79 @@
#include <scmp/Math.h>
#include <scmp/geom/Vector.h>
/// math contains the shimmering clarity math library.
namespace scmp {
/// geom contains geometric classes and functions.
namespace geom {
/// @brief Quaternions provide a representation of Orientation and rotations
/// in three dimensions.
/// \brief Quaternions provide a representation of Orientation
/// and rotations in three dimensions.
///
/// Quaternions encode rotations in three-dimensional space. While technically
/// a quaternion is comprised of a real element and a complex vector<3>, for
/// the purposes of this library, it is modeled as a floating point 4D vector
/// of the form <w, x, y, z>, where x, y, and z represent an axis of rotation in
/// R3 and w the angle, in radians, of the rotation about that axis. Where Euler
/// angles are concerned, the ZYX (or yaw, pitch, roll) sequence is used.
/// Quaternions encode rotations in three-dimensional space. While
/// technically a MakeQuaternion is comprised of a real element and a
/// complex vector<3>, for the purposes of this library, it is modeled
/// as a floating point 4D vector of the form <w, x, y, z>, where x, y,
/// and z represent an Axis of rotation in R3 and w the Angle, in
/// radians, of the rotation about that Axis. Where Euler angles are
/// concerned, the ZYX (or yaw, pitch, roll) sequence is used.
///
/// For information on the underlying vector type, see the documentation for
/// wr::geom::Vector.
/// For information on the underlying vector type, see the
/// documentation for scmp::geom::Vector.
///
/// The constructors are primarily intended for intended operations; in practice,
/// the quaternionf() and quaterniond() functions are more useful for constructing
/// quaternions from vectors and angles.
///
/// Like vectors, quaternions carry an internal tolerance value ε that is used for
/// floating point comparisons. The math namespace contains the default values
/// used for this; generally, a tolerance of 0.0001 is considered appropriate for
/// the uses of this library. The tolerance can be explicitly set with the
/// setEpsilon method.
/// Like vectors, quaternions carry an internal tolerance value ε that
/// is used for floating point comparisons. The math namespace contains
/// the default values used for this; generally, a tolerance of 0.0001
/// is considered appropriate for the uses of this library. The
/// tolerance can be explicitly set with the SetEpsilon method.
template<typename T>
class Quaternion {
public:
/// The default Quaternion constructor returns an identity quaternion.
/// \brief Construct an identity MakeQuaternion.
Quaternion() : v(Vector<T, 3>{0.0, 0.0, 0.0}), w(1.0)
{
scmp::DefaultEpsilon(this->eps);
v.setEpsilon(this->eps);
v.SetEpsilon(this->eps);
};
/// A Quaternion may be initialised with a Vector<T, 3> axis of rotation
/// and an angle of rotation. This doesn't do the angle transforms to simplify
/// internal operations.
/// \brief Construct a MakeQuaternion with an Axis and Angle of
/// rotation.
///
/// @param _axis A three-dimensional vector of the same type as the Quaternion.
/// @param _angle The angle of rotation about the axis of rotation.
/// A Quaternion may be initialised with a Vector<T, 3> Axis
/// of rotation and an Angle of rotation. This doesn't do the
/// Angle transforms to simplify internal operations.
///
/// \param _axis A three-dimensional vector of the same type as
/// the Quaternion.
/// \param _angle The Angle of rotation about the Axis of
/// rotation.
Quaternion(Vector<T, 3> _axis, T _angle) : v(_axis), w(_angle)
{
this->constrainAngle();
scmp::DefaultEpsilon(this->eps);
v.setEpsilon(this->eps);
v.SetEpsilon(this->eps);
};
/// A Quaternion may be initialised with a Vector<T, 4> comprised of
/// the axis of rotation followed by the angle of rotation.
/// the Axis of rotation followed by the Angle of rotation.
///
/// @param vector A vector in the form <w, x, y, z>.
/// \param vector A vector in the form <w, x, y, z>.
Quaternion(Vector<T, 4> vector) :
v(Vector<T, 3>{vector[1], vector[2], vector[3]}),
w(vector[0])
{
this->constrainAngle();
scmp::DefaultEpsilon(this->eps);
v.setEpsilon(this->eps);
v.SetEpsilon(this->eps);
}
/// A Quaternion may be constructed with an initializer list of
/// type T, which must have exactly N elements.
/// \brief An initializer list containing values for w, x, y,
/// and z.
///
/// @param ilst An initial set of values in the form <w, x, y, z>.
/// \param ilst An initial set of values in the form
/// <w, x, y, z>.
Quaternion(std::initializer_list<T> ilst)
{
auto it = ilst.begin();
@@ -93,47 +115,47 @@ public:
this->constrainAngle();
scmp::DefaultEpsilon(this->eps);
v.setEpsilon(this->eps);
v.SetEpsilon(this->eps);
}
/// Set the comparison tolerance for this quaternion.
/// \brief Set the comparison tolerance for this MakeQuaternion.
///
/// @param epsilon A tolerance value.
/// \param epsilon A tolerance value.
void
setEpsilon(T epsilon)
SetEpsilon(T epsilon)
{
this->eps = epsilon;
this->v.setEpsilon(epsilon);
this->v.SetEpsilon(epsilon);
}
/// Return the axis of rotation of this quaternion.
/// \brief Return the Axis of rotation of this MakeQuaternion.
///
/// @return The axis of rotation of this quaternion.
/// \return The Axis of rotation of this MakeQuaternion.
Vector<T, 3>
axis() const
Axis() const
{
return this->v;
}
/// Return the angle of rotation of this quaternion.
/// \brief Return the Angle of rotation of this MakeQuaternion.
///
/// @return the angle of rotation of this quaternion.
/// \return the Angle of rotation of this MakeQuaternion.
T
angle() const
Angle() const
{
return this->w;
}
/// Compute the dot product of two quaternions.
/// \brief Compute the Dot product of two quaternions.
///
/// \param other Another quaternion.
/// \return The dot product between the two quaternions.
/// \param other Another MakeQuaternion.
/// \return The Dot product between the two quaternions.
T
dot(const Quaternion<T> &other) const
Dot(const Quaternion<T> &other) const
{
double innerProduct = this->v[0] * other.v[0];
@@ -144,12 +166,14 @@ public:
}
/// Compute the norm of a quaternion. Treating the Quaternion as a
/// Vector<T, 4>, it's the same as computing the magnitude.
/// \brief Compute the Norm of a MakeQuaternion.
///
/// @return A non-negative real number.
/// Treating the Quaternion as a Vector<T, 4>, this is the same
/// process as computing the Magnitude.
///
/// \return A non-negative real number.
T
norm() const
Norm() const
{
T n = 0;
@@ -162,86 +186,92 @@ public:
}
/// Return the unit quaternion.
/// \brief Return the unit MakeQuaternion.
///
/// \return The unit quaternion.
/// \return The unit MakeQuaternion.
Quaternion
unitQuaternion()
UnitQuaternion()
{
return *this / this->norm();
return *this / this->Norm();
}
/// Compute the conjugate of a quaternion.
/// \brief Compute the Conjugate of a MakeQuaternion.
///
/// @return The conjugate of this quaternion.
/// \return The Conjugate of this MakeQuaternion.
Quaternion
conjugate() const
Conjugate() const
{
return Quaternion(Vector<T, 4>{this->w, -this->v[0], -this->v[1], -this->v[2]});
}
/// Compute the inverse of a quaternion.
/// \brief Compute the Inverse of a MakeQuaternion.
///
/// @return The inverse of this quaternion.
/// \return The Inverse of this MakeQuaternion.
Quaternion
inverse() const
Inverse() const
{
T _norm = this->norm();
T _norm = this->Norm();
return this->conjugate() / (_norm * _norm);
return this->Conjugate() / (_norm * _norm);
}
/// Determine whether this is an identity quaternion.
/// \brief Determine whether this is an identity MakeQuaternion.
///
/// \return true if this is an identity quaternion.
/// \return true if this is an identity MakeQuaternion.
bool
isIdentity() const {
return this->v.isZero() &&
IsIdentity() const {
return this->v.IsZero() &&
scmp::WithinTolerance(this->w, (T)1.0, this->eps);
}
/// Determine whether this is a unit quaternion.
/// \brief Determine whether this is a unit MakeQuaternion.
///
/// @return true if this is a unit quaternion.
/// \return true if this is a unit MakeQuaternion.
bool
isUnitQuaternion() const
IsUnitQuaternion() const
{
return scmp::WithinTolerance(this->norm(), (T) 1.0, this->eps);
return scmp::WithinTolerance(this->Norm(), (T) 1.0, this->eps);
}
/// Return the quaternion as a Vector<T, 4>, with the axis of rotation
/// followed by the angle of rotation.
/// \brief Convert to Vector form.
///
/// @return A vector representation of the quaternion.
/// Return the MakeQuaternion as a Vector<T, 4>, with the Axis of
/// rotation followed by the Angle of rotation.
///
/// \return A vector representation of the MakeQuaternion.
Vector<T, 4>
asVector() const
AsVector() const
{
return Vector<T, 4>{this->w, this->v[0], this->v[1], this->v[2]};
}
/// Rotate vector vr about this quaternion.
/// \brief Rotate Vector vr about this MakeQuaternion.
///
/// @param vr The vector to be rotated.
/// @return The rotated vector.
/// \param vr The vector to be rotated.
/// \return The rotated vector.
Vector<T, 3>
rotate(Vector<T, 3> vr) const
Rotate(Vector<T, 3> vr) const
{
return (this->conjugate() * vr * (*this)).axis();
return (this->Conjugate() * vr * (*this)).Axis();
}
/// Return the Euler angles for this quaternion as a vector of
/// <yaw, pitch, roll>. Users of this function should watch out
/// for gimbal lock.
/// \brief Return Euler angles for this MakeQuaternion.
///
/// @return A vector<T, 3> containing <yaw, pitch, roll>
/// Return the Euler angles for this MakeQuaternion as a vector of
/// <yaw, pitch, roll>.
///
/// \warn Users of this function should watch out for gimbal
/// lock.
///
/// \return A vector<T, 3> containing <yaw, pitch, roll>
Vector<T, 3>
euler() const
Euler() const
{
T yaw, pitch, roll;
T a = this->w, a2 = a * a;
@@ -257,10 +287,10 @@ public:
}
/// Perform quaternion addition with another quaternion.
/// \brief Quaternion addition.
///
/// @param other The quaternion to be added with this one.
/// @return The result of adding the two quaternions together.
/// \param other The MakeQuaternion to be added with this one.
/// \return The result of adding the two quaternions together.
Quaternion
operator+(const Quaternion<T> &other) const
{
@@ -268,10 +298,10 @@ public:
}
/// Perform quaternion subtraction with another quaternion.
/// \brief Quaternion subtraction.
///
/// @param other The quaternion to be subtracted from this one.
/// @return The result of subtracting the other quaternion from this one.
/// \param other The MakeQuaternion to be subtracted from this one.
/// \return The result of subtracting the other MakeQuaternion from this one.
Quaternion
operator-(const Quaternion<T> &other) const
{
@@ -279,10 +309,10 @@ public:
}
/// Perform scalar multiplication.
/// \brief Scalar multiplication.
///
/// @param k The scaling value.
/// @return A scaled quaternion.
/// \param k The scaling value.
/// \return A scaled MakeQuaternion.
Quaternion
operator*(const T k) const
{
@@ -290,10 +320,10 @@ public:
}
/// Perform scalar division.
/// \brief Scalar division.
///
/// @param k The scalar divisor.
/// @return A scaled quaternion.
/// \param k The scalar divisor.
/// \return A scaled MakeQuaternion.
Quaternion
operator/(const T k) const
{
@@ -301,23 +331,25 @@ public:
}
/// Perform quaternion Hamilton multiplication with a three-
/// dimensional vector; this is done by treating the vector
/// as a pure quaternion (e.g. with an angle of rotation of 0).
/// \brief Quaternion Hamilton multiplication with a three-
/// dimensional vector.
///
/// @param vector The vector to multiply with this quaternion.
/// @return The Hamilton product of the quaternion and vector.
/// This is done by treating the vector as a pure MakeQuaternion
/// (e.g. with an Angle of rotation of 0).
///
/// \param vector The vector to multiply with this MakeQuaternion.
/// \return The Hamilton product of the MakeQuaternion and vector.
Quaternion
operator*(const Vector<T, 3> &vector) const
{
return Quaternion(vector * this->w + this->v.cross(vector),
return Quaternion(vector * this->w + this->v.Cross(vector),
(T) 0.0);
}
/// Perform quaternion Hamilton multiplication.
/// \brief Quaternion Hamilton multiplication.
///
/// @param other The other quaternion to multiply with this one.
/// \param other The other MakeQuaternion to multiply with this one.
/// @result The Hamilton product of the two quaternions.
Quaternion
operator*(const Quaternion<T> &other) const
@@ -326,14 +358,15 @@ public:
(this->v * other.v);
Vector<T, 3> axis = (other.v * this->w) +
(this->v * other.w) +
(this->v.cross(other.v));
(this->v.Cross(other.v));
return Quaternion(axis, angle);
}
/// Perform quaternion equality checking.
/// @param other The quaternion to check equality against.
/// @return True if the two quaternions are equal within their tolerance.
/// \brief Quaternion equivalence.
///
/// \param other The MakeQuaternion to check equality against.
/// \return True if the two quaternions are equal within their tolerance.
bool
operator==(const Quaternion<T> &other) const
{
@@ -342,10 +375,10 @@ public:
}
/// Perform quaternion inequality checking.
/// \brief Quaternion non-equivalence.
///
/// @param other The quaternion to check inequality against.
/// @return True if the two quaternions are unequal within their tolerance.
/// \param other The MakeQuaternion to check inequality against.
/// \return True if the two quaternions are unequal within their tolerance.
bool
operator!=(const Quaternion<T> &other) const
{
@@ -353,12 +386,14 @@ public:
}
/// Support stream output of a quaternion in the form `a + <i, j, k>`.
/// \brief Output a MakeQuaternion to a stream in the form
/// `a + <i, j, k>`.
///
/// \todo improve the formatting.
///
/// @param outs An output stream
/// @param q A quaternion
/// @return The output stream
/// \param outs An output stream
/// \param q A MakeQuaternion
/// \return The output stream
friend std::ostream &
operator<<(std::ostream &outs, const Quaternion<T> &q)
{
@@ -370,8 +405,8 @@ private:
static constexpr T minRotation = -4 * M_PI;
static constexpr T maxRotation = 4 * M_PI;
Vector<T, 3> v; // axis of rotation
T w; // angle of rotation
Vector<T, 3> v; // Axis of rotation
T w; // Angle of rotation
T eps;
void
@@ -393,76 +428,93 @@ private:
///
/// \ingroup quaternion_aliases
/// Type alias for a float Quaternion.
/// \brief Type alias for a float Quaternion.
typedef Quaternion<float> Quaternionf;
/// \ingroup quaternion_aliases
/// Type alias for a double Quaternion.
/// \brief Type alias for a double Quaternion.
typedef Quaternion<double> Quaterniond;
/// Return a float quaternion scaled appropriately from a vector and angle,
/// e.g. angle = cos(angle / 2), axis.unitVector() * sin(angle / 2).
/// \brief Convenience Quaternion construction function.
///
/// @param axis The axis of rotation.
/// @param angle The angle of rotation.
/// @return A quaternion.
/// @relatesalso Quaternion
Quaternionf quaternionf(Vector3f axis, float angle);
/// Return a double quaternion scaled appropriately from a vector and angle,
/// e.g. angle = cos(angle / 2), axis.unitVector() * sin(angle / 2).
/// Return a float MakeQuaternion scaled appropriately from a vector and
/// Angle, e.g.
/// angle = cos(Angle / 2),
/// Axis.UnitVector() * sin(Angle / 2).
///
/// @param axis The axis of rotation.
/// @param angle The angle of rotation.
/// @return A quaternion.
/// @relatesalso Quaternion
Quaterniond quaterniond(Vector3d axis, double angle);
/// \param axis The Axis of rotation.
/// \param angle The Angle of rotation.
/// \return A MakeQuaternion.
/// \relatesalso Quaternion
Quaternionf MakeQuaternion(Vector3F axis, float angle);
/// Return a double quaternion scaled appropriately from a vector and angle,
/// e.g. angle = cos(angle / 2), axis.unitVector() * sin(angle / 2).
/// \brief Convience Quaternion construction function.
///
/// @param axis The axis of rotation.
/// @param angle The angle of rotation.
/// @return A quaternion.
/// @relatesalso Quaternion
/// Return a double MakeQuaternion scaled appropriately from a vector and
/// Angle, e.g.
/// Angle = cos(Angle / 2),
/// Axis.UnitVector() * sin(Angle / 2).
///
/// \param axis The Axis of rotation.
/// \param angle The Angle of rotation.
/// \return A MakeQuaternion.
/// \relatesalso Quaternion
Quaterniond MakeQuaternion(Vector3D axis, double angle);
/// \brief Convience Quaternion construction function.
///
/// Return a double MakeQuaternion scaled appropriately from a vector and
/// Angle, e.g.
/// Angle = cos(Angle / 2),
/// Axis.UnitVector() * sin(Angle / 2).
///
/// \param axis The Axis of rotation.
/// \param angle The Angle of rotation.
/// \return A MakeQuaternion.
/// \relatesalso Quaternion
template <typename T>
Quaternion<T>
quaternion(Vector<T, 3> axis, T angle)
MakeQuaternion(Vector<T, 3> axis, T angle)
{
return Quaternion<T>(axis.unitVector() * std::sin(angle / (T)2.0),
return Quaternion<T>(axis.UnitVector() * std::sin(angle / (T)2.0),
std::cos(angle / (T)2.0));
}
/// Given a vector of Euler angles in ZYX sequence (e.g. yaw, pitch, roll),
/// return a quaternion.
/// \brief COnstruct a Quaternion from Euler angles.
///
/// @param euler A vector Euler angle in ZYX sequence.
/// @return A Quaternion representation of the Orientation represented
/// by the Euler angles.
/// @relatesalso Quaternion
Quaternionf quaternionf_from_euler(Vector3f euler);
/// Given a vector of Euler angles in ZYX sequence (e.g. yaw, pitch, roll),
/// return a quaternion.
/// Given a vector of Euler angles in ZYX sequence (e.g. yaw, pitch,
/// roll), return a Quaternion.
///
/// @param euler A vector Euler angle in ZYX sequence.
/// @return A Quaternion representation of the Orientation represented
/// \param euler A vector Euler Angle in ZYX sequence.
/// \return A Quaternion representation of the Orientation represented
/// by the Euler angles.
/// @relatesalso Quaternion
Quaterniond quaterniond_from_euler(Vector3d euler);
/// \relatesalso Quaternion
Quaternionf QuaternionFromEuler(Vector3F euler);
/// LERP computes the linear interpolation of two quaternions at some
/// \brief COnstruct a Quaternion from Euler angles.
///
/// Given a vector of Euler angles in ZYX sequence (e.g. yaw, pitch,
/// roll), return a Quaternion.
///
/// \param euler A vector Euler Angle in ZYX sequence.
/// \return A Quaternion representation of the Orientation represented
/// by the Euler angles.
/// \relatesalso Quaternion
Quaterniond QuaternionFromEuler(Vector3D euler);
/// \brief Linear interpolation for two Quaternions.
///
/// LERP computes the linear interpolation of two quaternions At some
/// fraction of the distance between them.
///
/// \tparam T
/// \param p The starting quaternion.
/// \param q The ending quaternion.
/// \param p The starting MakeQuaternion.
/// \param q The ending MakeQuaternion.
/// \param t The fraction of the distance between the two quaternions to
/// interpolate.
/// \return A Quaternion representing the linear interpolation of the
@@ -471,17 +523,19 @@ template <typename T>
Quaternion<T>
LERP(Quaternion<T> p, Quaternion<T> q, T t)
{
return (p + (q - p) * t).unitQuaternion();
return (p + (q - p) * t).UnitQuaternion();
}
/// \brief Shortest distance spherical linear interpolation.
///
/// ShortestSLERP computes the shortest distance spherical linear
/// interpolation between two quaternions at some fraction of the
/// interpolation between two unit quaternions At some fraction of the
/// distance between them.
///
/// \tparam T
/// \param p The starting quaternion.
/// \param q The ending quaternion.Short
/// \param p The starting MakeQuaternion.
/// \param q The ending MakeQuaternion.Short
/// \param t The fraction of the distance between the two quaternions
/// to interpolate.
/// \return A Quaternion representing the shortest path between two
@@ -490,10 +544,10 @@ template <typename T>
Quaternion<T>
ShortestSLERP(Quaternion<T> p, Quaternion<T> q, T t)
{
assert(p.isUnitQuaternion());
assert(q.isUnitQuaternion());
assert(p.IsUnitQuaternion());
assert(q.IsUnitQuaternion());
T dp = p.dot(q);
T dp = p.Dot(q);
T sign = dp < 0.0 ? -1.0 : 1.0;
T omega = std::acos(dp * sign);
T sin_omega = std::sin(omega); // Compute once.
@@ -507,14 +561,16 @@ ShortestSLERP(Quaternion<T> p, Quaternion<T> q, T t)
}
/// \brief Internal consistency check.
///
/// Run a quick self test to exercise basic functionality of the Quaternion
/// class to verify correct operation. Note that if \#NDEBUG is defined, the
/// self test is disabled.
void Quaternion_SelfTest();
void QuaternionSelfTest();
} // namespace geom
} // namespace wr
#endif // WRMATH_QUATERNION_H
#endif // SCMATH_GEOM_QUATERNION_H

View File

@@ -1,28 +1,27 @@
//
// Project: scccl
// File: include/math/vectors.h
// Author: Kyle Isom
// Date: 2017-06-05
// Namespace: math::vectors.
//
// vectors.h defines the Vector2D class and associated functions in the
// namespace scmp::vectors.
//
// Copyright 2017 Kyle Isom <kyle@imap.cc>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SCMATH_VECTORS_H
#define SCMATH_VECTORS_H
///
/// \file include/scmp/geom/Vector.h
/// \author K. Isom <kyle@imap.cc>
/// \date 2017-06-05
/// \brief Linear algebraic vector class.
///
/// 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.
///
#ifndef SCMATH_GEOM_VECTORS_H
#define SCMATH_GEOM_VECTORS_H
#include <array>
@@ -44,21 +43,20 @@ namespace scmp {
namespace geom {
/// @brief Vectors represent a direction and magnitude.
/// \brief Vectors represent a direction and Magnitude.
///
/// Vector provides a standard interface for dimensionless fixed-size
/// vectors. Once instantiated, they cannot be modified.
///
/// Note that while the class is templated, it's intended to be used with
/// floating-point types.
/// Note that while the class is templated, it's intended to be used
/// with floating-point types.
///
/// Vectors can be indexed like arrays, and they contain an epsilon value
/// that defines a tolerance for equality.
/// Vectors can be indexed like arrays, and they contain an epsilon
/// value that defines a tolerance for equality.
template<typename T, size_t N>
class Vector {
public:
/// The default constructor creates a unit vector for a given type
/// and size.
/// \brief Construct a unit vector of a given type and size.
Vector()
{
T unitLength = (T) 1.0 / std::sqrt(N);
@@ -70,9 +68,12 @@ public:
}
/// \brief Construct a Vector with initial values.
///
/// If given an initializer_list, the vector is created with
/// those values. There must be exactly N elements in the list.
/// @param ilst An intializer list with N elements of type T.
///
/// \param ilst An intializer list with N elements of type T.
Vector(std::initializer_list<T> ilst)
{
assert(ilst.size() == N);
@@ -82,13 +83,13 @@ public:
}
/// \brief Return the element at index i.
/// \brief Return the element At index i.
///
/// \throws std::out_of_range if the index is out of bounds.
///
/// \param index The index of the item to retrieve.
/// \return The value at the index.
T at(size_t index) const
/// \return The value At the index.
T At(size_t index) const
{
if (index > this->arr.size()) {
throw std::out_of_range("index " +
@@ -105,7 +106,7 @@ public:
///
/// \throws std::out_of_range if the index is out of bounds.
///
/// \param index The index to insert the value at.
/// \param index The index to insert the value At.
/// \param value
void Set(size_t index, T value)
{
@@ -122,9 +123,10 @@ public:
/// Compute the length of the vector.
/// @return The length of the vector.
T magnitude() const
/// \brief Compute the length of the vector.
///
/// \return The length of the vector.
T Magnitude() const
{
T result = 0;
@@ -135,21 +137,25 @@ public:
}
/// Set the tolerance for equality checks. At a minimum, this allows
/// for systemic errors in floating math arithmetic.
/// @param eps is the maximum difference between this vector and
/// \brief Set equivalence tolerance.
///
/// Set the tolerance for equality checks. At a minimum, this
/// accounts for systemic errors in floating math arithmetic.
///
/// \param eps is the maximum difference between this vector and
/// another.
void
setEpsilon(T eps)
SetEpsilon(T eps)
{
this->epsilon = eps;
}
/// Determine whether this is a zero vector.
/// @return true if the vector is zero.
/// \brief Determine whether this is a zero vector.
///
/// \return true if the vector is zero.
bool
isZero() const
IsZero() const
{
for (size_t i = 0; i < N; i++) {
if (!scmp::WithinTolerance(this->arr[i], (T) 0.0, this->epsilon)) {
@@ -160,51 +166,55 @@ public:
}
/// Obtain the unit vector for this vector.
/// @return The unit vector
/// \brief Obtain the unit vector for this vector.
///
/// \return The unit vector
Vector
unitVector() const
UnitVector() const
{
return *this / this->magnitude();
return *this / this->Magnitude();
}
/// Determine if this is a unit vector, e.g. if its length is 1.
/// @return true if the vector is a unit vector.
/// \brief Determine if this is a unit vector.
///
/// \return true if the vector is a unit vector.
bool
isUnitVector() const
IsUnitVector() const
{
return scmp::WithinTolerance(this->magnitude(), (T) 1.0, this->epsilon);
return scmp::WithinTolerance(this->Magnitude(), (T) 1.0, this->epsilon);
}
/// Compute the angle between two other vectors.
/// @param other Another vector.
/// @return The angle in radians between the two vectors.
/// \brief Compute the Angle between two vectors.
///
/// \param other Another vector.
/// \return The Angle in radians between the two vectors.
T
angle(const Vector<T, N> &other) const
Angle(const Vector<T, N> &other) const
{
Vector<T, N> unitA = this->unitVector();
Vector<T, N> unitB = other.unitVector();
Vector<T, N> unitA = this->UnitVector();
Vector<T, N> unitB = other.UnitVector();
// Can't compute angles with a zero vector.
assert(!this->isZero());
assert(!other.isZero());
return std::acos(unitA * unitB);
assert(!this->IsZero());
assert(!other.IsZero());
return static_cast<T>(std::acos(unitA * unitB));
}
/// Determine whether two vectors are parallel.
/// @param other Another vector
/// @return True if the angle between the vectors is zero.
/// \brief Determine whether two vectors are parallel.
///
/// \param other Another vector
/// \return True if the Angle between the vectors is zero.
bool
isParallel(const Vector<T, N> &other) const
IsParallel(const Vector<T, N> &other) const
{
if (this->isZero() || other.isZero()) {
if (this->IsZero() || other.IsZero()) {
return true;
}
T angle = this->angle(other);
T angle = this->Angle(other);
if (scmp::WithinTolerance(angle, (T) 0.0, this->epsilon)) {
return true;
}
@@ -213,14 +223,15 @@ public:
}
/// Determine if two vectors are orthogonal or perpendicular to each
/// other.
/// @param other Another vector
/// @return True if the two vectors are orthogonal.
/// \brief Determine if two vectors are orthogonal or
/// perpendicular to each other.
///
/// \param other Another vector
/// \return True if the two vectors are orthogonal.
bool
isOrthogonal(const Vector<T, N> &other) const
IsOrthogonal(const Vector<T, N> &other) const
{
if (this->isZero() || other.isZero()) {
if (this->IsZero() || other.IsZero()) {
return true;
}
@@ -228,40 +239,51 @@ public:
}
/// Project this vector onto some basis vector.
/// @param basis The basis vector to be projected onto.
/// @return A vector that is the projection of this onto the basis
/// \brief Project this vector onto some basis vector.
///
/// \param basis The basis vector to be projected onto.
/// \return A vector that is the projection of this onto the basis
/// vector.
Vector
projectParallel(const Vector<T, N> &basis) const
ProjectParallel(const Vector<T, N> &basis) const
{
Vector<T, N> unit_basis = basis.unitVector();
Vector<T, N> unit_basis = basis.UnitVector();
return unit_basis * (*this * unit_basis);
}
/// Project this vector perpendicularly onto some basis vector.
/// This is also called the rejection of the vector.
/// @param basis The basis vector to be projected onto.
/// @return A vector that is the orthogonal projection of this onto
/// \brief Project this vector perpendicularly onto some basis vector.
///
/// This is also called the *rejection* of the vector.
///
/// \param basis The basis vector to be projected onto.
/// \return A vector that is the orthogonal projection of this onto
/// the basis vector.
Vector
projectOrthogonal(const Vector<T, N> &basis)
ProjectOrthogonal(const Vector<T, N> &basis)
{
Vector<T, N> spar = this->projectParallel(basis);
Vector<T, N> spar = this->ProjectParallel(basis);
return *this - spar;
}
/// Compute the cross product of two vectors. This is only defined
/// over three-dimensional vectors.
/// @param other Another 3D vector.
/// @return The cross product vector.
/// \brief Compute the cross product of two vectors.
///
/// This is only defined over three-dimensional vectors.
///
/// \throw std::out_of_range if this is not a three-dimensional vector.
///
/// \param other Another 3D vector.
/// \return The Cross product vector.
Vector
cross(const Vector<T, N> &other) const
Cross(const Vector<T, N> &other) const
{
assert(N == 3);
if (N != 3) {
throw std::out_of_range("Cross-product can only called on Vector<T, 3>.");
}
return Vector<T, N>{
(this->arr[1] * other.arr[2]) - (other.arr[1] * this->arr[2]),
-((this->arr[0] * other.arr[2]) - (other.arr[0] * this->arr[2])),
@@ -270,9 +292,10 @@ public:
}
/// Perform vector addition with another vector.
/// @param other The vector to be added.
/// @return A new vector that is the result of adding this and the
/// \brief Vector addition.
///
/// \param other The vector to be added.
/// \return A new vector that is the result of adding this and the
/// other vector.
Vector
operator+(const Vector<T, N> &other) const
@@ -287,9 +310,10 @@ public:
}
/// Perform vector subtraction with another vector.
/// @param other The vector to be subtracted from this vector.
/// @return A new vector that is the result of subtracting the
/// \brief Vector subtraction.
///
/// \param other The vector to be subtracted from this vector.
/// \return A new vector that is the result of subtracting the
/// other vector from this one.
Vector
operator-(const Vector<T, N> &other) const
@@ -304,9 +328,10 @@ public:
}
/// Perform scalar multiplication of this vector by some scale factor.
/// @param k The scaling value.
/// @return A new vector that is this vector scaled by k.
/// \brief Scalar multiplication.
///
/// \param k The scaling value.
/// \return A new vector that is this vector scaled by k.
Vector
operator*(const T k) const
{
@@ -320,9 +345,10 @@ public:
}
/// Perform scalar division of this vector by some scale factor.
/// @param k The scaling value
/// @return A new vector that is this vector scaled by 1/k.
/// \brief Scalar division.
///
/// \param k The scaling value
/// \return A new vector that is this vector scaled by 1/k.
Vector
operator/(const T k) const
{
@@ -336,9 +362,10 @@ public:
}
/// Compute the dot product between two vectors.
/// @param other The other vector.
/// @return A scalar value that is the dot product of the two vectors.
/// \brief Compute the Dot product between two vectors.
///
/// \param other The other vector.
/// \return A scalar value that is the Dot product of the two vectors.
T
operator*(const Vector<T, N> &other) const
{
@@ -352,9 +379,10 @@ public:
}
/// Compare two vectors for equality.
/// @param other The other vector.
/// @return Return true if all the components of both vectors are
/// \brief Vector equivalence
///
/// \param other The other vector.
/// \return Return true if all the components of both vectors are
/// within the tolerance value.
bool
operator==(const Vector<T, N> &other) const
@@ -368,9 +396,10 @@ public:
}
/// Compare two vectors for inequality.
/// @param other The other vector.
/// @return Return true if any of the components of both vectors are
/// \brief Vector non-equivalence.
///
/// \param other The other vector.
/// \return Return true if any of the components of both vectors are
/// not within the tolerance value.
bool
operator!=(const Vector<T, N> &other) const
@@ -379,18 +408,18 @@ public:
}
/// Support array indexing into vector.
/// \brief Array indexing into vector.
///
/// Note that the values of the vector cannot be modified. Instead,
/// it's required to do something like the following:
/// Note that the values of the vector cannot be modified.
/// Instead, something like the following must be done:
///
/// ```
/// Vector3d a {1.0, 2.0, 3.0};
/// Vector3d b {a[0], a[1]*2.0, a[2]};
/// Vector3D a {1.0, 2.0, 3.0};
/// Vector3D b {a[0], a[1]*2.0, a[2]};
/// ```
///
/// @param i The component index.
/// @return The value of the vector component at i.
/// \param i The component index.
/// \return The value of the vector component At i.
const T &
operator[](size_t i) const
{
@@ -398,10 +427,11 @@ public:
}
/// Support outputting vectors in the form "<i, j, ...>".
/// @param outs An output stream.
/// @param vec The vector to be formatted.
/// @return The output stream.
/// \brief Write a vector a stream in the form "<i, j, ...>".
///
/// \param outs An output stream.
/// \param vec The vector to be formatted.
/// \return The output stream.
friend std::ostream &
operator<<(std::ostream &outs, const Vector<T, N> &vec)
{
@@ -429,36 +459,35 @@ private:
/// \ingroup vector_aliases
/// A number of shorthand aliases for vectors are provided. They follow
/// the form of VectorNt, where N is the dimension and t is the type.
/// For example, a 2D float vector is Vector2f.
/// For example, a 2D float vector is Vector2F.
/// \ingroup vector_aliases
/// @brief Type alias for a two-dimensional float vector.
typedef Vector<float, 2> Vector2f;
/// \brief Type alias for a two-dimensional float vector.
typedef Vector<float, 2> Vector2F;
/// \ingroup vector_aliases
/// @brief Type alias for a three-dimensional float vector.
typedef Vector<float, 3> Vector3f;
/// \brief Type alias for a three-dimensional float vector.
typedef Vector<float, 3> Vector3F;
/// \ingroup vector_aliases
/// @brief Type alias for a four-dimensional float vector.
typedef Vector<float, 4> Vector4f;
/// \brief Type alias for a four-dimensional float vector.
typedef Vector<float, 4> Vector4F;
/// \ingroup vector_aliases
/// @brief Type alias for a two-dimensional double vector.
typedef Vector<double, 2> Vector2d;
/// \brief Type alias for a two-dimensional double vector.
typedef Vector<double, 2> Vector2D;
/// \ingroup vector_aliases
/// @brief Type alias for a three-dimensional double vector.
typedef Vector<double, 3> Vector3d;
/// \brief Type alias for a three-dimensional double vector.
typedef Vector<double, 3> Vector3D;
/// \ingroup vector_aliases
/// @brief Type alias for a four-dimensional double vector.
typedef Vector<double, 4> Vector4d;
/// \brief Type alias for a four-dimensional double vector.
typedef Vector<double, 4> Vector4D;
} // namespace geom
} // namespace scmp
#endif // SCMATH_VECTORS_H_H
#endif // SCMATH_GEOM_VECTORS_H

View File

@@ -70,7 +70,7 @@ enum class ArenaType
/// The arena should be initialized with one of the Set methods (SetStatic,
/// SetAlloc) or one of the file-based options (Create, Open, MemoryMap). At
/// this point, no further memory management should be done until the end of the
/// arena's life, at which point Destroy should be called.
/// arena's life, At which point Destroy should be called.
class Arena {
public:
/// An Arena is initialized with no backing memory.

View File

@@ -102,37 +102,37 @@ public:
/// \return True if the Buffer was resized.
bool Append(const uint8_t c);
/// Insert copies a C-style string into the buffer at index.
/// Insert copies a C-style string into the buffer At index.
///
/// \param index The index to insert the string at.
/// \param index The index to insert the string At.
/// \param s The string to insert.
/// \return True if the Buffer was resized.
bool Insert(const size_t index, const char *s);
/// Insert copies a string into the buffer at index.
/// Insert copies a string into the buffer At index.
///
/// \param index The index the string should be inserted at.
/// \param index The index the string should be inserted At.
/// \param s The string to insert.
/// \return True if the Buffer was resized.
bool Insert(const size_t index, const std::string s);
/// Insert copies a uint8_t buffer into the buffer at index.
/// Insert copies a uint8_t buffer into the buffer At index.
///
/// \param index The index to insert the buffer at.
/// \param index The index to insert the buffer At.
/// \param data The buffer to insert.
/// \param datalen The size of the data buffer.
/// \return True if the Buffer was resized.
bool
Insert(const size_t index, const uint8_t *data, const size_t datalen);
/// Insert copies a character into the buffer at index.
/// Insert copies a character into the buffer At index.
///
/// \param index The index to insert the character at.
/// \param index The index to insert the character At.
/// \param c The character to insert.
/// \return True if the Buffer was resized.
bool Insert(const size_t index, const uint8_t c);
/// Remove removes `count` bytes from the buffer at `index`.
/// Remove removes `count` bytes from the buffer At `index`.
///
/// \param index The starting index to remove bytes from.
/// \param count The number of bytes to remove.

View File

@@ -282,7 +282,7 @@ public:
/// Return a particular argument.
///
/// \param index The argument number to extract.
/// \return The argument at index i. If the index is greater than
/// \return The argument At index i. If the index is greater than
/// the number of arguments present, an out_of_range
/// exception is thrown.
std::string Arg(size_t index);

View File

@@ -39,27 +39,27 @@ namespace U {
namespace S {
/// Remove any whitespace at the beginning of the string. The string
/// Remove any whitespace At the beginning of the string. The string
/// is modified in-place.
void TrimLeadingWhitespace(std::string &s);
/// Remove any whitespace at the end of the string. The string is
/// Remove any whitespace At the end of the string. The string is
/// modified in-place.
void TrimTrailingWhitespace(std::string &s);
/// Remove any whitespace at the beginning and end of the string. The
/// Remove any whitespace At the beginning and end of the string. The
/// string is modified in-place.
void TrimWhitespace(std::string &s);
/// Remove any whitespace at the beginning of the string. The original
/// Remove any whitespace At the beginning of the string. The original
/// string isn't modified, and a copy is returned.
std::string TrimLeadingWhitespaceDup(std::string s);
/// Remove any whitespace at the end of the string. The original string
/// Remove any whitespace At the end of the string. The original string
/// isn't modified, and a copy is returned.
std::string TrimTrailingWhitespaceDup(std::string s);
/// Remove any whitespace at the beginning and end of the string. The
/// Remove any whitespace At the beginning and end of the string. The
/// original string isn't modified, and a copy is returned.
std::string TrimWhitespaceDup(std::string s);
@@ -92,7 +92,7 @@ std::vector<std::string> SplitKeyValuePair(std::string line, char delimiter);
std::vector<std::string> SplitN(std::string, std::string delimiter, size_t maxCount=0);
/// WrapText is a very simple wrapping function that breaks the line into
/// lines of at most lineLength characters. It does this by breaking the
/// lines of At most lineLength characters. It does this by breaking the
/// line into individual words (splitting on whitespace).
std::vector<std::string> WrapText(std::string& line, size_t lineLength);

View File

@@ -46,7 +46,7 @@ struct Record {
uint8_t Val[TLV_MAX_LEN];
};
/// WriteToMemory writes the TLV record into the arena at the location pointed
/// WriteToMemory writes the TLV record into the arena At the location pointed
/// to in the arena.
///
/// \param arena The backing memory store.
@@ -86,7 +86,7 @@ void DeleteRecord(Arena &arena, uint8_t *cursor);
///
/// \param arena The backing memory for the TLV store.
/// \param cursor A pointer to memory inside the arena; if it's NULL, the
/// search starts at the beginning of the arena.
/// search starts At the beginning of the arena.
/// \param rec The record to be filled.
/// \return If the tag is found, a cursor pointing to the next record is
/// returned; otherwise nullptr is returned.
@@ -97,7 +97,7 @@ uint8_t *FindTag(Arena &arena, uint8_t *cursor, Record &rec);
///
/// \param arena The backing memory for the TLV store.
/// \param cursor A pointer to memory inside the arena; if it's NULL, the
/// search starts at the beginning of the arena.
/// search starts At the beginning of the arena.
/// \param rec The record to be filled.
/// \return If the tag is found, a cursor pointing to the record is
/// returned; otherwise nullptr is returned.
@@ -110,7 +110,7 @@ uint8_t *LocateTag(Arena &arena, uint8_t *cursor, Record &rec);
///
/// \param arena The backing memory for the TLV store.
/// \param cursor A pointer to memory inside the arena; if it's NULL, the
/// search starts at the beginning of the arena.
/// search starts At the beginning of the arena.
/// \return If the arena has space available, a cursor pointing the start
/// of empty space; otherwise, nullptr is returned.
uint8_t *FindEmpty(Arena &arena, uint8_t *cursor);

View File

@@ -12,7 +12,7 @@
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// You may obtain a copy of the License At
//
// http://www.apache.org/licenses/LICENSE-2.0
//

View File

@@ -59,14 +59,14 @@ public:
/// \brief Define a suite setup function.
///
/// If present, this setup function is called at the start of
/// If present, this setup function is called At the start of
/// the Run method, before tests are run. It should be a
/// predicate: if it returns false, tests automatically fail.
void Setup(std::function<bool(void)> setupFn) { fnSetup = setupFn; }
/// \brief Define a teardown function.
///
/// If present, this teardown function is called at the end of
/// If present, this teardown function is called At the end of
/// the Run method, after all tests have run.
void Teardown(std::function<bool(void)> teardownFn) { fnTeardown = teardownFn; }