Removed default Angle type
This commit is contained in:
parent
58beb363ea
commit
64b7f1103b
2
Angle.h
2
Angle.h
@ -214,7 +214,7 @@ private:
|
||||
AngleOf<T>(T value);
|
||||
};
|
||||
|
||||
using Angle = AngleOf<float>;
|
||||
// using Angle = AngleOf<float>;
|
||||
using AngleSingle = AngleOf<float>;
|
||||
using Angle16 = AngleOf<signed short>;
|
||||
using Angle8 = AngleOf<signed char>;
|
||||
|
@ -2,8 +2,8 @@ warning: source 'images' is not a readable file or directory... skipping.
|
||||
d:/PlatformIO/linear-algebra/Quaternion.cpp:100: warning: no uniquely matching class member found for
|
||||
Quaternion Quaternion::operator*(const Quaternion &r2) const
|
||||
Possible candidates:
|
||||
'friend AngleOf< T > Passer::LinearAlgebra::AngleOf< T >::operator*(const AngleOf< T > &a, float f)' at line 48 of file d:/PlatformIO/linear-algebra/Angle.h
|
||||
'friend AngleOf< T > Passer::LinearAlgebra::AngleOf< T >::operator*(float f, const AngleOf< T > &a)' at line 51 of file d:/PlatformIO/linear-algebra/Angle.h
|
||||
'friend AngleOf< T > Passer::LinearAlgebra::AngleOf< T >::operator*(const AngleOf< T > &angle, float factor)' at line 120 of file d:/PlatformIO/linear-algebra/Angle.h
|
||||
'friend AngleOf< T > Passer::LinearAlgebra::AngleOf< T >::operator*(float factor, const AngleOf< T > &angle)' at line 127 of file d:/PlatformIO/linear-algebra/Angle.h
|
||||
'Vector3 Passer::LinearAlgebra::MatrixOf< T >::operator*(const Vector3 v) const' at line 64 of file d:/PlatformIO/linear-algebra/Matrix.h
|
||||
'friend PolarOf Passer::LinearAlgebra::PolarOf< T >::operator*(const PolarOf &v, float f)' at line 100 of file d:/PlatformIO/linear-algebra/Polar.h
|
||||
'friend PolarOf Passer::LinearAlgebra::PolarOf< T >::operator*(float f, const PolarOf &v)' at line 103 of file d:/PlatformIO/linear-algebra/Polar.h
|
||||
@ -20,8 +20,8 @@ Possible candidates:
|
||||
d:/PlatformIO/linear-algebra/Quaternion.cpp:108: warning: no uniquely matching class member found for
|
||||
Vector3 Quaternion::operator*(const Vector3 &p) const
|
||||
Possible candidates:
|
||||
'friend AngleOf< T > Passer::LinearAlgebra::AngleOf< T >::operator*(const AngleOf< T > &a, float f)' at line 48 of file d:/PlatformIO/linear-algebra/Angle.h
|
||||
'friend AngleOf< T > Passer::LinearAlgebra::AngleOf< T >::operator*(float f, const AngleOf< T > &a)' at line 51 of file d:/PlatformIO/linear-algebra/Angle.h
|
||||
'friend AngleOf< T > Passer::LinearAlgebra::AngleOf< T >::operator*(const AngleOf< T > &angle, float factor)' at line 120 of file d:/PlatformIO/linear-algebra/Angle.h
|
||||
'friend AngleOf< T > Passer::LinearAlgebra::AngleOf< T >::operator*(float factor, const AngleOf< T > &angle)' at line 127 of file d:/PlatformIO/linear-algebra/Angle.h
|
||||
'Vector3 Passer::LinearAlgebra::MatrixOf< T >::operator*(const Vector3 v) const' at line 64 of file d:/PlatformIO/linear-algebra/Matrix.h
|
||||
'friend PolarOf Passer::LinearAlgebra::PolarOf< T >::operator*(const PolarOf &v, float f)' at line 100 of file d:/PlatformIO/linear-algebra/Polar.h
|
||||
'friend PolarOf Passer::LinearAlgebra::PolarOf< T >::operator*(float f, const PolarOf &v)' at line 103 of file d:/PlatformIO/linear-algebra/Polar.h
|
||||
@ -54,8 +54,8 @@ d:/PlatformIO/linear-algebra/Spherical.cpp:137: warning: no uniquely matching cl
|
||||
template < T >
|
||||
SphericalOf< T > SphericalOf::operator-(const SphericalOf< T > &s2) const
|
||||
Possible candidates:
|
||||
'AngleOf< T > Passer::LinearAlgebra::AngleOf< T >::operator-() const' at line 43 of file d:/PlatformIO/linear-algebra/Angle.h
|
||||
'AngleOf< T > Passer::LinearAlgebra::AngleOf< T >::operator-(const AngleOf< T > &a) const' at line 44 of file d:/PlatformIO/linear-algebra/Angle.h
|
||||
'AngleOf< T > Passer::LinearAlgebra::AngleOf< T >::operator-() const' at line 102 of file d:/PlatformIO/linear-algebra/Angle.h
|
||||
'AngleOf< T > Passer::LinearAlgebra::AngleOf< T >::operator-(const AngleOf< T > &angle) const' at line 106 of file d:/PlatformIO/linear-algebra/Angle.h
|
||||
'DirectionOf< T > Passer::LinearAlgebra::DirectionOf< T >::operator-() const' at line 41 of file d:/PlatformIO/linear-algebra/Direction.h
|
||||
'PolarOf Passer::LinearAlgebra::PolarOf< T >::operator-() const' at line 82 of file d:/PlatformIO/linear-algebra/Polar.h
|
||||
'PolarOf Passer::LinearAlgebra::PolarOf< T >::operator-(const PolarOf &v) const' at line 87 of file d:/PlatformIO/linear-algebra/Polar.h
|
||||
@ -118,3 +118,5 @@ d:/PlatformIO/linear-algebra/Vector3.h:158: warning: Member operator*=(float f)
|
||||
d:/PlatformIO/linear-algebra/Vector3.h:170: warning: Member operator/=(float f) (function) of struct Passer::LinearAlgebra::Vector3 is not documented.
|
||||
d:/PlatformIO/linear-algebra/Vector3.h:154: warning: Member operator*(float f, const Vector3 &v) (friend) of struct Passer::LinearAlgebra::Vector3 is not documented.
|
||||
d:/PlatformIO/linear-algebra/Vector3.h:166: warning: Member operator/(float f, const Vector3 &v) (friend) of struct Passer::LinearAlgebra::Vector3 is not documented.
|
||||
t f, const Vector3 &v) (friend) of struct Passer::LinearAlgebra::Vector3 is not documented.
|
||||
d:/PlatformIO/linear-algebra/Vector3.h:166: warning: Member operator/(float f, const Vector3 &v) (friend) of struct Passer::LinearAlgebra::Vector3 is not documented.
|
||||
|
49
Polar.cpp
49
Polar.cpp
@ -2,13 +2,11 @@
|
||||
|
||||
#include "Polar.h"
|
||||
|
||||
template <typename T>
|
||||
PolarOf<T>::PolarOf() {
|
||||
template <typename T> PolarOf<T>::PolarOf() {
|
||||
this->distance = 0.0f;
|
||||
this->angle = AngleOf<T>();
|
||||
}
|
||||
template <typename T>
|
||||
PolarOf<T>::PolarOf(float distance, AngleOf<T> angle) {
|
||||
template <typename T> PolarOf<T>::PolarOf(float distance, AngleOf<T> angle) {
|
||||
// distance should always be 0 or greater
|
||||
if (distance < 0.0f) {
|
||||
this->distance = -distance;
|
||||
@ -23,16 +21,14 @@ PolarOf<T>::PolarOf(float distance, AngleOf<T> angle) {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PolarOf<T> PolarOf<T>::FromVector2(Vector2 v) {
|
||||
template <typename T> PolarOf<T> PolarOf<T>::FromVector2(Vector2 v) {
|
||||
float distance = v.magnitude();
|
||||
AngleOf<T> angle =
|
||||
AngleOf<T>::Degrees(Vector2::SignedAngle(Vector2::forward, v));
|
||||
PolarOf<T> p = PolarOf(distance, angle);
|
||||
return p;
|
||||
}
|
||||
template <typename T>
|
||||
PolarOf<T> PolarOf<T>::FromSpherical(SphericalOf<T> v) {
|
||||
template <typename T> PolarOf<T> PolarOf<T>::FromSpherical(SphericalOf<T> v) {
|
||||
float distance = v.distance * cosf(v.direction.vertical.InDegrees() *
|
||||
Passer::LinearAlgebra::Deg2Rad);
|
||||
AngleOf<T> angle = v.direction.horizontal;
|
||||
@ -51,43 +47,36 @@ const PolarOf<T> PolarOf<T>::right = PolarOf(1.0, AngleOf<T>::Degrees(90));
|
||||
template <typename T>
|
||||
const PolarOf<T> PolarOf<T>::left = PolarOf(1.0, AngleOf<T>::Degrees(-90));
|
||||
|
||||
template <typename T>
|
||||
bool PolarOf<T>::operator==(const PolarOf& v) const {
|
||||
template <typename T> bool PolarOf<T>::operator==(const PolarOf &v) const {
|
||||
return (this->distance == v.distance &&
|
||||
this->angle.InDegrees() == v.angle.InDegrees());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PolarOf<T> PolarOf<T>::Normalize(const PolarOf& v) {
|
||||
template <typename T> PolarOf<T> PolarOf<T>::Normalize(const PolarOf &v) {
|
||||
PolarOf<T> r = PolarOf(1, v.angle);
|
||||
return r;
|
||||
}
|
||||
template <typename T>
|
||||
PolarOf<T> PolarOf<T>::normalized() const {
|
||||
template <typename T> PolarOf<T> PolarOf<T>::normalized() const {
|
||||
PolarOf<T> r = PolarOf(1, this->angle);
|
||||
return r;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PolarOf<T> PolarOf<T>::operator-() const {
|
||||
template <typename T> PolarOf<T> PolarOf<T>::operator-() const {
|
||||
PolarOf<T> v =
|
||||
PolarOf(this->distance, this->angle + AngleOf<T>::Degrees(180));
|
||||
return v;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PolarOf<T> PolarOf<T>::operator-(const PolarOf& v) const {
|
||||
template <typename T> PolarOf<T> PolarOf<T>::operator-(const PolarOf &v) const {
|
||||
PolarOf<T> r = -v;
|
||||
return *this + r;
|
||||
}
|
||||
template <typename T>
|
||||
PolarOf<T> PolarOf<T>::operator-=(const PolarOf& v) {
|
||||
template <typename T> PolarOf<T> PolarOf<T>::operator-=(const PolarOf &v) {
|
||||
*this = *this - v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PolarOf<T> PolarOf<T>::operator+(const PolarOf& v) const {
|
||||
template <typename T> PolarOf<T> PolarOf<T>::operator+(const PolarOf &v) const {
|
||||
if (v.distance == 0)
|
||||
return PolarOf(this->distance, this->angle);
|
||||
if (this->distance == 0.0f)
|
||||
@ -105,7 +94,8 @@ PolarOf<T> PolarOf<T>::operator+(const PolarOf& v) const {
|
||||
float newDistance = AngleOf<T>::CosineRuleSide(v.distance, this->distance,
|
||||
AngleOf<T>::Degrees(rotation));
|
||||
|
||||
float angle = Angle::CosineRuleAngle(newDistance, this->distance, v.distance)
|
||||
float angle =
|
||||
AngleSingle::CosineRuleAngle(newDistance, this->distance, v.distance)
|
||||
.InDegrees();
|
||||
|
||||
float newAngle = deltaAngle < 0.0f ? this->angle.InDegrees() - angle
|
||||
@ -114,32 +104,29 @@ PolarOf<T> PolarOf<T>::operator+(const PolarOf& v) const {
|
||||
PolarOf vector = PolarOf(newDistance, newAngleA);
|
||||
return vector;
|
||||
}
|
||||
template <typename T>
|
||||
PolarOf<T> PolarOf<T>::operator+=(const PolarOf& v) {
|
||||
template <typename T> PolarOf<T> PolarOf<T>::operator+=(const PolarOf &v) {
|
||||
*this = *this + v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PolarOf<T> PolarOf<T>::operator*=(float f) {
|
||||
template <typename T> PolarOf<T> PolarOf<T>::operator*=(float f) {
|
||||
this->distance *= f;
|
||||
return *this;
|
||||
}
|
||||
template <typename T>
|
||||
PolarOf<T> PolarOf<T>::operator/=(float f) {
|
||||
template <typename T> PolarOf<T> PolarOf<T>::operator/=(float f) {
|
||||
this->distance /= f;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
float PolarOf<T>::Distance(const PolarOf& v1, const PolarOf& v2) {
|
||||
float PolarOf<T>::Distance(const PolarOf &v1, const PolarOf &v2) {
|
||||
float d =
|
||||
AngleOf<T>::CosineRuleSide(v1.distance, v2.distance, v2.angle - v1.angle);
|
||||
return d;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PolarOf<T> PolarOf<T>::Rotate(const PolarOf& v, AngleOf<T> angle) {
|
||||
PolarOf<T> PolarOf<T>::Rotate(const PolarOf &v, AngleOf<T> angle) {
|
||||
AngleOf<T> a = AngleOf<T>::Normalize(v.angle + angle);
|
||||
PolarOf<T> r = PolarOf(v.distance, a);
|
||||
return r;
|
||||
|
@ -251,7 +251,7 @@ AngleOf<T> SphericalOf<T>::AngleBetween(const SphericalOf &v1,
|
||||
|
||||
// float cdot = Float::Clamp(fraction, -1.0, 1.0);
|
||||
// float r = ((float)acos(cdot)) * Rad2Deg;
|
||||
Angle r = Vector3::Angle(v1_3, v2_3);
|
||||
AngleSingle r = Vector3::Angle(v1_3, v2_3);
|
||||
return AngleOf<T>::Degrees(r.InDegrees());
|
||||
}
|
||||
|
||||
@ -262,7 +262,7 @@ AngleOf<T> Passer::LinearAlgebra::SphericalOf<T>::SignedAngleBetween(
|
||||
Vector3 v1_vector = v1.ToVector3();
|
||||
Vector3 v2_vector = v2.ToVector3();
|
||||
Vector3 axis_vector = axis.ToVector3();
|
||||
Angle r = Vector3::SignedAngle(v1_vector, v2_vector, axis_vector);
|
||||
AngleSingle r = Vector3::SignedAngle(v1_vector, v2_vector, axis_vector);
|
||||
return AngleOf<T>::Degrees(r.InDegrees());
|
||||
}
|
||||
|
||||
|
45
Vector2.cpp
45
Vector2.cpp
@ -49,24 +49,18 @@ const Vector2 Vector2::down = Vector2(0, -1);
|
||||
const Vector2 Vector2::forward = Vector2(0, 1);
|
||||
const Vector2 Vector2::back = Vector2(0, -1);
|
||||
|
||||
bool Vector2::operator==(const Vector2& v) {
|
||||
bool Vector2::operator==(const Vector2 &v) {
|
||||
return (this->x == v.x && this->y == v.y);
|
||||
}
|
||||
|
||||
float Vector2::Magnitude(const Vector2& v) {
|
||||
float Vector2::Magnitude(const Vector2 &v) {
|
||||
return sqrtf(v.x * v.x + v.y * v.y);
|
||||
}
|
||||
float Vector2::magnitude() const {
|
||||
return (float)sqrtf(x * x + y * y);
|
||||
}
|
||||
float Vector2::SqrMagnitude(const Vector2& v) {
|
||||
return v.x * v.x + v.y * v.y;
|
||||
}
|
||||
float Vector2::sqrMagnitude() const {
|
||||
return (x * x + y * y);
|
||||
}
|
||||
float Vector2::magnitude() const { return (float)sqrtf(x * x + y * y); }
|
||||
float Vector2::SqrMagnitude(const Vector2 &v) { return v.x * v.x + v.y * v.y; }
|
||||
float Vector2::sqrMagnitude() const { return (x * x + y * y); }
|
||||
|
||||
Vector2 Vector2::Normalize(const Vector2& v) {
|
||||
Vector2 Vector2::Normalize(const Vector2 &v) {
|
||||
float num = Vector2::Magnitude(v);
|
||||
Vector2 result = Vector2::zero;
|
||||
if (num > Float::epsilon) {
|
||||
@ -83,28 +77,26 @@ Vector2 Vector2::normalized() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
Vector2 Vector2::operator-() {
|
||||
return Vector2(-this->x, -this->y);
|
||||
}
|
||||
Vector2 Vector2::operator-() { return Vector2(-this->x, -this->y); }
|
||||
|
||||
Vector2 Vector2::operator-(const Vector2& v) const {
|
||||
Vector2 Vector2::operator-(const Vector2 &v) const {
|
||||
return Vector2(this->x - v.x, this->y - v.y);
|
||||
}
|
||||
Vector2 Vector2::operator-=(const Vector2& v) {
|
||||
Vector2 Vector2::operator-=(const Vector2 &v) {
|
||||
this->x -= v.x;
|
||||
this->y -= v.y;
|
||||
return *this;
|
||||
}
|
||||
Vector2 Vector2::operator+(const Vector2& v) const {
|
||||
Vector2 Vector2::operator+(const Vector2 &v) const {
|
||||
return Vector2(this->x + v.x, this->y + v.y);
|
||||
}
|
||||
Vector2 Vector2::operator+=(const Vector2& v) {
|
||||
Vector2 Vector2::operator+=(const Vector2 &v) {
|
||||
this->x += v.x;
|
||||
this->y += v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector2 Vector2::Scale(const Vector2& v1, const Vector2& v2) {
|
||||
Vector2 Vector2::Scale(const Vector2 &v1, const Vector2 &v2) {
|
||||
return Vector2(v1.x * v2.x, v1.y * v2.y);
|
||||
}
|
||||
// Vector2 Passer::LinearAlgebra::operator*(const Vector2 &v, float f) {
|
||||
@ -130,18 +122,18 @@ Vector2 Vector2::operator/=(float f) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
float Vector2::Dot(const Vector2& v1, const Vector2& v2) {
|
||||
float Vector2::Dot(const Vector2 &v1, const Vector2 &v2) {
|
||||
return v1.x * v2.x + v1.y * v2.y;
|
||||
}
|
||||
|
||||
float Vector2::Distance(const Vector2& v1, const Vector2& v2) {
|
||||
float Vector2::Distance(const Vector2 &v1, const Vector2 &v2) {
|
||||
return Magnitude(v1 - v2);
|
||||
}
|
||||
|
||||
float Vector2::Angle(const Vector2& v1, const Vector2& v2) {
|
||||
float Vector2::Angle(const Vector2 &v1, const Vector2 &v2) {
|
||||
return (float)fabs(SignedAngle(v1, v2));
|
||||
}
|
||||
float Vector2::SignedAngle(const Vector2& v1, const Vector2& v2) {
|
||||
float Vector2::SignedAngle(const Vector2 &v1, const Vector2 &v2) {
|
||||
float sqrMagFrom = v1.sqrMagnitude();
|
||||
float sqrMagTo = v2.sqrMagnitude();
|
||||
|
||||
@ -159,7 +151,8 @@ float Vector2::SignedAngle(const Vector2& v1, const Vector2& v2) {
|
||||
return -(angleTo - angleFrom) * Passer::LinearAlgebra::Rad2Deg;
|
||||
}
|
||||
|
||||
Vector2 Vector2::Rotate(const Vector2& v, Passer::LinearAlgebra::Angle a) {
|
||||
Vector2 Vector2::Rotate(const Vector2 &v,
|
||||
Passer::LinearAlgebra::AngleSingle a) {
|
||||
float angleRad = a.InDegrees() * Passer::LinearAlgebra::Deg2Rad;
|
||||
#if defined(AVR)
|
||||
float sinValue = sin(angleRad);
|
||||
@ -176,7 +169,7 @@ Vector2 Vector2::Rotate(const Vector2& v, Passer::LinearAlgebra::Angle a) {
|
||||
return r;
|
||||
}
|
||||
|
||||
Vector2 Vector2::Lerp(const Vector2& v1, const Vector2& v2, float f) {
|
||||
Vector2 Vector2::Lerp(const Vector2 &v1, const Vector2 &v2, float f) {
|
||||
Vector2 v = v1 + (v2 - v1) * f;
|
||||
return v;
|
||||
}
|
||||
|
43
Vector2.h
43
Vector2.h
@ -30,8 +30,7 @@ namespace Passer {
|
||||
namespace LinearAlgebra {
|
||||
|
||||
struct Vector3;
|
||||
template <typename T>
|
||||
class PolarOf;
|
||||
template <typename T> class PolarOf;
|
||||
// using Polar = PolarOf<float>
|
||||
|
||||
/// @brief A 2=dimensional vector
|
||||
@ -40,7 +39,7 @@ class PolarOf;
|
||||
struct Vector2 : Vec2 {
|
||||
friend struct Vec2;
|
||||
|
||||
public:
|
||||
public:
|
||||
/// @brief A new 2-dimensional zero vector
|
||||
Vector2();
|
||||
/// @brief A new 2-dimensional vector
|
||||
@ -82,12 +81,12 @@ struct Vector2 : Vec2 {
|
||||
/// @return true if it is identical to the given vector
|
||||
/// @note This uses float comparison to check equality which may have strange
|
||||
/// effects. Equality on floats should be avoided.
|
||||
bool operator==(const Vector2& v);
|
||||
bool operator==(const Vector2 &v);
|
||||
|
||||
/// @brief The vector length
|
||||
/// @param v The vector for which you need the length
|
||||
/// @return The vector length
|
||||
static float Magnitude(const Vector2& v);
|
||||
static float Magnitude(const Vector2 &v);
|
||||
/// @brief The vector length
|
||||
/// @return The vector length
|
||||
float magnitude() const;
|
||||
@ -97,7 +96,7 @@ struct Vector2 : Vec2 {
|
||||
/// @remark The squared length is computationally simpler than the real
|
||||
/// length. Think of Pythagoras A^2 + B^2 = C^2. This prevents the calculation
|
||||
/// of the squared root of C.
|
||||
static float SqrMagnitude(const Vector2& v);
|
||||
static float SqrMagnitude(const Vector2 &v);
|
||||
/// @brief The squared vector length
|
||||
/// @return The squared vector length
|
||||
/// @remark The squared length is computationally simpler than the real
|
||||
@ -108,7 +107,7 @@ struct Vector2 : Vec2 {
|
||||
/// @brief Convert the vector to a length of 1
|
||||
/// @param v The vector to convert
|
||||
/// @return The vector normalized to a length of 1
|
||||
static Vector2 Normalize(const Vector2& v);
|
||||
static Vector2 Normalize(const Vector2 &v);
|
||||
/// @brief Convert the vector to a length 1
|
||||
/// @return The vector normalized to a length of 1
|
||||
Vector2 normalized() const;
|
||||
@ -120,13 +119,13 @@ struct Vector2 : Vec2 {
|
||||
/// @brief Subtract a vector from this vector
|
||||
/// @param v The vector to subtract from this vector
|
||||
/// @return The result of the subtraction
|
||||
Vector2 operator-(const Vector2& v) const;
|
||||
Vector2 operator-=(const Vector2& v);
|
||||
Vector2 operator-(const Vector2 &v) const;
|
||||
Vector2 operator-=(const Vector2 &v);
|
||||
/// @brief Add a vector to this vector
|
||||
/// @param v The vector to add to this vector
|
||||
/// @return The result of the addition
|
||||
Vector2 operator+(const Vector2& v) const;
|
||||
Vector2 operator+=(const Vector2& v);
|
||||
Vector2 operator+(const Vector2 &v) const;
|
||||
Vector2 operator+=(const Vector2 &v);
|
||||
|
||||
/// @brief Scale the vector using another vector
|
||||
/// @param v1 The vector to scale
|
||||
@ -134,16 +133,16 @@ struct Vector2 : Vec2 {
|
||||
/// @return The scaled vector
|
||||
/// @remark Each component of the vector v1 will be multiplied with the
|
||||
/// matching component from the scaling vector v2.
|
||||
static Vector2 Scale(const Vector2& v1, const Vector2& v2);
|
||||
static Vector2 Scale(const Vector2 &v1, const Vector2 &v2);
|
||||
/// @brief Scale the vector uniformly up
|
||||
/// @param f The scaling factor
|
||||
/// @return The scaled vector
|
||||
/// @remark Each component of the vector will be multipled with the same
|
||||
/// factor f.
|
||||
friend Vector2 operator*(const Vector2& v, float f) {
|
||||
friend Vector2 operator*(const Vector2 &v, float f) {
|
||||
return Vector2(v.x * f, v.y * f);
|
||||
}
|
||||
friend Vector2 operator*(float f, const Vector2& v) {
|
||||
friend Vector2 operator*(float f, const Vector2 &v) {
|
||||
return Vector2(v.x * f, v.y * f);
|
||||
// return Vector2(f * v.x, f * v.y);
|
||||
}
|
||||
@ -152,10 +151,10 @@ struct Vector2 : Vec2 {
|
||||
/// @param f The scaling factor
|
||||
/// @return The scaled vector
|
||||
/// @remark Each componet of the vector will be divided by the same factor.
|
||||
friend Vector2 operator/(const Vector2& v, float f) {
|
||||
friend Vector2 operator/(const Vector2 &v, float f) {
|
||||
return Vector2(v.x / f, v.y / f);
|
||||
}
|
||||
friend Vector2 operator/(float f, const Vector2& v) {
|
||||
friend Vector2 operator/(float f, const Vector2 &v) {
|
||||
return Vector2(f / v.x, f / v.y);
|
||||
}
|
||||
Vector2 operator/=(float f);
|
||||
@ -164,13 +163,13 @@ struct Vector2 : Vec2 {
|
||||
/// @param v1 The first vector
|
||||
/// @param v2 The second vector
|
||||
/// @return The dot product of the two vectors
|
||||
static float Dot(const Vector2& v1, const Vector2& v2);
|
||||
static float Dot(const Vector2 &v1, const Vector2 &v2);
|
||||
|
||||
/// @brief The distance between two vectors
|
||||
/// @param v1 The first vector
|
||||
/// @param v2 The second vector
|
||||
/// @return The distance between the two vectors
|
||||
static float Distance(const Vector2& v1, const Vector2& v2);
|
||||
static float Distance(const Vector2 &v1, const Vector2 &v2);
|
||||
|
||||
/// @brief The angle between two vectors
|
||||
/// @param v1 The first vector
|
||||
@ -179,18 +178,18 @@ struct Vector2 : Vec2 {
|
||||
/// @remark This reterns an unsigned angle which is the shortest distance
|
||||
/// between the two vectors. Use Vector2::SignedAngle if a signed angle is
|
||||
/// needed.
|
||||
static float Angle(const Vector2& v1, const Vector2& v2);
|
||||
static float Angle(const Vector2 &v1, const Vector2 &v2);
|
||||
/// @brief The signed angle between two vectors
|
||||
/// @param v1 The starting vector
|
||||
/// @param v2 The ending vector
|
||||
/// @return The signed angle between the two vectors
|
||||
static float SignedAngle(const Vector2& v1, const Vector2& v2);
|
||||
static float SignedAngle(const Vector2 &v1, const Vector2 &v2);
|
||||
|
||||
/// @brief Rotate the vector
|
||||
/// @param v The vector to rotate
|
||||
/// @param a The angle in degrees to rotate
|
||||
/// @return The rotated vector
|
||||
static Vector2 Rotate(const Vector2& v, Passer::LinearAlgebra::Angle a);
|
||||
static Vector2 Rotate(const Vector2 &v, Passer::LinearAlgebra::AngleSingle a);
|
||||
|
||||
/// @brief Lerp (linear interpolation) between two vectors
|
||||
/// @param v1 The starting vector
|
||||
@ -200,7 +199,7 @@ struct Vector2 : Vec2 {
|
||||
/// @remark The factor f is unclamped. Value 0 matches the vector *v1*, Value
|
||||
/// 1 matches vector *v2*. Value -1 is vector *v1* minus the difference
|
||||
/// between *v1* and *v2* etc.
|
||||
static Vector2 Lerp(const Vector2& v1, const Vector2& v2, float f);
|
||||
static Vector2 Lerp(const Vector2 &v1, const Vector2 &v2, float f);
|
||||
};
|
||||
|
||||
} // namespace LinearAlgebra
|
||||
|
@ -63,7 +63,7 @@ TEST(AngleSingle, Compare) {
|
||||
}
|
||||
|
||||
TEST(AngleSingle, Normalize) {
|
||||
Angle r = AngleSingle();
|
||||
AngleSingle r = AngleSingle();
|
||||
|
||||
r = AngleSingle::Normalize(AngleSingle::Degrees(90.0f));
|
||||
EXPECT_FLOAT_EQ(r.InDegrees(), 90) << "Normalize 90";
|
||||
@ -96,7 +96,7 @@ TEST(AngleSingle, Normalize) {
|
||||
}
|
||||
|
||||
TEST(AngleSingle, Clamp) {
|
||||
Angle r = AngleSingle();
|
||||
AngleSingle r = AngleSingle();
|
||||
|
||||
r = AngleSingle::Clamp(AngleSingle::Degrees(1), AngleSingle::Degrees(0),
|
||||
AngleSingle::Degrees(2));
|
||||
@ -135,7 +135,7 @@ TEST(AngleSingle, Clamp) {
|
||||
}
|
||||
|
||||
// TEST(AngleSingle, Difference) {
|
||||
// Angle r = 0;
|
||||
// AngleSingle r = 0;
|
||||
|
||||
// r = AngleSingle::Difference(0, 90);
|
||||
// EXPECT_FLOAT_EQ(r.InDegrees(), 90) << "Difference 0 90";
|
||||
|
@ -32,40 +32,40 @@ TEST(Polar, FromSpherical) {
|
||||
SphericalSingle s;
|
||||
Polar p;
|
||||
|
||||
s = SphericalSingle(1, Angle::Degrees(0), Angle::Degrees(0));
|
||||
s = SphericalSingle(1, AngleSingle::Degrees(0), AngleSingle::Degrees(0));
|
||||
p = Polar::FromSpherical(s);
|
||||
|
||||
EXPECT_FLOAT_EQ(p.distance, 1.0F) << "p.distance FromSpherical(1 0 0)";
|
||||
EXPECT_FLOAT_EQ(p.angle.InDegrees(), 0.0F) << "p.angle FromSpherical(1 0 0)";
|
||||
|
||||
s = SphericalSingle(1, Angle::Degrees(45), Angle::Degrees(0));
|
||||
s = SphericalSingle(1, AngleSingle::Degrees(45), AngleSingle::Degrees(0));
|
||||
p = Polar::FromSpherical(s);
|
||||
|
||||
EXPECT_FLOAT_EQ(p.distance, 1.0F) << "p.distance FromSpherical(1 45 0)";
|
||||
EXPECT_FLOAT_EQ(p.angle.InDegrees(), 45.0F)
|
||||
<< "p.angle FromSpherical(1 45 0)";
|
||||
|
||||
s = SphericalSingle(1, Angle::Degrees(-45), Angle::Degrees(0));
|
||||
s = SphericalSingle(1, AngleSingle::Degrees(-45), AngleSingle::Degrees(0));
|
||||
p = Polar::FromSpherical(s);
|
||||
|
||||
EXPECT_FLOAT_EQ(p.distance, 1.0F) << "p.distance FromSpherical(1 -45 0)";
|
||||
EXPECT_FLOAT_EQ(p.angle.InDegrees(), -45.0F)
|
||||
<< "p.angle FromSpherical(1 -45 0)";
|
||||
|
||||
s = SphericalSingle(0, Angle::Degrees(0), Angle::Degrees(0));
|
||||
s = SphericalSingle(0, AngleSingle::Degrees(0), AngleSingle::Degrees(0));
|
||||
p = Polar::FromSpherical(s);
|
||||
|
||||
EXPECT_FLOAT_EQ(p.distance, 0.0F) << "p.distance FromSpherical(0 0 0)";
|
||||
EXPECT_FLOAT_EQ(p.angle.InDegrees(), 0.0F) << "p.angle FromSpherical(0 0 0)";
|
||||
|
||||
s = SphericalSingle(-1, Angle::Degrees(0), Angle::Degrees(0));
|
||||
s = SphericalSingle(-1, AngleSingle::Degrees(0), AngleSingle::Degrees(0));
|
||||
p = Polar::FromSpherical(s);
|
||||
|
||||
EXPECT_FLOAT_EQ(p.distance, 1.0F) << "p.distance FromSpherical(-1 0 0)";
|
||||
EXPECT_FLOAT_EQ(p.angle.InDegrees(), -180.0F)
|
||||
<< "p.angle FromSpherical(-1 0 0)";
|
||||
|
||||
s = SphericalSingle(0, Angle::Degrees(0), Angle::Degrees(90));
|
||||
s = SphericalSingle(0, AngleSingle::Degrees(0), AngleSingle::Degrees(90));
|
||||
p = Polar::FromSpherical(s);
|
||||
|
||||
EXPECT_FLOAT_EQ(p.distance, 0.0F) << "p.distance FromSpherical(0 0 90)";
|
||||
@ -73,32 +73,32 @@ TEST(Polar, FromSpherical) {
|
||||
}
|
||||
|
||||
TEST(Polar, Negation) {
|
||||
Polar v = Polar(2, Angle::Degrees(45));
|
||||
Polar v = Polar(2, AngleSingle::Degrees(45));
|
||||
Polar r = Polar::zero;
|
||||
|
||||
r = -v;
|
||||
EXPECT_FLOAT_EQ(r.distance, 2);
|
||||
EXPECT_FLOAT_EQ(r.angle.InDegrees(), -135);
|
||||
EXPECT_TRUE(r == Polar(2, Angle::Degrees(-135))) << "Negate(2 45)";
|
||||
EXPECT_TRUE(r == Polar(2, AngleSingle::Degrees(-135))) << "Negate(2 45)";
|
||||
|
||||
v = Polar(2, Angle::Degrees(-45));
|
||||
v = Polar(2, AngleSingle::Degrees(-45));
|
||||
r = -v;
|
||||
EXPECT_TRUE(r == Polar(2, Angle::Degrees(135))) << "Negate(2 -45)";
|
||||
EXPECT_TRUE(r == Polar(2, AngleSingle::Degrees(135))) << "Negate(2 -45)";
|
||||
|
||||
v = Polar(2, Angle::Degrees(0));
|
||||
v = Polar(2, AngleSingle::Degrees(0));
|
||||
r = -v;
|
||||
EXPECT_TRUE(r == Polar(2, Angle::Degrees(180))) << "Negate(2 0)";
|
||||
EXPECT_TRUE(r == Polar(2, AngleSingle::Degrees(180))) << "Negate(2 0)";
|
||||
|
||||
v = Polar(0, Angle::Degrees(0));
|
||||
v = Polar(0, AngleSingle::Degrees(0));
|
||||
r = -v;
|
||||
EXPECT_FLOAT_EQ(r.distance, 0.0f);
|
||||
EXPECT_FLOAT_EQ(r.angle.InDegrees(), 0.0f);
|
||||
EXPECT_TRUE(r == Polar(0, Angle::Degrees(0))) << "Negate(0 0)";
|
||||
EXPECT_TRUE(r == Polar(0, AngleSingle::Degrees(0))) << "Negate(0 0)";
|
||||
}
|
||||
|
||||
TEST(Polar, Subtraction) {
|
||||
Polar v1 = Polar(4, Angle::Degrees(45));
|
||||
Polar v2 = Polar(1, Angle::Degrees(-90));
|
||||
Polar v1 = Polar(4, AngleSingle::Degrees(45));
|
||||
Polar v2 = Polar(1, AngleSingle::Degrees(-90));
|
||||
Polar r = Polar::zero;
|
||||
|
||||
r = v1 - v2;
|
||||
@ -110,8 +110,8 @@ TEST(Polar, Subtraction) {
|
||||
}
|
||||
|
||||
TEST(Polar, Addition) {
|
||||
Polar v1 = Polar(1, Angle::Degrees(45));
|
||||
Polar v2 = Polar(1, Angle::Degrees(-90));
|
||||
Polar v1 = Polar(1, AngleSingle::Degrees(45));
|
||||
Polar v2 = Polar(1, AngleSingle::Degrees(-90));
|
||||
Polar r = Polar::zero;
|
||||
|
||||
r = v1 - v2;
|
||||
@ -125,14 +125,14 @@ TEST(Polar, Addition) {
|
||||
r += v2;
|
||||
EXPECT_FLOAT_EQ(r.distance, v1.distance) << "Addition(0 0)";
|
||||
|
||||
v2 = Polar(1, Angle::Degrees(-45));
|
||||
v2 = Polar(1, AngleSingle::Degrees(-45));
|
||||
r = v1 + v2;
|
||||
EXPECT_FLOAT_EQ(r.distance, sqrtf(2)) << "Addition(0 0 0)";
|
||||
EXPECT_FLOAT_EQ(r.angle.InDegrees(), 0) << "Addition(0 0 0)";
|
||||
}
|
||||
|
||||
TEST(Polar, Scale_Multiply) {
|
||||
Polar v1 = Polar(4, Angle::Degrees(45));
|
||||
Polar v1 = Polar(4, AngleSingle::Degrees(45));
|
||||
Polar r = Polar::zero;
|
||||
|
||||
r = v1 * 2.0f;
|
||||
@ -142,7 +142,7 @@ TEST(Polar, Scale_Multiply) {
|
||||
}
|
||||
|
||||
TEST(Polar, Scale_Divide) {
|
||||
Polar v1 = Polar(4, Angle::Degrees(45));
|
||||
Polar v1 = Polar(4, AngleSingle::Degrees(45));
|
||||
Polar r = Polar::zero;
|
||||
|
||||
r = v1 / 2.0f;
|
||||
@ -152,8 +152,8 @@ TEST(Polar, Scale_Divide) {
|
||||
}
|
||||
|
||||
TEST(Polar, Distance) {
|
||||
Polar v1 = Polar(4, Angle::Degrees(45));
|
||||
Polar v2 = Polar(1, Angle::Degrees(-90));
|
||||
Polar v1 = Polar(4, AngleSingle::Degrees(45));
|
||||
Polar v2 = Polar(1, AngleSingle::Degrees(-90));
|
||||
float d = 0;
|
||||
|
||||
d = Polar::Distance(v1, v2);
|
||||
@ -165,10 +165,10 @@ TEST(Polar, Distance) {
|
||||
}
|
||||
|
||||
TEST(Polar, Rotate) {
|
||||
Polar v = Polar(4, Angle::Degrees(45));
|
||||
Polar v = Polar(4, AngleSingle::Degrees(45));
|
||||
Polar r = Polar::zero;
|
||||
|
||||
r = Polar::Rotate(v, Angle::Degrees(45));
|
||||
r = Polar::Rotate(v, AngleSingle::Degrees(45));
|
||||
EXPECT_FLOAT_EQ(r.distance, v.distance) << "Rotate(4 45, 45)";
|
||||
EXPECT_FLOAT_EQ(r.angle.InDegrees(), 90.0f) << "Rotate(4 45, 45)";
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ TEST(SphericalSingle, FromVector3) {
|
||||
}
|
||||
|
||||
TEST(SphericalSingle, FromPolar) {
|
||||
Polar p = Polar(1, Angle::Degrees(0));
|
||||
Polar p = Polar(1, AngleSingle::Degrees(0));
|
||||
SphericalSingle s = SphericalSingle ::FromPolar(p);
|
||||
|
||||
EXPECT_FLOAT_EQ(s.distance, 1.0F) << "s.distance Polar(1 0)";
|
||||
@ -40,7 +40,7 @@ TEST(SphericalSingle, FromPolar) {
|
||||
EXPECT_FLOAT_EQ(s.direction.vertical.InDegrees(), 0.0F)
|
||||
<< "s.vert Polar(1 0)";
|
||||
|
||||
p = Polar(1, Angle::Degrees(45));
|
||||
p = Polar(1, AngleSingle::Degrees(45));
|
||||
s = SphericalSingle ::FromPolar(p);
|
||||
|
||||
EXPECT_FLOAT_EQ(s.distance, 1.0F) << "s.distance Polar(1 45)";
|
||||
@ -49,7 +49,7 @@ TEST(SphericalSingle, FromPolar) {
|
||||
EXPECT_FLOAT_EQ(s.direction.vertical.InDegrees(), 0.0F)
|
||||
<< "s.vert Polar(1 45)";
|
||||
|
||||
p = Polar(1, Angle::Degrees(-45));
|
||||
p = Polar(1, AngleSingle::Degrees(-45));
|
||||
s = SphericalSingle ::FromPolar(p);
|
||||
|
||||
EXPECT_FLOAT_EQ(s.distance, 1.0F) << "s.distance Polar(1 -45)";
|
||||
@ -58,7 +58,7 @@ TEST(SphericalSingle, FromPolar) {
|
||||
EXPECT_FLOAT_EQ(s.direction.vertical.InDegrees(), 0.0F)
|
||||
<< "s.vert Polar(1 -45)";
|
||||
|
||||
p = Polar(0, Angle::Degrees(0));
|
||||
p = Polar(0, AngleSingle::Degrees(0));
|
||||
s = SphericalSingle ::FromPolar(p);
|
||||
|
||||
EXPECT_FLOAT_EQ(s.distance, 0.0F) << "s.distance Polar(0 0)";
|
||||
@ -67,7 +67,7 @@ TEST(SphericalSingle, FromPolar) {
|
||||
EXPECT_FLOAT_EQ(s.direction.vertical.InDegrees(), 0.0F)
|
||||
<< "s.vert Polar(0 0)";
|
||||
|
||||
p = Polar(-1, Angle::Degrees(0));
|
||||
p = Polar(-1, AngleSingle::Degrees(0));
|
||||
s = SphericalSingle ::FromPolar(p);
|
||||
|
||||
EXPECT_FLOAT_EQ(s.distance, 1.0F) << "s.distance Polar(-1 0)";
|
||||
@ -81,8 +81,8 @@ TEST(SphericalSingle, Incident1) {
|
||||
Vector3 v = Vector3(2.242557f, 1.027884f, -0.322347f);
|
||||
SphericalSingle s = SphericalSingle ::FromVector3(v);
|
||||
|
||||
SphericalSingle sr =
|
||||
SphericalSingle(2.49F, Angle::Degrees(98.18f), Angle::Degrees(24.4F));
|
||||
SphericalSingle sr = SphericalSingle(2.49F, AngleSingle::Degrees(98.18f),
|
||||
AngleSingle::Degrees(24.4F));
|
||||
EXPECT_NEAR(s.distance, sr.distance, 1.0e-01);
|
||||
EXPECT_NEAR(s.direction.horizontal.InDegrees(),
|
||||
sr.direction.horizontal.InDegrees(), 1.0e-02);
|
||||
@ -99,8 +99,8 @@ TEST(SphericalSingle, Incident2) {
|
||||
Vector3 v = Vector3(1.0f, 0.0f, 1.0f);
|
||||
SphericalSingle s = SphericalSingle ::FromVector3(v);
|
||||
|
||||
SphericalSingle sr = SphericalSingle(1.4142135623F, Angle::Degrees(45.0f),
|
||||
Angle::Degrees(0.0F));
|
||||
SphericalSingle sr = SphericalSingle(
|
||||
1.4142135623F, AngleSingle::Degrees(45.0f), AngleSingle::Degrees(0.0F));
|
||||
EXPECT_NEAR(s.distance, sr.distance, 1.0e-05);
|
||||
EXPECT_NEAR(s.direction.horizontal.InDegrees(),
|
||||
sr.direction.horizontal.InDegrees(), 1.0e-05);
|
||||
@ -115,8 +115,8 @@ TEST(SphericalSingle, Incident2) {
|
||||
v = Vector3(0.0f, 1.0f, 1.0f);
|
||||
s = SphericalSingle ::FromVector3(v);
|
||||
|
||||
sr = SphericalSingle(1.4142135623F, Angle::Degrees(0.0f),
|
||||
Angle::Degrees(45.0F));
|
||||
sr = SphericalSingle(1.4142135623F, AngleSingle::Degrees(0.0f),
|
||||
AngleSingle::Degrees(45.0F));
|
||||
EXPECT_NEAR(s.distance, sr.distance, 1.0e-05);
|
||||
EXPECT_NEAR(s.direction.horizontal.InDegrees(),
|
||||
sr.direction.horizontal.InDegrees(), 1.0e-05);
|
||||
@ -149,7 +149,7 @@ TEST(SphericalSingle, Incident2) {
|
||||
|
||||
TEST(SphericalSingle, Addition) {
|
||||
SphericalSingle v1 =
|
||||
SphericalSingle(1, Angle::Degrees(45), Angle::Degrees(0));
|
||||
SphericalSingle(1, AngleSingle::Degrees(45), AngleSingle::Degrees(0));
|
||||
SphericalSingle v2 = SphericalSingle ::zero;
|
||||
SphericalSingle r = SphericalSingle ::zero;
|
||||
|
||||
@ -160,13 +160,13 @@ TEST(SphericalSingle, Addition) {
|
||||
r += v2;
|
||||
EXPECT_FLOAT_EQ(r.distance, v1.distance) << "Addition(0 0 0)";
|
||||
|
||||
v2 = SphericalSingle(1, Angle::Degrees(-45), Angle::Degrees(0));
|
||||
v2 = SphericalSingle(1, AngleSingle::Degrees(-45), AngleSingle::Degrees(0));
|
||||
r = v1 + v2;
|
||||
EXPECT_FLOAT_EQ(r.distance, sqrtf(2)) << "Addition(1 -45 0)";
|
||||
EXPECT_FLOAT_EQ(r.direction.horizontal.InDegrees(), 0) << "Addition(1 -45 0)";
|
||||
EXPECT_FLOAT_EQ(r.direction.vertical.InDegrees(), 0) << "Addition(1 -45 0)";
|
||||
|
||||
v2 = SphericalSingle(1, Angle::Degrees(0), Angle::Degrees(90));
|
||||
v2 = SphericalSingle(1, AngleSingle::Degrees(0), AngleSingle::Degrees(90));
|
||||
r = v1 + v2;
|
||||
EXPECT_FLOAT_EQ(r.distance, sqrtf(2)) << "Addition(1 0 90)";
|
||||
EXPECT_FLOAT_EQ(r.direction.horizontal.InDegrees(), 45) << "Addition(1 0 90)";
|
||||
|
@ -1,7 +1,7 @@
|
||||
#if GTEST
|
||||
#include <gtest/gtest.h>
|
||||
#include <math.h>
|
||||
#include <limits>
|
||||
#include <math.h>
|
||||
|
||||
#include "Vector2.h"
|
||||
|
||||
@ -462,16 +462,16 @@ TEST(Vector2, Rotate) {
|
||||
Vector2 v1 = Vector2(1, 2);
|
||||
Vector2 r = Vector2(0, 0);
|
||||
|
||||
r = Vector2::Rotate(v1, Angle::Degrees(0));
|
||||
r = Vector2::Rotate(v1, AngleSingle::Degrees(0));
|
||||
EXPECT_FLOAT_EQ(Vector2::Distance(r, v1), 0);
|
||||
|
||||
r = Vector2::Rotate(v1, Angle::Degrees(180));
|
||||
r = Vector2::Rotate(v1, AngleSingle::Degrees(180));
|
||||
EXPECT_NEAR(Vector2::Distance(r, Vector2(-1, -2)), 0, 1.0e-06);
|
||||
|
||||
r = Vector2::Rotate(v1, Angle::Degrees(-90));
|
||||
r = Vector2::Rotate(v1, AngleSingle::Degrees(-90));
|
||||
EXPECT_NEAR(Vector2::Distance(r, Vector2(2, -1)), 0, 1.0e-06);
|
||||
|
||||
r = Vector2::Rotate(v1, Angle::Degrees(270));
|
||||
r = Vector2::Rotate(v1, AngleSingle::Degrees(270));
|
||||
EXPECT_NEAR(Vector2::Distance(r, Vector2(2, -1)), 0, 1.0e-06);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user