lib/matrix: inline common Vector3f operators

This commit is contained in:
Daniel Agar
2022-01-21 12:53:26 -05:00
parent 56de0e27d8
commit 61778511ea
3 changed files with 22 additions and 16 deletions
+7 -7
View File
@@ -66,7 +66,7 @@ public:
return v(i, 0);
}
Type dot(const MatrixM1 &b) const
inline Type dot(const MatrixM1 &b) const
{
const Vector &a(*this);
Type r(0);
@@ -89,13 +89,13 @@ public:
return Vector(MatrixM1::operator*(b));
}
Type norm() const
inline Type norm() const
{
const Vector &a(*this);
return Type(matrix::sqrt(a.dot(a)));
}
Type norm_squared() const
inline Type norm_squared() const
{
const Vector &a(*this);
return a.dot(a);
@@ -111,12 +111,12 @@ public:
(*this) /= norm();
}
Vector unit() const
inline Vector unit() const
{
return (*this) / norm();
}
Vector unit_or_zero(const Type eps = Type(1e-5)) const
inline Vector unit_or_zero(const Type eps = Type(1e-5)) const
{
const Type n = norm();
@@ -132,12 +132,12 @@ public:
return unit();
}
bool longerThan(Type testVal) const
inline bool longerThan(Type testVal) const
{
return norm_squared() > testVal * testVal;
}
Vector sqrt() const
inline Vector sqrt() const
{
const Vector &a(*this);
Vector r;
+2 -2
View File
@@ -60,13 +60,13 @@ public:
v(1) = other(1);
}
Type cross(const Matrix21 &b) const
inline Type cross(const Matrix21 &b) const
{
const Vector2 &a(*this);
return a(0) * b(1, 0) - a(1) * b(0, 0);
}
Type operator%(const Matrix21 &b) const
inline Type operator%(const Matrix21 &b) const
{
return (*this).cross(b);
}
+13 -7
View File
@@ -62,7 +62,7 @@ public:
{
}
Vector3 cross(const Matrix31 &b) const
inline Vector3 cross(const Matrix31 &b) const
{
const Vector3 &a(*this);
return {a(1) *b(2, 0) - a(2) *b(1, 0), -a(0) *b(2, 0) + a(2) *b(0, 0), a(0) *b(1, 0) - a(1) *b(0, 0)};
@@ -74,32 +74,38 @@ public:
inline Vector3 operator+(Vector3 other) const
{
return Matrix31::operator+(other);
const Vector3 &a(*this);
return Vector3{a(0) + other(0), a(1) + other(1), a(2) + other(2)};
}
inline Vector3 operator+(Type scalar) const
{
return Matrix31::operator+(scalar);
const Vector3 &a(*this);
return Vector3{a(0) + scalar, a(1) + scalar, a(2) + scalar};
}
inline Vector3 operator-(Vector3 other) const
{
return Matrix31::operator-(other);
const Vector3 &a(*this);
return Vector3{a(0) - other(0), a(1) - other(1), a(2) - other(2)};
}
inline Vector3 operator-(Type scalar) const
{
return Matrix31::operator-(scalar);
const Vector3 &a(*this);
return Vector3{a(0) - scalar, a(1) - scalar, a(2) - scalar};
}
inline Vector3 operator-() const
{
return Matrix31::operator-();
const Vector3 &a(*this);
return Vector3{-a(0), -a(1), -a(2)};
}
inline Vector3 operator*(Type scalar) const
{
return Matrix31::operator*(scalar);
const Vector3 &a(*this);
return Vector3{a(0) *scalar, a(1) *scalar, a(2) *scalar};
}
inline Type operator*(Vector3 b) const