From cc08591d794ca14a310ae4c3fe18f2bcdfa7c543 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Mon, 13 Apr 2020 13:28:08 -0400
Subject: [PATCH] Add string parser to Vector4

---
 indra/llmath/v4math.cpp | 24 ++++++++++++++++++++++++
 indra/llmath/v4math.h   |  5 +++++
 2 files changed, 29 insertions(+)

diff --git a/indra/llmath/v4math.cpp b/indra/llmath/v4math.cpp
index 2782cf29661..0e697919ebc 100644
--- a/indra/llmath/v4math.cpp
+++ b/indra/llmath/v4math.cpp
@@ -35,6 +35,12 @@
 
 // LLVector4
 
+// WARNING: Don't use these for global const definitions!
+// For example: 
+//		const LLQuaternion(0.5f * F_PI, LLVector3d::zero);
+// at the top of a *.cpp file might not give you what you think.
+const LLVector4 LLVector4::zero(0.f, 0.f, 0.f, 0.f);
+
 // Axis-Angle rotations
 
 /*
@@ -102,6 +108,24 @@ std::ostream& operator<<(std::ostream& s, const LLVector4 &a)
 }
 
 
+BOOL LLVector4::parseVector4(const std::string& buf, LLVector4* value)
+{
+	if (buf.empty() || value == NULL)
+	{
+		return FALSE;
+	}
+
+	LLVector4 v;
+	S32 count = sscanf(buf.c_str(), "%lf %lf %lf %lf", v.mV + 0, v.mV + 1, v.mV + 2, v.mV + 3);
+	if (4 == count)
+	{
+		value->setVec(v);
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
 // Non-member functions
 
 F32 angle_between( const LLVector4& a, const LLVector4& b )
diff --git a/indra/llmath/v4math.h b/indra/llmath/v4math.h
index b8835ba2e40..1100f96b6e3 100644
--- a/indra/llmath/v4math.h
+++ b/indra/llmath/v4math.h
@@ -44,6 +44,9 @@ class LLVector4
 {
 	public:
 		F32 mV[LENGTHOFVECTOR4];
+
+		const static LLVector4 zero;
+
 		LLVector4();						// Initializes LLVector4 to (0, 0, 0, 1)
 		explicit LLVector4(const F32 *vec);			// Initializes LLVector4 to (vec[0]. vec[1], vec[2], vec[3])
 		explicit LLVector4(const F64 *vec);			// Initialized LLVector4 to ((F32) vec[0], (F32) vec[1], (F32) vec[3], (F32) vec[4]);
@@ -135,6 +138,8 @@ class LLVector4
 		friend const LLVector4& operator/=(LLVector4 &a, F32 k);				// Return a divided by scaler k
 
 		friend LLVector4 operator-(const LLVector4 &a);					// Return vector -a
+
+		static BOOL parseVector4(const std::string& buf, LLVector4* value);
 };
 
 // Non-member functions 
-- 
GitLab