summaryrefslogtreecommitdiff
path: root/indra/llmath/v2math.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llmath/v2math.cpp')
-rw-r--r--indra/llmath/v2math.cpp42
1 files changed, 24 insertions, 18 deletions
diff --git a/indra/llmath/v2math.cpp b/indra/llmath/v2math.cpp
index 4649e13376..9d16f1e654 100644
--- a/indra/llmath/v2math.cpp
+++ b/indra/llmath/v2math.cpp
@@ -26,7 +26,6 @@
#include "linden_common.h"
-//#include "vmath.h"
#include "v2math.h"
#include "v3math.h"
#include "v4math.h"
@@ -47,8 +46,8 @@ bool LLVector2::abs()
{
bool ret{ false };
- if (mV[0] < 0.f) { mV[0] = -mV[0]; ret = true; }
- if (mV[1] < 0.f) { mV[1] = -mV[1]; ret = true; }
+ if (mV[VX] < 0.f) { mV[VX] = -mV[VX]; ret = true; }
+ if (mV[VY] < 0.f) { mV[VY] = -mV[VY]; ret = true; }
return ret;
}
@@ -67,7 +66,14 @@ F32 angle_between(const LLVector2& a, const LLVector2& b)
return angle;
}
-bool are_parallel(const LLVector2 &a, const LLVector2 &b, float epsilon)
+F32 signed_angle_between(const LLVector2& a, const LLVector2& b)
+{
+ F32 angle = angle_between(a, b);
+ F32 rhombus_square = a[VX] * b[VY] - b[VX] * a[VY];
+ return rhombus_square < 0 ? -angle : angle;
+}
+
+bool are_parallel(const LLVector2 &a, const LLVector2 &b, F32 epsilon)
{
LLVector2 an = a;
LLVector2 bn = b;
@@ -82,28 +88,28 @@ bool are_parallel(const LLVector2 &a, const LLVector2 &b, float epsilon)
}
-F32 dist_vec(const LLVector2 &a, const LLVector2 &b)
+F32 dist_vec(const LLVector2& a, const LLVector2& b)
{
- F32 x = a.mV[0] - b.mV[0];
- F32 y = a.mV[1] - b.mV[1];
+ F32 x = a.mV[VX] - b.mV[VX];
+ F32 y = a.mV[VY] - b.mV[VY];
return (F32) sqrt( x*x + y*y );
}
-F32 dist_vec_squared(const LLVector2 &a, const LLVector2 &b)
+F32 dist_vec_squared(const LLVector2& a, const LLVector2& b)
{
- F32 x = a.mV[0] - b.mV[0];
- F32 y = a.mV[1] - b.mV[1];
+ F32 x = a.mV[VX] - b.mV[VX];
+ F32 y = a.mV[VY] - b.mV[VY];
return x*x + y*y;
}
-F32 dist_vec_squared2D(const LLVector2 &a, const LLVector2 &b)
+F32 dist_vec_squared2D(const LLVector2& a, const LLVector2& b)
{
- F32 x = a.mV[0] - b.mV[0];
- F32 y = a.mV[1] - b.mV[1];
+ F32 x = a.mV[VX] - b.mV[VX];
+ F32 y = a.mV[VY] - b.mV[VY];
return x*x + y*y;
}
-LLVector2 lerp(const LLVector2 &a, const LLVector2 &b, F32 u)
+LLVector2 lerp(const LLVector2& a, const LLVector2& b, F32 u)
{
return LLVector2(
a.mV[VX] + (b.mV[VX] - a.mV[VX]) * u,
@@ -113,14 +119,14 @@ LLVector2 lerp(const LLVector2 &a, const LLVector2 &b, F32 u)
LLSD LLVector2::getValue() const
{
LLSD ret;
- ret[0] = mV[0];
- ret[1] = mV[1];
+ ret[0] = mV[VX];
+ ret[1] = mV[VY];
return ret;
}
void LLVector2::setValue(const LLSD& sd)
{
- mV[0] = (F32) sd[0].asReal();
- mV[1] = (F32) sd[1].asReal();
+ mV[VX] = (F32) sd[0].asReal();
+ mV[VY] = (F32) sd[1].asReal();
}