summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
Diffstat (limited to 'indra')
-rw-r--r--indra/llmath/CMakeLists.txt5
-rw-r--r--indra/llmath/tests/llbbox_test.cpp371
-rw-r--r--indra/llmath/tests/llbboxlocal_test.cpp239
-rw-r--r--indra/llmath/tests/v2math_test.cpp454
-rw-r--r--indra/llmath/tests/v3math_test.cpp573
-rw-r--r--indra/llmath/tests/xform_test.cpp251
6 files changed, 1893 insertions, 0 deletions
diff --git a/indra/llmath/CMakeLists.txt b/indra/llmath/CMakeLists.txt
index 81ccdcdfad..890288936f 100644
--- a/indra/llmath/CMakeLists.txt
+++ b/indra/llmath/CMakeLists.txt
@@ -92,6 +92,11 @@ SET(llmath_TEST_SOURCE_FILES
LL_ADD_PROJECT_UNIT_TESTS(llmath "${llmath_TEST_SOURCE_FILES}")
set(test_libs llmath llcommon ${LLCOMMON_LIBRARIES} ${WINDOWS_LIBRARIES})
+LL_ADD_INTEGRATION_TEST(v2math v2math.cpp "${test_libs}")
+LL_ADD_INTEGRATION_TEST(v3math v3math.cpp "${test_libs}")
+LL_ADD_INTEGRATION_TEST(xform xform.cpp "${test_libs}")
+LL_ADD_INTEGRATION_TEST(llbbox llbbox.cpp "${test_libs}")
+LL_ADD_INTEGRATION_TEST(llbboxlocal llbboxlocal.cpp "${test_libs}")
LL_ADD_INTEGRATION_TEST(v3color v3color.cpp "${test_libs}")
LL_ADD_INTEGRATION_TEST(v3dmath v3dmath.cpp "${test_libs}")
LL_ADD_INTEGRATION_TEST(v4color v4color.cpp "${test_libs}")
diff --git a/indra/llmath/tests/llbbox_test.cpp b/indra/llmath/tests/llbbox_test.cpp
new file mode 100644
index 0000000000..2cfdd8b36d
--- /dev/null
+++ b/indra/llmath/tests/llbbox_test.cpp
@@ -0,0 +1,371 @@
+/**
+ * @file llbbox_tut.cpp
+ * @author Martin Reddy
+ * @date 2009-06-25
+ * @brief Test for llbbox.cpp.
+ *
+ * $LicenseInfo:firstyear=2009&license=viewergpl$
+ *
+ * Copyright (c) 2009-2009, Linden Research, Inc.
+ *
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab. Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ *
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ *
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ *
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#include "../test/lltut.h"
+
+#include "../llbbox.h"
+
+
+#define ANGLE (3.14159265f / 2.0f)
+#define APPROX_EQUAL(a, b) dist_vec((a),(b)) < 1e-5
+
+namespace tut
+{
+ struct LLBBoxData
+ {
+ };
+
+ typedef test_group<LLBBoxData> factory;
+ typedef factory::object object;
+}
+
+namespace
+{
+ tut::factory llbbox_test_factory("LLBBox");
+}
+
+namespace tut
+{
+ template<> template<>
+ void object::test<1>()
+ {
+ //
+ // test the default constructor
+ //
+
+ LLBBox bbox1;
+
+ ensure_equals("Default bbox min", bbox1.getMinLocal(), LLVector3(0.0f, 0.0f, 0.0f));
+ ensure_equals("Default bbox max", bbox1.getMaxLocal(), LLVector3(0.0f, 0.0f, 0.0f));
+ ensure_equals("Default bbox pos agent", bbox1.getPositionAgent(), LLVector3(0.0f, 0.0f, 0.0f));
+ ensure_equals("Default bbox rotation", bbox1.getRotation(), LLQuaternion(0.0f, 0.0f, 0.0f, 1.0f));
+ }
+
+ template<> template<>
+ void object::test<2>()
+ {
+ //
+ // test the non-default constructor
+ //
+
+ LLBBox bbox2(LLVector3(1.0f, 2.0f, 3.0f), LLQuaternion(),
+ LLVector3(2.0f, 3.0f, 4.0f), LLVector3(4.0f, 5.0f, 6.0f));
+
+ ensure_equals("Custom bbox min", bbox2.getMinLocal(), LLVector3(2.0f, 3.0f, 4.0f));
+ ensure_equals("Custom bbox max", bbox2.getMaxLocal(), LLVector3(4.0f, 5.0f, 6.0f));
+ ensure_equals("Custom bbox pos agent", bbox2.getPositionAgent(), LLVector3(1.0f, 2.0f, 3.0f));
+ ensure_equals("Custom bbox rotation", bbox2.getRotation(), LLQuaternion(0.0f, 0.0f, 0.0f, 1.0f));
+ }
+
+ template<> template<>
+ void object::test<3>()
+ {
+ //
+ // test the setMinLocal() method
+ //
+ LLBBox bbox2;
+ bbox2.setMinLocal(LLVector3(3.0f, 3.0f, 3.0f));
+ ensure_equals("Custom bbox min (2)", bbox2.getMinLocal(), LLVector3(3.0f, 3.0f, 3.0f));
+ }
+
+ template<> template<>
+ void object::test<4>()
+ {
+ //
+ // test the setMaxLocal() method
+ //
+ LLBBox bbox2;
+ bbox2.setMaxLocal(LLVector3(5.0f, 5.0f, 5.0f));
+ ensure_equals("Custom bbox max (2)", bbox2.getMaxLocal(), LLVector3(5.0f, 5.0f, 5.0f));
+ }
+
+ template<> template<>
+ void object::test<5>()
+ {
+ //
+ // test the getCenterLocal() method
+ //
+
+ ensure_equals("Default bbox local center", LLBBox().getCenterLocal(), LLVector3(0.0f, 0.0f, 0.0f));
+
+ LLBBox bbox1(LLVector3(1.0f, 2.0f, 3.0f), LLQuaternion(),
+ LLVector3(2.0f, 4.0f, 6.0f), LLVector3(4.0f, 6.0f, 8.0f));
+
+ ensure_equals("Custom bbox center local", bbox1.getCenterLocal(), LLVector3(3.0f, 5.0f, 7.0f));
+
+ LLBBox bbox2(LLVector3(1.0f, 1.0f, 1.0f), LLQuaternion(ANGLE, LLVector3(0.0f, 0.0f, 1.0f)),
+ LLVector3(2.0f, 2.0f, 2.0f), LLVector3(4.0f, 4.0f, 4.0f));
+
+ ensure_equals("Custom bbox center local with rot", bbox2.getCenterLocal(), LLVector3(3.0f, 3.0f, 3.0f));
+ }
+
+ template<> template<>
+ void object::test<6>()
+ {
+ //
+ // test the getCenterAgent()
+ //
+
+ ensure_equals("Default bbox agent center", LLBBox().getCenterAgent(), LLVector3(0.0f, 0.0f, 0.0f));
+
+ LLBBox bbox1(LLVector3(1.0f, 2.0f, 3.0f), LLQuaternion(),
+ LLVector3(2.0f, 4.0f, 6.0f), LLVector3(4.0f, 6.0f, 8.0f));
+
+ ensure_equals("Custom bbox center agent", bbox1.getCenterAgent(), LLVector3(4.0f, 7.0f, 10.0f));
+
+ LLBBox bbox2(LLVector3(1.0f, 1.0f, 1.0f), LLQuaternion(ANGLE, LLVector3(0.0f, 0.0f, 1.0f)),
+ LLVector3(2.0f, 2.0f, 2.0f), LLVector3(4.0f, 4.0f, 4.0f));
+
+ ensure("Custom bbox center agent with rot", APPROX_EQUAL(bbox2.getCenterAgent(), LLVector3(-2.0f, 4.0f, 4.0f)));
+ }
+
+ template<> template<>
+ void object::test<7>()
+ {
+ //
+ // test the getExtentLocal() method
+ //
+
+ ensure_equals("Default bbox local extent", LLBBox().getExtentLocal(), LLVector3(0.0f, 0.0f, 0.0f));
+
+ LLBBox bbox1(LLVector3(1.0f, 2.0f, 3.0f), LLQuaternion(),
+ LLVector3(2.0f, 4.0f, 6.0f), LLVector3(4.0f, 6.0f, 8.0f));
+
+ ensure_equals("Custom bbox extent local", bbox1.getExtentLocal(), LLVector3(2.0f, 2.0f, 2.0f));
+
+ LLBBox bbox2(LLVector3(1.0f, 1.0f, 1.0f), LLQuaternion(ANGLE, LLVector3(0.0f, 0.0f, 1.0f)),
+ LLVector3(2.0f, 2.0f, 2.0f), LLVector3(4.0f, 4.0f, 4.0f));
+
+ ensure_equals("Custom bbox extent local with rot", bbox1.getExtentLocal(), LLVector3(2.0f, 2.0f, 2.0f));
+ }
+
+ template<> template<>
+ void object::test<8>()
+ {
+ //
+ // test the addPointLocal() method
+ //
+
+ LLBBox bbox1;
+ bbox1.addPointLocal(LLVector3(1.0f, 1.0f, 1.0f));
+ bbox1.addPointLocal(LLVector3(3.0f, 3.0f, 3.0f));
+
+ ensure_equals("addPointLocal center local (1)", bbox1.getCenterLocal(), LLVector3(2.0f, 2.0f, 2.0f));
+ ensure_equals("addPointLocal center agent (1)", bbox1.getCenterAgent(), LLVector3(2.0f, 2.0f, 2.0f));
+ ensure_equals("addPointLocal min (1)", bbox1.getMinLocal(), LLVector3(1.0f, 1.0f, 1.0f));
+ ensure_equals("addPointLocal max (1)", bbox1.getMaxLocal(), LLVector3(3.0f, 3.0f, 3.0f));
+
+ bbox1.addPointLocal(LLVector3(0.0f, 0.0f, 0.0f));
+ bbox1.addPointLocal(LLVector3(1.0f, 1.0f, 1.0f));
+ bbox1.addPointLocal(LLVector3(2.0f, 2.0f, 2.0f));
+
+ ensure_equals("addPointLocal center local (2)", bbox1.getCenterLocal(), LLVector3(1.5f, 1.5f, 1.5f));
+ ensure_equals("addPointLocal min (2)", bbox1.getMinLocal(), LLVector3(0.0f, 0.0f, 0.0f));
+ ensure_equals("addPointLocal max (2)", bbox1.getMaxLocal(), LLVector3(3.0f, 3.0f, 3.0f));
+ }
+
+ template<> template<>
+ void object::test<9>()
+ {
+ //
+ // test the addBBoxLocal() method
+ //
+
+ LLBBox bbox1;
+ bbox1.addBBoxLocal(LLBBox(LLVector3(), LLQuaternion(),
+ LLVector3(0.0f, 0.0f, 0.0f), LLVector3(3.0f, 3.0f, 3.0f)));
+
+ ensure_equals("addPointLocal center local (3)", bbox1.getCenterLocal(), LLVector3(1.5f, 1.5f, 1.5f));
+ ensure_equals("addPointLocal min (3)", bbox1.getMinLocal(), LLVector3(0.0f, 0.0f, 0.0f));
+ ensure_equals("addPointLocal max (3)", bbox1.getMaxLocal(), LLVector3(3.0f, 3.0f, 3.0f));
+
+ bbox1.addBBoxLocal(LLBBox(LLVector3(1.0f, 1.0f, 1.0f), LLQuaternion(),
+ LLVector3(5.0f, 5.0f, 5.0f), LLVector3(10.0f, 10.0f, 10.0f)));
+
+ ensure_equals("addPointLocal center local (4)", bbox1.getCenterLocal(), LLVector3(5.0f, 5.0f, 5.0f));
+ ensure_equals("addPointLocal center agent (4)", bbox1.getCenterAgent(), LLVector3(5.0f, 5.0f, 5.0f));
+ ensure_equals("addPointLocal min (4)", bbox1.getMinLocal(), LLVector3(0.0f, 0.0f, 0.0f));
+ ensure_equals("addPointLocal max (4)", bbox1.getMaxLocal(), LLVector3(10.0f, 10.0f, 10.0f));
+ }
+
+ template<> template<>
+ void object::test<10>()
+ {
+ //
+ // test the addPointAgent() method
+ //
+
+ LLBBox bbox1(LLVector3(1.0f, 1.0f, 1.0f), LLQuaternion(1.0, 0.0, 0.0, 1.0),
+ LLVector3(2.0f, 2.0f, 2.0f), LLVector3(4.0f, 4.0f, 4.0f));
+
+ bbox1.addPointAgent(LLVector3(1.0f, 1.0f, 1.0f));
+ bbox1.addPointAgent(LLVector3(3.0f, 3.0f, 3.0f));
+
+ ensure_equals("addPointAgent center local (1)", bbox1.getCenterLocal(), LLVector3(2.0f, 2.0f, -2.0f));
+ ensure_equals("addPointAgent center agent (1)", bbox1.getCenterAgent(), LLVector3(3.0f, 3.0f, 7.0f));
+ ensure_equals("addPointAgent min (1)", bbox1.getMinLocal(), LLVector3(0.0f, 0.0f, -4.0f));
+ ensure_equals("addPointAgent max (1)", bbox1.getMaxLocal(), LLVector3(4.0f, 4.0f, 0.0f));
+ }
+
+ template<> template<>
+ void object::test<11>()
+ {
+ //
+ // test the addBBoxAgent() method
+ //
+
+ LLBBox bbox1(LLVector3(1.0f, 1.0f, 1.0f), LLQuaternion(1.0, 0.0, 0.0, 1.0),
+ LLVector3(2.0f, 2.0f, 2.0f), LLVector3(4.0f, 4.0f, 4.0f));
+
+ bbox1.addPointAgent(LLVector3(1.0f, 1.0f, 1.0f));
+ bbox1.addPointAgent(LLVector3(3.0f, 3.0f, 3.0f));
+
+ bbox1.addBBoxLocal(LLBBox(LLVector3(1.0f, 1.0f, 1.0f), LLQuaternion(),
+ LLVector3(5.0f, 5.0f, 5.0f), LLVector3(10.0f, 10.0f, 10.0f)));
+
+ ensure_equals("addPointAgent center local (2)", bbox1.getCenterLocal(), LLVector3(5.0f, 5.0f, 3.0f));
+ ensure_equals("addPointAgent center agent (2)", bbox1.getCenterAgent(), LLVector3(6.0f, -10.0f, 8.0f));
+ ensure_equals("addPointAgent min (2)", bbox1.getMinLocal(), LLVector3(0.0f, 0.0f, -4.0f));
+ ensure_equals("addPointAgent max (2)", bbox1.getMaxLocal(), LLVector3(10.0f, 10.0f, 10.0f));
+ }
+
+ template<> template<>
+ void object::test<12>()
+ {
+ //
+ // test the expand() method
+ //
+
+ LLBBox bbox1;
+ bbox1.expand(0.0);
+
+ ensure_equals("Zero-expanded Default BBox center", bbox1.getCenterLocal(), LLVector3(0.0f, 0.0f, 0.0f));
+
+ LLBBox bbox2(LLVector3(1.0f, 1.0f, 1.0f), LLQuaternion(),
+ LLVector3(1.0f, 1.0f, 1.0f), LLVector3(3.0f, 3.0f, 3.0f));
+ bbox2.expand(0.0);
+
+ ensure_equals("Zero-expanded center local", bbox2.getCenterLocal(), LLVector3(2.0f, 2.0f, 2.0f));
+ ensure_equals("Zero-expanded center agent", bbox2.getCenterAgent(), LLVector3(3.0f, 3.0f, 3.0f));
+ ensure_equals("Zero-expanded min", bbox2.getMinLocal(), LLVector3(1.0f, 1.0f, 1.0f));
+ ensure_equals("Zero-expanded max", bbox2.getMaxLocal(), LLVector3(3.0f, 3.0f, 3.0f));
+
+ bbox2.expand(0.5);
+
+ ensure_equals("Positive-expanded center", bbox2.getCenterLocal(), LLVector3(2.0f, 2.0f, 2.0f));
+ ensure_equals("Positive-expanded min", bbox2.getMinLocal(), LLVector3(0.5f, 0.5f, 0.5f));
+ ensure_equals("Positive-expanded max", bbox2.getMaxLocal(), LLVector3(3.5f, 3.5f, 3.5f));
+
+ bbox2.expand(-1.0);
+
+ ensure_equals("Negative-expanded center", bbox2.getCenterLocal(), LLVector3(2.0f, 2.0f, 2.0f));
+ ensure_equals("Negative-expanded min", bbox2.getMinLocal(), LLVector3(1.5f, 1.5f, 1.5f));
+ ensure_equals("Negative-expanded max", bbox2.getMaxLocal(), LLVector3(2.5f, 2.5f, 2.5f));
+ }
+
+ template<> template<>
+ void object::test<13>()
+ {
+ //
+ // test the localToAgent() method
+ //
+
+ LLBBox bbox1(LLVector3(1.0f, 1.0f, 1.0f), LLQuaternion(),
+ LLVector3(1.0f, 1.0f, 1.0f), LLVector3(3.0f, 3.0f, 3.0f));
+
+ ensure_equals("localToAgent(1,2,3)", bbox1.localToAgent(LLVector3(1.0f, 2.0f, 3.0f)), LLVector3(2.0f, 3.0f, 4.0f));
+
+ LLBBox bbox2(LLVector3(1.0f, 1.0f, 1.0f), LLQuaternion(ANGLE, LLVector3(1.0f, 0.0f, 0.0f)),
+ LLVector3(1.0f, 1.0f, 1.0f), LLVector3(3.0f, 3.0f, 3.0f));
+
+ ensure("localToAgent(1,2,3) rot", APPROX_EQUAL(bbox2.localToAgent(LLVector3(1.0f, 2.0f, 3.0f)), LLVector3(2.0f, -2.0f, 3.0f)));
+ }
+
+ template<> template<>
+ void object::test<14>()
+ {
+ //
+ // test the agentToLocal() method
+ //
+
+ LLBBox bbox1(LLVector3(1.0f, 1.0f, 1.0f), LLQuaternion(),
+ LLVector3(1.0f, 1.0f, 1.0f), LLVector3(3.0f, 3.0f, 3.0f));
+
+ ensure_equals("agentToLocal(1,2,3)", bbox1.agentToLocal(LLVector3(1.0f, 2.0f, 3.0f)), LLVector3(0.0f, 1.0f, 2.0f));
+ ensure_equals("agentToLocal(localToAgent)", bbox1.agentToLocal(bbox1.localToAgent(LLVector3(1.0f, 2.0f, 3.0f))),
+ LLVector3(1.0f, 2.0f, 3.0f));
+
+ LLBBox bbox2(LLVector3(1.0f, 1.0f, 1.0f), LLQuaternion(ANGLE, LLVector3(1.0f, 0.0f, 0.0f)),
+ LLVector3(1.0f, 1.0f, 1.0f), LLVector3(3.0f, 3.0f, 3.0f));
+
+ ensure("agentToLocal(1,2,3) rot", APPROX_EQUAL(bbox2.agentToLocal(LLVector3(1.0f, 2.0f, 3.0f)), LLVector3(0.0f, 2.0f, -1.0f)));
+ ensure("agentToLocal(localToAgent) rot", APPROX_EQUAL(bbox2.agentToLocal(bbox2.localToAgent(LLVector3(1.0f, 2.0f, 3.0f))),
+ LLVector3(1.0f, 2.0f, 3.0f)));
+ }
+
+ template<> template<>
+ void object::test<15>()
+ {
+ //
+ // test the containsPointLocal() method
+ //
+
+ LLBBox bbox1(LLVector3(1.0f, 1.0f, 1.0f), LLQuaternion(),
+ LLVector3(1.0f, 2.0f, 3.0f), LLVector3(3.0f, 4.0f, 5.0f));
+
+ ensure("containsPointLocal(0,0,0)", bbox1.containsPointLocal(LLVector3(0.0f, 0.0f, 0.0f)) == FALSE);
+ ensure("containsPointLocal(1,2,3)", bbox1.containsPointLocal(LLVector3(1.0f, 2.0f, 3.0f)) == TRUE);
+ ensure("containsPointLocal(0.999,2,3)", bbox1.containsPointLocal(LLVector3(0.999f, 2.0f, 3.0f)) == FALSE);
+ ensure("containsPointLocal(3,4,5)", bbox1.containsPointLocal(LLVector3(3.0f, 4.0f, 5.0f)) == TRUE);
+ ensure("containsPointLocal(3,4,5.001)", bbox1.containsPointLocal(LLVector3(3.0f, 4.0f, 5.001f)) == FALSE);
+ }
+
+ template<> template<>
+ void object::test<16>()
+ {
+ //
+ // test the containsPointAgent() method
+ //
+
+ LLBBox bbox1(LLVector3(1.0f, 1.0f, 1.0f), LLQuaternion(),
+ LLVector3(1.0f, 2.0f, 3.0f), LLVector3(3.0f, 4.0f, 5.0f));
+
+ ensure("containsPointAgent(0,0,0)", bbox1.containsPointAgent(LLVector3(0.0f, 0.0f, 0.0f)) == FALSE);
+ ensure("containsPointAgent(2,3,4)", bbox1.containsPointAgent(LLVector3(2.0f, 3.0f, 4.0f)) == TRUE);
+ ensure("containsPointAgent(2,2.999,4)", bbox1.containsPointAgent(LLVector3(2.0f, 2.999f, 4.0f)) == FALSE);
+ ensure("containsPointAgent(4,5,6)", bbox1.containsPointAgent(LLVector3(4.0f, 5.0f, 6.0f)) == TRUE);
+ ensure("containsPointAgent(4,5.001,6)", bbox1.containsPointAgent(LLVector3(4.0f, 5.001f, 6.0f)) == FALSE);
+ }
+}
+
diff --git a/indra/llmath/tests/llbboxlocal_test.cpp b/indra/llmath/tests/llbboxlocal_test.cpp
new file mode 100644
index 0000000000..92cdf1c8a2
--- /dev/null
+++ b/indra/llmath/tests/llbboxlocal_test.cpp
@@ -0,0 +1,239 @@
+/**
+ * @file llbboxlocal_tut.cpp
+ * @author Martin Reddy
+ * @date 2009-06-25
+ * @brief Test for llbboxlocal.cpp.
+ *
+ * $LicenseInfo:firstyear=2009&license=viewergpl$
+ *
+ * Copyright (c) 2009-2009, Linden Research, Inc.
+ *
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab. Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ *
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ *
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ *
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#include "../test/lltut.h"
+
+#include "../llbboxlocal.h"
+
+
+namespace tut
+{
+ struct LLBBoxLocalData
+ {
+ };
+
+ typedef test_group<LLBBoxLocalData> factory;
+ typedef factory::object object;
+}
+
+namespace
+{
+ tut::factory llbboxlocal_test_factory("LLBBoxLocal");
+}
+
+namespace tut
+{
+ template<> template<>
+ void object::test<1>()
+ {
+ //
+ // test the default constructor
+ //
+
+ LLBBoxLocal bbox1;
+
+ ensure_equals("Default bbox min", bbox1.getMin(), LLVector3(0.0f, 0.0f, 0.0f));
+ ensure_equals("Default bbox max", bbox1.getMax(), LLVector3(0.0f, 0.0f, 0.0f));
+ }
+
+ template<> template<>
+ void object::test<2>()
+ {
+ //
+ // test the non-default constructor
+ //
+
+ LLBBoxLocal bbox2(LLVector3(-1.0f, -2.0f, 0.0f), LLVector3(1.0f, 2.0f, 3.0f));
+
+ ensure_equals("Custom bbox min", bbox2.getMin(), LLVector3(-1.0f, -2.0f, 0.0f));
+ ensure_equals("Custom bbox max", bbox2.getMax(), LLVector3(1.0f, 2.0f, 3.0f));
+ }
+
+ template<> template<>
+ void object::test<3>()
+ {
+ //
+ // test the setMin()
+ //
+ // N.B. no validation is currently performed to ensure that the min
+ // and max vectors are actually the min/max values.
+ //
+
+ LLBBoxLocal bbox2;
+ bbox2.setMin(LLVector3(1.0f, 2.0f, 3.0f));
+
+ ensure_equals("Custom bbox min (2)", bbox2.getMin(), LLVector3(1.0f, 2.0f, 3.0f));
+ }
+
+ template<> template<>
+ void object::test<4>()
+ {
+ //
+ // test the setMax()
+ //
+ // N.B. no validation is currently performed to ensure that the min
+ // and max vectors are actually the min/max values.
+ //
+
+ LLBBoxLocal bbox2;
+ bbox2.setMax(LLVector3(10.0f, 20.0f, 30.0f));
+
+ ensure_equals("Custom bbox max (2)", bbox2.getMax(), LLVector3(10.0f, 20.0f, 30.0f));
+ }
+
+ template<> template<>
+ void object::test<5>()
+ {
+ //
+ // test the getCenter() method
+ //
+
+ ensure_equals("Default bbox center", LLBBoxLocal().getCenter(), LLVector3(0.0f, 0.0f, 0.0f));
+
+ LLBBoxLocal bbox1(LLVector3(-1.0f, -1.0f, -1.0f), LLVector3(0.0f, 0.0f, 0.0f));
+
+ ensure_equals("Custom bbox center", bbox1.getCenter(), LLVector3(-0.5f, -0.5f, -0.5f));
+
+ LLBBoxLocal bbox2(LLVector3(0.0f, 0.0f, 0.0f), LLVector3(-1.0f, -1.0f, -1.0f));
+
+ ensure_equals("Invalid bbox center", bbox2.getCenter(), LLVector3(-0.5f, -0.5f, -0.5f));
+ }
+
+ template<> template<>
+ void object::test<6>()
+ {
+ //
+ // test the getExtent() method
+ //
+
+ LLBBoxLocal bbox2(LLVector3(0.0f, 0.0f, 0.0f), LLVector3(-1.0f, -1.0f, -1.0f));
+
+ ensure_equals("Default bbox extent", LLBBoxLocal().getExtent(), LLVector3(0.0f, 0.0f, 0.0f));
+
+ LLBBoxLocal bbox3(LLVector3(-1.0f, -1.0f, -1.0f), LLVector3(1.0f, 2.0f, 0.0f));
+
+ ensure_equals("Custom bbox extent", bbox3.getExtent(), LLVector3(2.0f, 3.0f, 1.0f));
+ }
+
+ template<> template<>
+ void object::test<7>()
+ {
+ //
+ // test the addPoint() method
+ //
+ // N.B. if you create an empty bbox and then add points,
+ // the vector (0, 0, 0) will always be part of the bbox.
+ // (Fixing this would require adding a bool to the class size).
+ //
+
+ LLBBoxLocal bbox1;
+ bbox1.addPoint(LLVector3(-1.0f, -2.0f, -3.0f));
+ bbox1.addPoint(LLVector3(3.0f, 4.0f, 5.0f));
+
+ ensure_equals("Custom BBox center (1)", bbox1.getCenter(), LLVector3(1.0f, 1.0f, 1.0f));
+ ensure_equals("Custom BBox min (1)", bbox1.getMin(), LLVector3(-1.0f, -2.0f, -3.0f));
+ ensure_equals("Custom BBox max (1)", bbox1.getMax(), LLVector3(3.0f, 4.0f, 5.0f));
+
+ bbox1.addPoint(LLVector3(0.0f, 0.0f, 0.0f));
+ bbox1.addPoint(LLVector3(1.0f, 2.0f, 3.0f));
+ bbox1.addPoint(LLVector3(2.0f, 2.0f, 2.0f));
+
+ ensure_equals("Custom BBox center (2)", bbox1.getCenter(), LLVector3(1.0f, 1.0f, 1.0f));
+ ensure_equals("Custom BBox min (2)", bbox1.getMin(), LLVector3(-1.0f, -2.0f, -3.0f));
+ ensure_equals("Custom BBox max (2)", bbox1.getMax(), LLVector3(3.0f, 4.0f, 5.0f));
+
+ bbox1.addPoint(LLVector3(5.0f, 5.0f, 5.0f));
+
+ ensure_equals("Custom BBox center (3)", bbox1.getCenter(), LLVector3(2.0f, 1.5f, 1.0f));
+ ensure_equals("Custom BBox min (3)", bbox1.getMin(), LLVector3(-1.0f, -2.0f, -3.0f));
+ ensure_equals("Custom BBox max (3)", bbox1.getMax(), LLVector3(5.0f, 5.0f, 5.0f));
+ }
+
+ template<> template<>
+ void object::test<8>()
+ {
+ //
+ // test the addBBox() methods
+ //
+ // N.B. if you create an empty bbox and then add points,
+ // the vector (0, 0, 0) will always be part of the bbox.
+ // (Fixing this would require adding a bool to the class size).
+ //
+
+ LLBBoxLocal bbox2(LLVector3(1.0f, 1.0f, 1.0f), LLVector3(2.0f, 2.0f, 2.0f));
+ bbox2.addBBox(LLBBoxLocal(LLVector3(1.5f, 1.5f, 1.5f), LLVector3(3.0f, 3.0f, 3.0f)));
+
+ ensure_equals("Custom BBox center (4)", bbox2.getCenter(), LLVector3(2.0f, 2.0f, 2.0f));
+ ensure_equals("Custom BBox min (4)", bbox2.getMin(), LLVector3(1.0f, 1.0f, 1.0f));
+ ensure_equals("Custom BBox max (4)", bbox2.getMax(), LLVector3(3.0f, 3.0f, 3.0f));
+
+ bbox2.addBBox(LLBBoxLocal(LLVector3(-1.0f, -1.0f, -1.0f), LLVector3(0.0f, 0.0f, 0.0f)));
+
+ ensure_equals("Custom BBox center (5)", bbox2.getCenter(), LLVector3(1.0f, 1.0f, 1.0f));
+ ensure_equals("Custom BBox min (5)", bbox2.getMin(), LLVector3(-1.0f, -1.0f, -1.0f));
+ ensure_equals("Custom BBox max (5)", bbox2.getMax(), LLVector3(3.0f, 3.0f, 3.0f));
+ }
+
+ template<> template<>
+ void object::test<9>()
+ {
+ //
+ // test the expand() method
+ //
+
+ LLBBoxLocal bbox1;
+ bbox1.expand(0.0f);
+
+ ensure_equals("Zero-expanded Default BBox center", bbox1.getCenter(), LLVector3(0.0f, 0.0f, 0.0f));
+
+ LLBBoxLocal bbox2(LLVector3(1.0f, 2.0f, 3.0f), LLVector3(3.0f, 4.0f, 5.0f));
+ bbox2.expand(0.0f);
+
+ ensure_equals("Zero-expanded BBox center", bbox2.getCenter(), LLVector3(2.0f, 3.0f, 4.0f));
+ ensure_equals("Zero-expanded BBox min", bbox2.getMin(), LLVector3(1.0f, 2.0f, 3.0f));
+ ensure_equals("Zero-expanded BBox max", bbox2.getMax(), LLVector3(3.0f, 4.0f, 5.0f));
+
+ bbox2.expand(0.5f);
+
+ ensure_equals("Positive-expanded BBox center", bbox2.getCenter(), LLVector3(2.0f, 3.0f, 4.0f));
+ ensure_equals("Positive-expanded BBox min", bbox2.getMin(), LLVector3(0.5f, 1.5f, 2.5f));
+ ensure_equals("Positive-expanded BBox max", bbox2.getMax(), LLVector3(3.5f, 4.5f, 5.5f));
+
+ bbox2.expand(-1.0f);
+
+ ensure_equals("Negative-expanded BBox center", bbox2.getCenter(), LLVector3(2.0f, 3.0f, 4.0f));
+ ensure_equals("Negative-expanded BBox min", bbox2.getMin(), LLVector3(1.5f, 2.5f, 3.5f));
+ ensure_equals("Negative-expanded BBox max", bbox2.getMax(), LLVector3(2.5f, 3.5f, 4.5f));
+ }
+}
diff --git a/indra/llmath/tests/v2math_test.cpp b/indra/llmath/tests/v2math_test.cpp
new file mode 100644
index 0000000000..748cdf913a
--- /dev/null
+++ b/indra/llmath/tests/v2math_test.cpp
@@ -0,0 +1,454 @@
+/**
+ * @file v2math_tut.cpp
+ * @author Adroit
+ * @date 2007-02
+ * @brief v2math test cases.
+ *
+ * $LicenseInfo:firstyear=2007&license=viewergpl$
+ *
+ * Copyright (c) 2007-2009, Linden Research, Inc.
+ *
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab. Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ *
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ *
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ *
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#include "linden_common.h"
+#include "../test/lltut.h"
+
+#include "../v2math.h"
+
+
+namespace tut
+{
+ struct v2math_data
+ {
+ };
+ typedef test_group<v2math_data> v2math_test;
+ typedef v2math_test::object v2math_object;
+ tut::v2math_test v2math_testcase("v2math");
+
+ template<> template<>
+ void v2math_object::test<1>()
+ {
+ LLVector2 vec2;
+ ensure("LLVector2:Fail to initialize ", (0.f == vec2.mV[VX] && 0.f == vec2.mV[VY]));
+
+ F32 x =2.0f, y = 3.2f ;
+ LLVector2 vec3(x,y);
+ ensure("LLVector2(F32 x, F32 y):Fail to initialize ", (x == vec3.mV[VX]) && (y == vec3.mV[VY]));
+
+ const F32 vec[2] = {3.2f, 4.5f};
+ LLVector2 vec4(vec);
+ ensure("LLVector2(const F32 *vec):Fail to initialize ", (vec[0] == vec4.mV[VX]) && (vec[1] == vec4.mV[VY]));
+
+ vec4.clearVec();
+ ensure("clearVec():Fail to clean the values ", (0.f == vec4.mV[VX] && 0.f == vec4.mV[VY]));
+
+ vec3.zeroVec();
+ ensure("zeroVec():Fail to fill the zero ", (0.f == vec3.mV[VX] && 0.f == vec3.mV[VY]));
+ }
+
+ template<> template<>
+ void v2math_object::test<2>()
+ {
+ F32 x = 123.356f, y = 2387.453f;
+ LLVector2 vec2,vec3;
+ vec2.setVec(x, y);
+ ensure("1:setVec: Fail ", (x == vec2.mV[VX]) && (y == vec2.mV[VY]));
+
+ vec3.setVec(vec2);
+ ensure("2:setVec: Fail " ,(vec2 == vec3));
+
+ vec3.zeroVec();
+ const F32 vec[2] = {3.24653f, 457653.4f};
+ vec3.setVec(vec);
+ ensure("3:setVec: Fail ", (vec[0] == vec3.mV[VX]) && (vec[1] == vec3.mV[VY]));
+ }
+
+ template<> template<>
+ void v2math_object::test<3>()
+ {
+ F32 x = 2.2345f, y = 3.5678f ;
+ LLVector2 vec2(x,y);
+ ensure("magVecSquared:Fail ", is_approx_equal(vec2.magVecSquared(), (x*x + y*y)));
+ ensure("magVec:Fail ", is_approx_equal(vec2.magVec(), fsqrtf(x*x + y*y)));
+ }
+
+ template<> template<>
+ void v2math_object::test<4>()
+ {
+ F32 x =-2.0f, y = -3.0f ;
+ LLVector2 vec2(x,y);
+ ensure_equals("abs():Fail", vec2.abs(), TRUE);
+ ensure("abs() x", is_approx_equal(vec2.mV[VX], 2.f));
+ ensure("abs() y", is_approx_equal(vec2.mV[VY], 3.f));
+
+ ensure("isNull():Fail ", FALSE == vec2.isNull()); //Returns TRUE if vector has a _very_small_ length
+
+ x =.00000001f, y = .000001001f;
+ vec2.setVec(x, y);
+ ensure("isNull(): Fail ", TRUE == vec2.isNull());
+ }
+
+ template<> template<>
+ void v2math_object::test<5>()
+ {
+ F32 x =1.f, y = 2.f;
+ LLVector2 vec2(x, y), vec3;
+ vec3 = vec3.scaleVec(vec2);
+ ensure("scaleVec: Fail ", vec3.mV[VX] == 0. && vec3.mV[VY] == 0.);
+ ensure("isExactlyZero(): Fail", TRUE == vec3.isExactlyZero());
+
+ vec3.setVec(2.f, 1.f);
+ vec3 = vec3.scaleVec(vec2);
+ ensure("scaleVec: Fail ", (2.f == vec3.mV[VX]) && (2.f == vec3.mV[VY]));
+ ensure("isExactlyZero():Fail", FALSE == vec3.isExactlyZero());
+ }
+
+ template<> template<>
+ void v2math_object::test<6>()
+ {
+ F32 x1 =1.f, y1 = 2.f, x2 = -2.3f, y2 = 1.11f;
+ F32 val1, val2;
+ LLVector2 vec2(x1, y1), vec3(x2, y2), vec4;
+ vec4 = vec2 + vec3 ;
+ val1 = x1+x2;
+ val2 = y1+y2;
+ ensure("1:operator+ failed",(val1 == vec4.mV[VX]) && ((val2 == vec4.mV[VY])));
+
+ vec2.clearVec();
+ vec3.clearVec();
+ x1 = -.235f, y1 = -24.32f, x2 = -2.3f, y2 = 1.f;
+ vec2.setVec(x1, y1);
+ vec3.setVec(x2, y2);
+ vec4 = vec2 + vec3;
+ val1 = x1+x2;
+ val2 = y1+y2;
+ ensure("2:operator+ failed",(val1 == vec4.mV[VX]) && ((val2 == vec4.mV[VY])));
+ }
+
+ template<> template<>
+ void v2math_object::test<7>()
+ {
+ F32 x1 =1.f, y1 = 2.f, x2 = -2.3f, y2 = 1.11f;
+ F32 val1, val2;
+ LLVector2 vec2(x1, y1), vec3(x2, y2), vec4;
+ vec4 = vec2 - vec3 ;
+ val1 = x1-x2;
+ val2 = y1-y2;
+ ensure("1:operator- failed",(val1 == vec4.mV[VX]) && ((val2 == vec4.mV[VY])));
+
+ vec2.clearVec();
+ vec3.clearVec();
+ vec4.clearVec();
+ x1 = -.235f, y1 = -24.32f, x2 = -2.3f, y2 = 1.f;
+ vec2.setVec(x1, y1);
+ vec3.setVec(x2, y2);
+ vec4 = vec2 - vec3;
+ val1 = x1-x2;
+ val2 = y1-y2;
+ ensure("2:operator- failed",(val1 == vec4.mV[VX]) && ((val2 == vec4.mV[VY])));
+ }
+
+ template<> template<>
+ void v2math_object::test<8>()
+ {
+ F32 x1 =1.f, y1 = 2.f, x2 = -2.3f, y2 = 1.11f;
+ F32 val1, val2;
+ LLVector2 vec2(x1, y1), vec3(x2, y2);
+ val1 = vec2 * vec3;
+ val2 = x1*x2 + y1*y2;
+ ensure("1:operator* failed",(val1 == val2));
+
+ vec3.clearVec();
+ F32 mulVal = 4.332f;
+ vec3 = vec2 * mulVal;
+ val1 = x1*mulVal;
+ val2 = y1*mulVal;
+ ensure("2:operator* failed",(val1 == vec3.mV[VX]) && (val2 == vec3.mV[VY]));
+
+ vec3.clearVec();
+ vec3 = mulVal * vec2;
+ ensure("3:operator* failed",(val1 == vec3.mV[VX]) && (val2 == vec3.mV[VY]));
+ }
+
+ template<> template<>
+ void v2math_object::test<9>()
+ {
+ F32 x1 =1.f, y1 = 2.f, div = 3.2f;
+ F32 val1, val2;
+ LLVector2 vec2(x1, y1), vec3;
+ vec3 = vec2 / div;
+ val1 = x1 / div;
+ val2 = y1 / div;
+ ensure("1:operator/ failed", is_approx_equal(val1, vec3.mV[VX]) && is_approx_equal(val2, vec3.mV[VY]));
+
+ vec3.clearVec();
+ x1 = -.235f, y1 = -24.32f, div = -2.2f;
+ vec2.setVec(x1, y1);
+ vec3 = vec2 / div;
+ val1 = x1 / div;
+ val2 = y1 / div;
+ ensure("2:operator/ failed", is_approx_equal(val1, vec3.mV[VX]) && is_approx_equal(val2, vec3.mV[VY]));
+ }
+
+ template<> template<>
+ void v2math_object::test<10>()
+ {
+ F32 x1 =1.f, y1 = 2.f, x2 = -2.3f, y2 = 1.11f;
+ F32 val1, val2;
+ LLVector2 vec2(x1, y1), vec3(x2, y2), vec4;
+ vec4 = vec2 % vec3;
+ val1 = x1*y2 - x2*y1;
+ val2 = y1*x2 - y2*x1;
+ ensure("1:operator% failed",(val1 == vec4.mV[VX]) && (val2 == vec4.mV[VY]));
+
+ vec2.clearVec();
+ vec3.clearVec();
+ vec4.clearVec();
+ x1 = -.235f, y1 = -24.32f, x2 = -2.3f, y2 = 1.f;
+ vec2.setVec(x1, y1);
+ vec3.setVec(x2, y2);
+ vec4 = vec2 % vec3;
+ val1 = x1*y2 - x2*y1;
+ val2 = y1*x2 - y2*x1;
+ ensure("2:operator% failed",(val1 == vec4.mV[VX]) && (val2 == vec4.mV[VY]));
+ }
+ template<> template<>
+ void v2math_object::test<11>()
+ {
+ F32 x1 =1.f, y1 = 2.f;
+ LLVector2 vec2(x1, y1), vec3(x1, y1);
+ ensure("1:operator== failed",(vec2 == vec3));
+
+ vec2.clearVec();
+ vec3.clearVec();
+ x1 = -.235f, y1 = -24.32f;
+ vec2.setVec(x1, y1);
+ vec3.setVec(vec2);
+ ensure("2:operator== failed",(vec2 == vec3));
+ }
+
+ template<> template<>
+ void v2math_object::test<12>()
+ {
+ F32 x1 = 1.f, y1 = 2.f,x2 = 2.332f, y2 = -1.23f;
+ LLVector2 vec2(x1, y1), vec3(x2, y2);
+ ensure("1:operator!= failed",(vec2 != vec3));
+
+ vec2.clearVec();
+ vec3.clearVec();
+ vec2.setVec(x1, y1);
+ vec3.setVec(vec2);
+ ensure("2:operator!= failed", (FALSE == (vec2 != vec3)));
+ }
+ template<> template<>
+ void v2math_object::test<13>()
+ {
+ F32 x1 = 1.f, y1 = 2.f,x2 = 2.332f, y2 = -1.23f;
+ F32 val1, val2;
+ LLVector2 vec2(x1, y1), vec3(x2, y2);
+ vec2 +=vec3;
+ val1 = x1+x2;
+ val2 = y1+y2;
+ ensure("1:operator+= failed",(val1 == vec2.mV[VX]) && (val2 == vec2.mV[VY]));
+
+ vec2.setVec(x1, y1);
+ vec2 -=vec3;
+ val1 = x1-x2;
+ val2 = y1-y2;
+ ensure("2:operator-= failed",(val1 == vec2.mV[VX]) && (val2 == vec2.mV[VY]));
+
+ vec2.clearVec();
+ vec3.clearVec();
+ x1 = -21.000466f, y1 = 2.98382f,x2 = 0.332f, y2 = -01.23f;
+ vec2.setVec(x1, y1);
+ vec3.setVec(x2, y2);
+ vec2 +=vec3;
+ val1 = x1+x2;
+ val2 = y1+y2;
+ ensure("3:operator+= failed",(val1 == vec2.mV[VX]) && (val2 == vec2.mV[VY]));
+
+ vec2.setVec(x1, y1);
+ vec2 -=vec3;
+ val1 = x1-x2;
+ val2 = y1-y2;
+ ensure("4:operator-= failed", is_approx_equal(val1, vec2.mV[VX]) && is_approx_equal(val2, vec2.mV[VY]));
+ }
+
+ template<> template<>
+ void v2math_object::test<14>()
+ {
+ F32 x1 =1.f, y1 = 2.f;
+ F32 val1, val2, mulVal = 4.332f;
+ LLVector2 vec2(x1, y1);
+ vec2 /=mulVal;
+ val1 = x1 / mulVal;
+ val2 = y1 / mulVal;
+ ensure("1:operator/= failed", is_approx_equal(val1, vec2.mV[VX]) && is_approx_equal(val2, vec2.mV[VY]));
+
+ vec2.clearVec();
+ x1 = .213f, y1 = -2.34f, mulVal = -.23f;
+ vec2.setVec(x1, y1);
+ vec2 /=mulVal;
+ val1 = x1 / mulVal;
+ val2 = y1 / mulVal;
+ ensure("2:operator/= failed", is_approx_equal(val1, vec2.mV[VX]) && is_approx_equal(val2, vec2.mV[VY]));
+ }
+
+ template<> template<>
+ void v2math_object::test<15>()
+ {
+ F32 x1 =1.f, y1 = 2.f;
+ F32 val1, val2, mulVal = 4.332f;
+ LLVector2 vec2(x1, y1);
+ vec2 *=mulVal;
+ val1 = x1*mulVal;
+ val2 = y1*mulVal;
+ ensure("1:operator*= failed",(val1 == vec2.mV[VX]) && (val2 == vec2.mV[VY]));
+
+ vec2.clearVec();
+ x1 = .213f, y1 = -2.34f, mulVal = -.23f;
+ vec2.setVec(x1, y1);
+ vec2 *=mulVal;
+ val1 = x1*mulVal;
+ val2 = y1*mulVal;
+ ensure("2:operator*= failed",(val1 == vec2.mV[VX]) && (val2 == vec2.mV[VY]));
+ }
+
+ template<> template<>
+ void v2math_object::test<16>()
+ {
+ F32 x1 =1.f, y1 = 2.f, x2 = -2.3f, y2 = 1.11f;
+ F32 val1, val2;
+ LLVector2 vec2(x1, y1), vec3(x2, y2);
+ vec2 %= vec3;
+ val1 = x1*y2 - x2*y1;
+ val2 = y1*x2 - y2*x1;
+ ensure("1:operator%= failed",(val1 == vec2.mV[VX]) && (val2 == vec2.mV[VY]));
+ }
+
+ template<> template<>
+ void v2math_object::test<17>()
+ {
+ F32 x1 =1.f, y1 = 2.f;
+ LLVector2 vec2(x1, y1),vec3;
+ vec3 = -vec2;
+ ensure("1:operator- failed",(-vec3 == vec2));
+ }
+
+ template<> template<>
+ void v2math_object::test<18>()
+ {
+ F32 x1 =1.f, y1 = 2.f;
+ std::ostringstream stream1, stream2;
+ LLVector2 vec2(x1, y1),vec3;
+ stream1 << vec2;
+ vec3.setVec(x1, y1);
+ stream2 << vec3;
+ ensure("1:operator << failed",(stream1.str() == stream2.str()));
+ }
+
+ template<> template<>
+ void v2math_object::test<19>()
+ {
+ F32 x1 =1.0f, y1 = 2.0f, x2 = -.32f, y2 = .2234f;
+ LLVector2 vec2(x1, y1),vec3(x2, y2);
+ ensure("1:operator < failed",(vec3 < vec2));
+
+ x1 = 1.0f, y1 = 2.0f, x2 = 1.0f, y2 = 3.2234f;
+ vec2.setVec(x1, y1);
+ vec3.setVec(x2, y2);
+ ensure("2:operator < failed", (FALSE == vec3 < vec2));
+ }
+
+ template<> template<>
+ void v2math_object::test<20>()
+ {
+ F32 x1 =1.0f, y1 = 2.0f;
+ LLVector2 vec2(x1, y1);
+ ensure("1:operator [] failed",( x1 == vec2[0]));
+ ensure("2:operator [] failed",( y1 == vec2[1]));
+
+ vec2.clearVec();
+ x1 = 23.0f, y1 = -.2361f;
+ vec2.setVec(x1, y1);
+ F32 ref1 = vec2[0];
+ ensure("3:operator [] failed", ( ref1 == x1));
+ F32 ref2 = vec2[1];
+ ensure("4:operator [] failed", ( ref2 == y1));
+ }
+
+ template<> template<>
+ void v2math_object::test<21>()
+ {
+ F32 x1 =1.f, y1 = 2.f, x2 = -.32f, y2 = .2234f;
+ F32 val1, val2;
+ LLVector2 vec2(x1, y1),vec3(x2, y2);
+ val1 = dist_vec_squared2D(vec2, vec3);
+ val2 = (x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2);
+ ensure_equals("dist_vec_squared2D values are not equal",val2, val1);
+
+ val1 = dist_vec_squared(vec2, vec3);
+ ensure_equals("dist_vec_squared values are not equal",val2, val1);
+
+ val1 = dist_vec(vec2, vec3);
+ val2 = fsqrtf((x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2));
+ ensure_equals("dist_vec values are not equal",val2, val1);
+ }
+
+ template<> template<>
+ void v2math_object::test<22>()
+ {
+ F32 x1 =1.f, y1 = 2.f, x2 = -.32f, y2 = .2234f,fVal = .0121f;
+ F32 val1, val2;
+ LLVector2 vec2(x1, y1),vec3(x2, y2);
+ LLVector2 vec4 = lerp(vec2, vec3, fVal);
+ val1 = x1 + (x2 - x1) * fVal;
+ val2 = y1 + (y2 - y1) * fVal;
+ ensure("lerp values are not equal", ((val1 == vec4.mV[VX]) && (val2 == vec4.mV[VY])));
+ }
+
+ template<> template<>
+ void v2math_object::test<23>()
+ {
+ F32 x1 =1.f, y1 = 2.f;
+ F32 val1, val2;
+ LLVector2 vec2(x1, y1);
+
+ F32 vecMag = vec2.normVec();
+ F32 mag = fsqrtf(x1*x1 + y1*y1);
+
+ F32 oomag = 1.f / mag;
+ val1 = x1 * oomag;
+ val2 = y1 * oomag;
+
+ ensure("normVec failed", is_approx_equal(val1, vec2.mV[VX]) && is_approx_equal(val2, vec2.mV[VY]) && is_approx_equal(vecMag, mag));
+
+ x1 =.00000001f, y1 = 0.f;
+
+ vec2.setVec(x1, y1);
+ vecMag = vec2.normVec();
+ ensure("normVec failed should be 0.", 0. == vec2.mV[VX] && 0. == vec2.mV[VY] && vecMag == 0.);
+ }
+}
diff --git a/indra/llmath/tests/v3math_test.cpp b/indra/llmath/tests/v3math_test.cpp
new file mode 100644
index 0000000000..00cffde367
--- /dev/null
+++ b/indra/llmath/tests/v3math_test.cpp
@@ -0,0 +1,573 @@
+/**
+ * @file v3math_tut.cpp
+ * @author Adroit
+ * @date 2007-02
+ * @brief v3math test cases.
+ *
+ * $LicenseInfo:firstyear=2007&license=viewergpl$
+ *
+ * Copyright (c) 2007-2009, Linden Research, Inc.
+ *
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab. Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ *
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ *
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ *
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#include "linden_common.h"
+#include "../test/lltut.h"
+#include "llsd.h"
+
+#include "../llquaternion.h"
+#include "../llquantize.h"
+#include "../v3dmath.h"
+#include "../m3math.h"
+#include "../v4math.h"
+#include "../v3math.h"
+
+
+namespace tut
+{
+ struct v3math_data
+ {
+ };
+ typedef test_group<v3math_data> v3math_test;
+ typedef v3math_test::object v3math_object;
+ tut::v3math_test v3math_testcase("v3math");
+
+ template<> template<>
+ void v3math_object::test<1>()
+ {
+ LLVector3 vec3;
+ ensure("1:LLVector3:Fail to initialize ", ((0.f == vec3.mV[VX]) && (0.f == vec3.mV[VY]) && (0.f == vec3.mV[VZ])));
+ F32 x = 2.32f, y = 1.212f, z = -.12f;
+ LLVector3 vec3a(x,y,z);
+ ensure("2:LLVector3:Fail to initialize ", ((2.32f == vec3a.mV[VX]) && (1.212f == vec3a.mV[VY]) && (-.12f == vec3a.mV[VZ])));
+ const F32 vec[3] = {1.2f ,3.2f, -4.2f};
+ LLVector3 vec3b(vec);
+ ensure("3:LLVector3:Fail to initialize ", ((1.2f == vec3b.mV[VX]) && (3.2f == vec3b.mV[VY]) && (-4.2f == vec3b.mV[VZ])));
+ }
+
+ template<> template<>
+ void v3math_object::test<2>()
+ {
+ F32 x = 2.32f, y = 1.212f, z = -.12f;
+ LLVector3 vec3(x,y,z);
+ LLVector3d vector3d(vec3);
+ LLVector3 vec3a(vector3d);
+ ensure("1:LLVector3:Fail to initialize ", vec3 == vec3a);
+ LLVector4 vector4(vec3);
+ LLVector3 vec3b(vector4);
+ ensure("2:LLVector3:Fail to initialize ", vec3 == vec3b);
+ }
+
+ template<> template<>
+ void v3math_object::test<3>()
+ {
+ S32 a = 231;
+ LLSD llsd(a);
+ LLVector3 vec3(llsd);
+ LLSD sd = vec3.getValue();
+ LLVector3 vec3a(sd);
+ ensure("1:LLVector3:Fail to initialize ", (vec3 == vec3a));
+ }
+
+ template<> template<>
+ void v3math_object::test<4>()
+ {
+ S32 a = 231;
+ LLSD llsd(a);
+ LLVector3 vec3(llsd),vec3a;
+ vec3a = vec3;
+ ensure("1:Operator= Fail to initialize " ,(vec3 == vec3a));
+ }
+
+ template<> template<>
+ void v3math_object::test<5>()
+ {
+ F32 x = 2.32f, y = 1.212f, z = -.12f;
+ LLVector3 vec3(x,y,z);
+ ensure("1:isFinite= Fail to initialize ", (TRUE == vec3.isFinite()));//need more test cases:
+ vec3.clearVec();
+ ensure("2:clearVec:Fail to set values ", ((0.f == vec3.mV[VX]) && (0.f == vec3.mV[VY]) && (0.f == vec3.mV[VZ])));
+ vec3.setVec(x,y,z);
+ ensure("3:setVec:Fail to set values ", ((2.32f == vec3.mV[VX]) && (1.212f == vec3.mV[VY]) && (-.12f == vec3.mV[VZ])));
+ vec3.zeroVec();
+ ensure("4:zeroVec:Fail to set values ", ((0.f == vec3.mV[VX]) && (0.f == vec3.mV[VY]) && (0.f == vec3.mV[VZ])));
+ }
+
+ template<> template<>
+ void v3math_object::test<6>()
+ {
+ F32 x = 2.32f, y = 1.212f, z = -.12f;
+ LLVector3 vec3(x,y,z),vec3a;
+ vec3.abs();
+ ensure("1:abs:Fail ", ((x == vec3.mV[VX]) && (y == vec3.mV[VY]) && (-z == vec3.mV[VZ])));
+ vec3a.setVec(vec3);
+ ensure("2:setVec:Fail to initialize ", (vec3a == vec3));
+ const F32 vec[3] = {1.2f ,3.2f, -4.2f};
+ vec3.clearVec();
+ vec3.setVec(vec);
+ ensure("3:setVec:Fail to initialize ", ((1.2f == vec3.mV[VX]) && (3.2f == vec3.mV[VY]) && (-4.2f == vec3.mV[VZ])));
+ vec3a.clearVec();
+ LLVector3d vector3d(vec3);
+ vec3a.setVec(vector3d);
+ ensure("4:setVec:Fail to initialize ", (vec3 == vec3a));
+ LLVector4 vector4(vec3);
+ vec3a.clearVec();
+ vec3a.setVec(vector4);
+ ensure("5:setVec:Fail to initialize ", (vec3 == vec3a));
+ }
+
+ template<> template<>
+ void v3math_object::test<7>()
+ {
+ F32 x = 2.32f, y = 3.212f, z = -.12f;
+ F32 min = 0.0001f, max = 3.0f;
+ LLVector3 vec3(x,y,z);
+ ensure("1:clamp:Fail ", TRUE == vec3.clamp(min, max) && x == vec3.mV[VX] && max == vec3.mV[VY] && min == vec3.mV[VZ]);
+ x = 1.f, y = 2.2f, z = 2.8f;
+ vec3.setVec(x,y,z);
+ ensure("2:clamp:Fail ", FALSE == vec3.clamp(min, max));
+ }
+
+ template<> template<>
+ void v3math_object::test<8>()
+ {
+ F32 x = 2.32f, y = 1.212f, z = -.12f;
+ LLVector3 vec3(x,y,z);
+ ensure("1:magVecSquared:Fail ", is_approx_equal(vec3.magVecSquared(), (x*x + y*y + z*z)));
+ ensure("2:magVec:Fail ", is_approx_equal(vec3.magVec(), fsqrtf(x*x + y*y + z*z)));
+ }
+
+ template<> template<>
+ void v3math_object::test<9>()
+ {
+ F32 x =-2.0f, y = -3.0f, z = 1.23f ;
+ LLVector3 vec3(x,y,z);
+ ensure("1:abs():Fail ", (TRUE == vec3.abs()));
+ ensure("2:isNull():Fail", (FALSE == vec3.isNull())); //Returns TRUE if vector has a _very_small_ length
+ x =.00000001f, y = .000001001f, z = .000001001f;
+ vec3.setVec(x,y,z);
+ ensure("3:isNull(): Fail ", (TRUE == vec3.isNull()));
+ }
+
+ template<> template<>
+ void v3math_object::test<10>()
+ {
+ F32 x =-2.0f, y = -3.0f, z = 1.f ;
+ LLVector3 vec3(x,y,z),vec3a;
+ ensure("1:isExactlyZero():Fail ", (TRUE == vec3a.isExactlyZero()));
+ vec3a = vec3a.scaleVec(vec3);
+ ensure("2:scaleVec: Fail ", vec3a.mV[VX] == 0.f && vec3a.mV[VY] == 0.f && vec3a.mV[VZ] == 0.f);
+ vec3a.setVec(x,y,z);
+ vec3a = vec3a.scaleVec(vec3);
+ ensure("3:scaleVec: Fail ", ((4 == vec3a.mV[VX]) && (9 == vec3a.mV[VY]) &&(1 == vec3a.mV[VZ])));
+ ensure("4:isExactlyZero():Fail ", (FALSE == vec3.isExactlyZero()));
+ }
+
+ template<> template<>
+ void v3math_object::test<11>()
+ {
+ F32 x =20.0f, y = 30.0f, z = 15.f ;
+ F32 angle = 100.f;
+ LLVector3 vec3(x,y,z),vec3a(1.f,2.f,3.f);
+ vec3a = vec3a.rotVec(angle, vec3);
+ LLVector3 vec3b(1.f,2.f,3.f);
+ vec3b = vec3b.rotVec(angle, vec3);
+ ensure_equals("rotVec():Fail" ,vec3b,vec3a);
+ }
+
+ template<> template<>
+ void v3math_object::test<12>()
+ {
+ F32 x =-2.0f, y = -3.0f, z = 1.f ;
+ LLVector3 vec3(x,y,z);
+ ensure("1:operator [] failed",( x == vec3[0]));
+ ensure("2:operator [] failed",( y == vec3[1]));
+ ensure("3:operator [] failed",( z == vec3[2]));
+
+ vec3.clearVec();
+ x = 23.f, y = -.2361f, z = 3.25;
+ vec3.setVec(x,y,z);
+ F32 &ref1 = vec3[0];
+ ensure("4:operator [] failed",( ref1 == vec3[0]));
+ F32 &ref2 = vec3[1];
+ ensure("5:operator [] failed",( ref2 == vec3[1]));
+ F32 &ref3 = vec3[2];
+ ensure("6:operator [] failed",( ref3 == vec3[2]));
+ }
+
+ template<> template<>
+ void v3math_object::test<13>()
+ {
+ F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f;
+ F32 val1, val2, val3;
+ LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2), vec3b;
+ vec3b = vec3 + vec3a ;
+ val1 = x1+x2;
+ val2 = y1+y2;
+ val3 = z1+z2;
+ ensure("1:operator+ failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ]));
+
+ vec3.clearVec();
+ vec3a.clearVec();
+ vec3b.clearVec();
+ x1 = -.235f, y1 = -24.32f,z1 = 2.13f, x2 = -2.3f, y2 = 1.f, z2 = 34.21f;
+ vec3.setVec(x1,y1,z1);
+ vec3a.setVec(x2,y2,z2);
+ vec3b = vec3 + vec3a;
+ val1 = x1+x2;
+ val2 = y1+y2;
+ val3 = z1+z2;
+ ensure("2:operator+ failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ]));
+ }
+
+ template<> template<>
+ void v3math_object::test<14>()
+ {
+ F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f;
+ F32 val1, val2, val3;
+ LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2), vec3b;
+ vec3b = vec3 - vec3a ;
+ val1 = x1-x2;
+ val2 = y1-y2;
+ val3 = z1-z2;
+ ensure("1:operator- failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ]));
+
+ vec3.clearVec();
+ vec3a.clearVec();
+ vec3b.clearVec();
+ x1 = -.235f, y1 = -24.32f,z1 = 2.13f, x2 = -2.3f, y2 = 1.f, z2 = 34.21f;
+ vec3.setVec(x1,y1,z1);
+ vec3a.setVec(x2,y2,z2);
+ vec3b = vec3 - vec3a;
+ val1 = x1-x2;
+ val2 = y1-y2;
+ val3 = z1-z2;
+ ensure("2:operator- failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ]));
+ }
+
+ template<> template<>
+ void v3math_object::test<15>()
+ {
+ F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f;
+ F32 val1, val2, val3;
+ LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2);
+ val1 = vec3 * vec3a;
+ val2 = x1*x2 + y1*y2 + z1*z2;
+ ensure_equals("1:operator* failed",val1,val2);
+
+ vec3a.clearVec();
+ F32 mulVal = 4.332f;
+ vec3a = vec3 * mulVal;
+ val1 = x1*mulVal;
+ val2 = y1*mulVal;
+ val3 = z1*mulVal;
+ ensure("2:operator* failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ]));
+ vec3a.clearVec();
+ vec3a = mulVal * vec3;
+ ensure("3:operator* failed ", (val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ]));
+ }
+
+ template<> template<>
+ void v3math_object::test<16>()
+ {
+ F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f;
+ F32 val1, val2, val3;
+ LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2), vec3b;
+ vec3b = vec3 % vec3a ;
+ val1 = y1*z2 - y2*z1;
+ val2 = z1*x2 -z2*x1;
+ val3 = x1*y2-x2*y1;
+ ensure("1:operator% failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ]));
+
+ vec3.clearVec();
+ vec3a.clearVec();
+ vec3b.clearVec();
+ x1 =112.f, y1 = 22.3f,z1 = 1.2f, x2 = -2.3f, y2 = 341.11f, z2 = 1234.234f;
+ vec3.setVec(x1,y1,z1);
+ vec3a.setVec(x2,y2,z2);
+ vec3b = vec3 % vec3a ;
+ val1 = y1*z2 - y2*z1;
+ val2 = z1*x2 -z2*x1;
+ val3 = x1*y2-x2*y1;
+ ensure("2:operator% failed ", (val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ]));
+ }
+
+ template<> template<>
+ void v3math_object::test<17>()
+ {
+ F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, div = 3.2f;
+ F32 t = 1.f / div, val1, val2, val3;
+ LLVector3 vec3(x1,y1,z1), vec3a;
+ vec3a = vec3 / div;
+ val1 = x1 * t;
+ val2 = y1 * t;
+ val3 = z1 *t;
+ ensure("1:operator/ failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY]) && (val3 == vec3a.mV[VZ]));
+
+ vec3a.clearVec();
+ x1 = -.235f, y1 = -24.32f, z1 = .342f, div = -2.2f;
+ t = 1.f / div;
+ vec3.setVec(x1,y1,z1);
+ vec3a = vec3 / div;
+ val1 = x1 * t;
+ val2 = y1 * t;
+ val3 = z1 *t;
+ ensure("2:operator/ failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY]) && (val3 == vec3a.mV[VZ]));
+ }
+
+ template<> template<>
+ void v3math_object::test<18>()
+ {
+ F32 x1 =1.f, y1 = 2.f,z1 = 1.2f;
+ LLVector3 vec3(x1,y1,z1), vec3a(x1,y1,z1);
+ ensure("1:operator== failed",(vec3 == vec3a));
+
+ vec3a.clearVec();
+ x1 = -.235f, y1 = -24.32f, z1 = .342f;
+ vec3.clearVec();
+ vec3a.clearVec();
+ vec3.setVec(x1,y1,z1);
+ vec3a.setVec(x1,y1,z1);
+ ensure("2:operator== failed ", (vec3 == vec3a));
+ }
+
+ template<> template<>
+ void v3math_object::test<19>()
+ {
+ F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 =112.f, y2 = 2.234f,z2 = 11.2f;;
+ LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2);
+ ensure("1:operator!= failed",(vec3a != vec3));
+
+ vec3.clearVec();
+ vec3.clearVec();
+ vec3a.setVec(vec3);
+ ensure("2:operator!= failed", ( FALSE == (vec3a != vec3)));
+ }
+
+ template<> template<>
+ void v3math_object::test<20>()
+ {
+ F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 =112.f, y2 = 2.2f,z2 = 11.2f;;
+ LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2);
+ vec3a += vec3;
+ F32 val1, val2, val3;
+ val1 = x1+x2;
+ val2 = y1+y2;
+ val3 = z1+z2;
+ ensure("1:operator+= failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ]));
+ }
+
+ template<> template<>
+ void v3math_object::test<21>()
+ {
+ F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 =112.f, y2 = 2.2f,z2 = 11.2f;;
+ LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2);
+ vec3a -= vec3;
+ F32 val1, val2, val3;
+ val1 = x2-x1;
+ val2 = y2-y1;
+ val3 = z2-z1;
+ ensure("1:operator-= failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ]));
+ }
+
+ template<> template<>
+ void v3math_object::test<22>()
+ {
+ F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f;
+ F32 val1,val2,val3;
+ LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2);
+ vec3a *= vec3;
+ val1 = x1*x2;
+ val2 = y1*y2;
+ val3 = z1*z2;
+ ensure("1:operator*= failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ]));
+
+ F32 mulVal = 4.332f;
+ vec3 *=mulVal;
+ val1 = x1*mulVal;
+ val2 = y1*mulVal;
+ val3 = z1*mulVal;
+ ensure("2:operator*= failed ", is_approx_equal(val1, vec3.mV[VX]) && is_approx_equal(val2, vec3.mV[VY]) && is_approx_equal(val3, vec3.mV[VZ]));
+ }
+
+ template<> template<>
+ void v3math_object::test<23>()
+ {
+ F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f;
+ LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2),vec3b;
+ vec3b = vec3a % vec3;
+ vec3a %= vec3;
+ ensure_equals("1:operator%= failed",vec3a,vec3b);
+ }
+
+ template<> template<>
+ void v3math_object::test<24>()
+ {
+ F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, div = 3.2f;
+ F32 t = 1.f / div, val1, val2, val3;
+ LLVector3 vec3a(x1,y1,z1);
+ vec3a /= div;
+ val1 = x1 * t;
+ val2 = y1 * t;
+ val3 = z1 *t;
+ ensure("1:operator/= failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY]) && (val3 == vec3a.mV[VZ]));
+ }
+
+ template<> template<>
+ void v3math_object::test<25>()
+ {
+ F32 x1 =1.f, y1 = 2.f,z1 = 1.2f;
+ LLVector3 vec3(x1,y1,z1), vec3a;
+ vec3a = -vec3;
+ ensure("1:operator- failed",(-vec3a == vec3));
+ }
+
+ template<> template<>
+ void v3math_object::test<26>()
+ {
+ F32 x1 =1.f, y1 = 2.f,z1 = 1.2f;
+ std::ostringstream stream1, stream2;
+ LLVector3 vec3(x1,y1,z1), vec3a;
+ stream1 << vec3;
+ vec3a.setVec(x1,y1,z1);
+ stream2 << vec3a;
+ ensure("1:operator << failed",(stream1.str() == stream2.str()));
+ }
+
+ template<> template<>
+ void v3math_object::test<27>()
+ {
+ F32 x1 =-2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, y2 = 1.11f, z2 = 1234.234f;
+ LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2);
+ ensure("1:operator< failed", (TRUE == vec3 < vec3a));
+ x1 =-2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, y2 = 2.f, z2 = 1234.234f;
+ vec3.setVec(x1,y1,z1);
+ vec3a.setVec(x2,y2,z2);
+ ensure("2:operator< failed ", (TRUE == vec3 < vec3a));
+ x1 =2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f,
+ vec3.setVec(x1,y1,z1);
+ vec3a.setVec(x2,y2,z2);
+ ensure("3:operator< failed ", (FALSE == vec3 < vec3a));
+ }
+
+ template<> template<>
+ void v3math_object::test<28>()
+ {
+ F32 x1 =1.23f, y1 = 2.f,z1 = 4.f;
+ std::string buf("1.23 2. 4");
+ LLVector3 vec3, vec3a(x1,y1,z1);
+ LLVector3::parseVector3(buf, &vec3);
+ ensure_equals("1:parseVector3 failed", vec3, vec3a);
+ }
+
+ template<> template<>
+ void v3math_object::test<29>()
+ {
+ F32 x1 =1.f, y1 = 2.f,z1 = 4.f;
+ LLVector3 vec3(x1,y1,z1),vec3a,vec3b;
+ vec3a.setVec(1,1,1);
+ vec3a.scaleVec(vec3);
+ ensure_equals("1:scaleVec failed", vec3, vec3a);
+ vec3a.clearVec();
+ vec3a.setVec(x1,y1,z1);
+ vec3a.scaleVec(vec3);
+ ensure("2:scaleVec failed", ((1.f ==vec3a.mV[VX])&& (4.f ==vec3a.mV[VY]) && (16.f ==vec3a.mV[VZ])));
+ }
+
+ template<> template<>
+ void v3math_object::test<30>()
+ {
+ F32 x1 =-2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, y2 = 1.11f, z2 = 1234.234f;
+ F32 val = 2.3f,val1,val2,val3;
+ val1 = x1 + (x2 - x1)* val;
+ val2 = y1 + (y2 - y1)* val;
+ val3 = z1 + (z2 - z1)* val;
+ LLVector3 vec3(x1,y1,z1),vec3a(x2,y2,z2);
+ LLVector3 vec3b = lerp(vec3,vec3a,val);
+ ensure("1:lerp failed", ((val1 ==vec3b.mV[VX])&& (val2 ==vec3b.mV[VY]) && (val3 ==vec3b.mV[VZ])));
+ }
+
+ template<> template<>
+ void v3math_object::test<31>()
+ {
+ F32 x1 =-2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, y2 = 1.f, z2 = 1.f;
+ F32 val1,val2;
+ LLVector3 vec3(x1,y1,z1),vec3a(x2,y2,z2);
+ val1 = dist_vec(vec3,vec3a);
+ val2 = fsqrtf((x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2) + (z1 - z2)* (z1 -z2));
+ ensure_equals("1:dist_vec: Fail ",val2, val1);
+ val1 = dist_vec_squared(vec3,vec3a);
+ val2 =((x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2) + (z1 - z2)* (z1 -z2));
+ ensure_equals("2:dist_vec_squared: Fail ",val2, val1);
+ val1 = dist_vec_squared2D(vec3, vec3a);
+ val2 =(x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2);
+ ensure_equals("3:dist_vec_squared2D: Fail ",val2, val1);
+ }
+
+ template<> template<>
+ void v3math_object::test<32>()
+ {
+ F32 x =12.3524f, y = -342.f,z = 4.126341f;
+ LLVector3 vec3(x,y,z);
+ F32 mag = vec3.normVec();
+ mag = 1.f/ mag;
+ F32 val1 = x* mag, val2 = y* mag, val3 = z* mag;
+ ensure("1:normVec: Fail ", is_approx_equal(val1, vec3.mV[VX]) && is_approx_equal(val2, vec3.mV[VY]) && is_approx_equal(val3, vec3.mV[VZ]));
+ x = 0.000000001f, y = 0.f, z = 0.f;
+ vec3.clearVec();
+ vec3.setVec(x,y,z);
+ mag = vec3.normVec();
+ val1 = x* mag, val2 = y* mag, val3 = z* mag;
+ ensure("2:normVec: Fail ", (mag == 0.) && (0. == vec3.mV[VX]) && (0. == vec3.mV[VY])&& (0. == vec3.mV[VZ]));
+ }
+
+ template<> template<>
+ void v3math_object::test<33>()
+ {
+ F32 x = -202.23412f, y = 123.2312f, z = -89.f;
+ LLVector3 vec(x,y,z);
+ vec.snap(2);
+ ensure("1:snap: Fail ", is_approx_equal(-202.23f, vec.mV[VX]) && is_approx_equal(123.23f, vec.mV[VY]) && is_approx_equal(-89.f, vec.mV[VZ]));
+ }
+
+ template<> template<>
+ void v3math_object::test<34>()
+ {
+ F32 x = 10.f, y = 20.f, z = -15.f;
+ F32 x1, y1, z1;
+ F32 lowerxy = 0.f, upperxy = 1.0f, lowerz = -1.0f, upperz = 1.f;
+ LLVector3 vec3(x,y,z);
+ vec3.quantize16(lowerxy,upperxy,lowerz,upperz);
+ x1 = U16_to_F32(F32_to_U16(x, lowerxy, upperxy), lowerxy, upperxy);
+ y1 = U16_to_F32(F32_to_U16(y, lowerxy, upperxy), lowerxy, upperxy);
+ z1 = U16_to_F32(F32_to_U16(z, lowerz, upperz), lowerz, upperz);
+ ensure("1:quantize16: Fail ", is_approx_equal(x1, vec3.mV[VX]) && is_approx_equal(y1, vec3.mV[VY]) && is_approx_equal(z1, vec3.mV[VZ]));
+ LLVector3 vec3a(x,y,z);
+ vec3a.quantize8(lowerxy,upperxy,lowerz,upperz);
+ x1 = U8_to_F32(F32_to_U8(x, lowerxy, upperxy), lowerxy, upperxy);
+ y1 = U8_to_F32(F32_to_U8(y, lowerxy, upperxy), lowerxy, upperxy);
+ z1 = U8_to_F32(F32_to_U8(z, lowerz, upperz), lowerz, upperz);
+ ensure("2:quantize8: Fail ", is_approx_equal(x1, vec3a.mV[VX]) && is_approx_equal(y1, vec3a.mV[VY]) && is_approx_equal(z1, vec3a.mV[VZ]));
+ }
+}
diff --git a/indra/llmath/tests/xform_test.cpp b/indra/llmath/tests/xform_test.cpp
new file mode 100644
index 0000000000..81116a58f0
--- /dev/null
+++ b/indra/llmath/tests/xform_test.cpp
@@ -0,0 +1,251 @@
+/**
+ * @file xform_tut.cpp
+ * @author Adroit
+ * @date March 2007
+ * @brief Test cases for LLXform
+ *
+ * $LicenseInfo:firstyear=2007&license=viewergpl$
+ *
+ * Copyright (c) 2007-2009, Linden Research, Inc.
+ *
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab. Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ *
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ *
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ *
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#include "linden_common.h"
+#include "../test/lltut.h"
+
+#include "../xform.h"
+
+namespace tut
+{
+ struct xform_test
+ {
+ };
+ typedef test_group<xform_test> xform_test_t;
+ typedef xform_test_t::object xform_test_object_t;
+ tut::xform_test_t tut_xform_test("xform_test");
+
+ //test case for init(), getParent(), getRotation(), getPositionW(), getWorldRotation() fns.
+ template<> template<>
+ void xform_test_object_t::test<1>()
+ {
+ LLXform xform_obj;
+ LLVector3 emptyVec(0.f,0.f,0.f);
+ LLVector3 initialScaleVec(1.f,1.f,1.f);
+
+ ensure("LLXform empty constructor failed: ", !xform_obj.getParent() && !xform_obj.isChanged() &&
+ xform_obj.getPosition() == emptyVec &&
+ (xform_obj.getRotation()).isIdentity() &&
+ xform_obj.getScale() == initialScaleVec &&
+ xform_obj.getPositionW() == emptyVec &&
+ (xform_obj.getWorldRotation()).isIdentity() &&
+ !xform_obj.getScaleChildOffset());
+ }
+
+ // test cases for
+ // setScale(const LLVector3& scale)
+ // setScale(const F32 x, const F32 y, const F32 z)
+ // setRotation(const F32 x, const F32 y, const F32 z)
+ // setPosition(const F32 x, const F32 y, const F32 z)
+ // getLocalMat4(LLMatrix4 &mat)
+ template<> template<>
+ void xform_test_object_t::test<2>()
+ {
+ LLMatrix4 llmat4;
+ LLXform xform_obj;
+
+ F32 x = 3.6f;
+ F32 y = 5.5f;
+ F32 z = 4.2f;
+ F32 w = 0.f;
+ F32 posz = z + 2.122f;
+ LLVector3 vec(x, y, z);
+ xform_obj.setScale(x, y, z);
+ xform_obj.setPosition(x, y, posz);
+ ensure("setScale failed: ", xform_obj.getScale() == vec);
+
+ vec.setVec(x, y, posz);
+ ensure("getPosition failed: ", xform_obj.getPosition() == vec);
+
+ x = x * 2.f;
+ y = y + 2.3f;
+ z = posz * 4.f;
+ vec.setVec(x, y, z);
+ xform_obj.setPositionX(x);
+ xform_obj.setPositionY(y);
+ xform_obj.setPositionZ(z);
+ ensure("setPositionX/Y/Z failed: ", xform_obj.getPosition() == vec);
+
+ xform_obj.setScaleChildOffset(TRUE);
+ ensure("setScaleChildOffset failed: ", xform_obj.getScaleChildOffset());
+
+ vec.setVec(x, y, z);
+
+ xform_obj.addPosition(vec);
+ vec += vec;
+ ensure("addPosition failed: ", xform_obj.getPosition() == vec);
+
+ xform_obj.setScale(vec);
+ ensure("setScale vector failed: ", xform_obj.getScale() == vec);
+
+ LLQuaternion quat(x, y, z, w);
+ xform_obj.setRotation(quat);
+ ensure("setRotation quat failed: ", xform_obj.getRotation() == quat);
+
+ xform_obj.setRotation(x, y, z, w);
+ ensure("getRotation 2 failed: ", xform_obj.getRotation() == quat);
+
+ xform_obj.setRotation(x, y, z);
+ quat.setQuat(x,y,z);
+ ensure("setRotation xyz failed: ", xform_obj.getRotation() == quat);
+
+ // LLXform::setRotation(const F32 x, const F32 y, const F32 z)
+ // Does normalization
+ // LLXform::setRotation(const F32 x, const F32 y, const F32 z, const F32 s)
+ // Simply copies the individual values - does not do any normalization.
+ // Is that the expected behavior?
+ }
+
+ // test cases for inline BOOL setParent(LLXform *parent) and getParent() fn.
+ template<> template<>
+ void xform_test_object_t::test<3>()
+ {
+ LLXform xform_obj;
+ LLXform par;
+ LLXform grandpar;
+ xform_obj.setParent(&par);
+ par.setParent(&grandpar);
+ ensure("setParent/getParent failed: ", &par == xform_obj.getParent());
+ ensure("getRoot failed: ", &grandpar == xform_obj.getRoot());
+ ensure("isRoot failed: ", grandpar.isRoot() && !par.isRoot() && !xform_obj.isRoot());
+ ensure("isRootEdit failed: ", grandpar.isRootEdit() && !par.isRootEdit() && !xform_obj.isRootEdit());
+ }
+
+ template<> template<>
+ void xform_test_object_t::test<4>()
+ {
+ LLXform xform_obj;
+ xform_obj.setChanged(LLXform::TRANSLATED | LLXform::ROTATED | LLXform::SCALED);
+ ensure("setChanged/isChanged failed: ", xform_obj.isChanged());
+
+ xform_obj.clearChanged(LLXform::TRANSLATED | LLXform::ROTATED | LLXform::SCALED);
+ ensure("clearChanged failed: ", !xform_obj.isChanged());
+
+ LLVector3 llvect3(12.4f, -5.6f, 0.34f);
+ xform_obj.setScale(llvect3);
+ ensure("setScale did not set SCALED flag: ", xform_obj.isChanged(LLXform::SCALED));
+ xform_obj.setPosition(1.2f, 2.3f, 3.4f);
+ ensure("setScale did not set TRANSLATED flag: ", xform_obj.isChanged(LLXform::TRANSLATED));
+ ensure("TRANSLATED reset SCALED flag: ", xform_obj.isChanged(LLXform::TRANSLATED | LLXform::SCALED));
+ xform_obj.clearChanged(LLXform::SCALED);
+ ensure("reset SCALED failed: ", !xform_obj.isChanged(LLXform::SCALED));
+ xform_obj.setRotation(1, 2, 3, 4);
+ ensure("ROTATION flag not set ", xform_obj.isChanged(LLXform::TRANSLATED | LLXform::ROTATED));
+ xform_obj.setScale(llvect3);
+ ensure("ROTATION flag not set ", xform_obj.isChanged(LLXform::MOVED));
+ }
+
+ //to test init() and getWorldMatrix() fns.
+ template<> template<>
+ void xform_test_object_t::test<5>()
+ {
+ LLXformMatrix formMatrix_obj;
+ formMatrix_obj.init();
+ LLMatrix4 mat4_obj;
+
+ ensure("1. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[0][0]);
+ ensure("2. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[0][1]);
+ ensure("3. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[0][2]);
+ ensure("4. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[0][3]);
+ ensure("5. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[1][0]);
+ ensure("6. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[1][1]);
+ ensure("7. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[1][2]);
+ ensure("8. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[1][3]);
+ ensure("9. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[2][0]);
+ ensure("10. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[2][1]);
+ ensure("11. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[2][2]);
+ ensure("12. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[2][3]);
+ ensure("13. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[3][0]);
+ ensure("14. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[3][1]);
+ ensure("15. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[3][2]);
+ ensure("16. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[3][3]);
+ }
+
+ //to test mMin.clearVec() and mMax.clearVec() fns
+ template<> template<>
+ void xform_test_object_t::test<6>()
+ {
+ LLXformMatrix formMatrix_obj;
+ formMatrix_obj.init();
+ LLVector3 llmin_vec3;
+ LLVector3 llmax_vec3;
+ formMatrix_obj.getMinMax(llmin_vec3, llmax_vec3);
+ ensure("1. The value is not NULL", 0.f == llmin_vec3.mV[0]);
+ ensure("2. The value is not NULL", 0.f == llmin_vec3.mV[1]);
+ ensure("3. The value is not NULL", 0.f == llmin_vec3.mV[2]);
+ ensure("4. The value is not NULL", 0.f == llmin_vec3.mV[0]);
+ ensure("5. The value is not NULL", 0.f == llmin_vec3.mV[1]);
+ ensure("6. The value is not NULL", 0.f == llmin_vec3.mV[2]);
+ }
+
+ //test case of update() fn.
+ template<> template<>
+ void xform_test_object_t::test<7>()
+ {
+ LLXformMatrix formMatrix_obj;
+
+ LLXformMatrix parent;
+ LLVector3 llvecpos(1.0, 2.0, 3.0);
+ LLVector3 llvecpospar(10.0, 20.0, 30.0);
+ formMatrix_obj.setPosition(llvecpos);
+ parent.setPosition(llvecpospar);
+
+ LLVector3 llvecparentscale(1.0, 2.0, 0);
+ parent.setScaleChildOffset(TRUE);
+ parent.setScale(llvecparentscale);
+
+ LLQuaternion quat(1, 2, 3, 4);
+ LLQuaternion quatparent(5, 6, 7, 8);
+ formMatrix_obj.setRotation(quat);
+ parent.setRotation(quatparent);
+ formMatrix_obj.setParent(&parent);
+
+ parent.update();
+ formMatrix_obj.update();
+
+ LLVector3 worldPos = llvecpos;
+ worldPos.scaleVec(llvecparentscale);
+ worldPos *= quatparent;
+ worldPos += llvecpospar;
+
+ LLQuaternion worldRot = quat * quatparent;
+
+ ensure("getWorldPosition failed: ", formMatrix_obj.getWorldPosition() == worldPos);
+ ensure("getWorldRotation failed: ", formMatrix_obj.getWorldRotation() == worldRot);
+
+ ensure("getWorldPosition for parent failed: ", parent.getWorldPosition() == llvecpospar);
+ ensure("getWorldRotation for parent failed: ", parent.getWorldRotation() == quatparent);
+ }
+}
+