Add spherical subtract
This commit is contained in:
parent
2bad384611
commit
c70c079efc
@ -71,6 +71,19 @@ Spherical Spherical::operator-() const {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Spherical Spherical::operator-(const Spherical &s2) const {
|
||||||
|
// let's do it the easy way...
|
||||||
|
Vector3 v1 = Vector3(*this);
|
||||||
|
Vector3 v2 = Vector3(s2);
|
||||||
|
Vector3 v = v1 - v2;
|
||||||
|
Spherical r = Spherical(v);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
Spherical Spherical::operator-=(const Spherical &v) {
|
||||||
|
*this = *this - v;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Spherical Spherical::operator+(const Spherical &s2) const {
|
Spherical Spherical::operator+(const Spherical &s2) const {
|
||||||
// let's do it the easy way...
|
// let's do it the easy way...
|
||||||
Vector3 v1 = Vector3(*this);
|
Vector3 v1 = Vector3(*this);
|
||||||
@ -140,6 +153,7 @@ Spherical Spherical::operator*=(float f) {
|
|||||||
this->distance *= f;
|
this->distance *= f;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Spherical Passer::LinearAlgebra::operator/(const Spherical &v, float f) {
|
Spherical Passer::LinearAlgebra::operator/(const Spherical &v, float f) {
|
||||||
return Spherical(v.distance / f, v.horizontalAngle, v.verticalAngle);
|
return Spherical(v.distance / f, v.horizontalAngle, v.verticalAngle);
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,11 @@ public:
|
|||||||
/// vertically. Distance will stay the same.
|
/// vertically. Distance will stay the same.
|
||||||
Spherical operator-() const;
|
Spherical operator-() const;
|
||||||
|
|
||||||
|
/// @brief Subtract a spherical vector from this vector
|
||||||
|
/// @param v The vector to subtract
|
||||||
|
/// @return The result of the subtraction
|
||||||
|
Spherical operator-(const Spherical &v) const;
|
||||||
|
Spherical operator-=(const Spherical &v);
|
||||||
/// @brief Add a spherical vector to this vector
|
/// @brief Add a spherical vector to this vector
|
||||||
/// @param v The vector to add
|
/// @param v The vector to add
|
||||||
/// @return The result of the addition
|
/// @return The result of the addition
|
||||||
|
@ -142,9 +142,9 @@ TEST(Spherical, Addition) {
|
|||||||
|
|
||||||
v2 = Spherical(1, -45, 0);
|
v2 = Spherical(1, -45, 0);
|
||||||
r = v1 + v2;
|
r = v1 + v2;
|
||||||
EXPECT_FLOAT_EQ(r.distance, sqrtf(2)) << "Addition(0 0 0)";
|
EXPECT_FLOAT_EQ(r.distance, sqrtf(2)) << "Addition(1 -45 0)";
|
||||||
EXPECT_FLOAT_EQ(r.horizontalAngle, 0) << "Addition(0 0 0)";
|
EXPECT_FLOAT_EQ(r.horizontalAngle, 0) << "Addition(1 -45 0)";
|
||||||
EXPECT_FLOAT_EQ(r.verticalAngle, 0) << "Addition(0 0 0)";
|
EXPECT_FLOAT_EQ(r.verticalAngle, 0) << "Addition(1 -45 0)";
|
||||||
|
|
||||||
v2 = Spherical(1, 0, 90);
|
v2 = Spherical(1, 0, 90);
|
||||||
r = v1 + v2;
|
r = v1 + v2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user