From a8a8fb6e1380c37b64963d0968c5af4f64e6f25e Mon Sep 17 00:00:00 2001 From: Micheil Merlin Date: Sat, 20 Nov 2010 17:04:59 -0600 Subject: llVecNorm nant test --- .../ScriptEngine/Shared/Tests/LSL_ApiTest.cs | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs index dfc9aa3..1d55b95 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs @@ -47,6 +47,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests { private const double ANGLE_ACCURACY_IN_RADIANS = 1E-6; + private const double VECTOR_COMPONENT_ACCURACY = 0.0000005d; private LSL_Api m_lslApi; [SetUp] @@ -164,5 +165,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests Assert.Greater(eulerCalc.z, eulerCheck.z - ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler Z lower bounds check fail"); Assert.Less(eulerCalc.z, eulerCheck.z + ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler Z upper bounds check fail"); } + + [Test] + // llVecNorm test. + public void TestllVecNorm() + { + // Check special case for normalizing zero vector. + CheckllVecNorm(new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), new LSL_Types.Vector3(0.0d, 0.0d, 0.0d)); + // Check various vectors. + CheckllVecNorm(new LSL_Types.Vector3(10.0d, 25.0d, 0.0d), new LSL_Types.Vector3(0.371391d, 0.928477d, 0.0d)); + CheckllVecNorm(new LSL_Types.Vector3(1.0d, 0.0d, 0.0d), new LSL_Types.Vector3(1.0d, 0.0d, 0.0d)); + CheckllVecNorm(new LSL_Types.Vector3(-90.0d, 55.0d, 2.0d), new LSL_Types.Vector3(-0.853128d, 0.521356d, 0.018958d)); + CheckllVecNorm(new LSL_Types.Vector3(255.0d, 255.0d, 255.0d), new LSL_Types.Vector3(0.577350d, 0.577350d, 0.577350d)); + } + + public void CheckllVecNorm(LSL_Types.Vector3 vec, LSL_Types.Vector3 vecNormCheck) + { + // Call LSL function to normalize the vector. + LSL_Types.Vector3 vecNorm = m_lslApi.llVecNorm(vec); + // Check each vector component against expected result. + Assert.AreEqual(vecNorm.x, vecNormCheck.x, VECTOR_COMPONENT_ACCURACY, "TestllVecNorm vector check fail on x component"); + Assert.AreEqual(vecNorm.y, vecNormCheck.y, VECTOR_COMPONENT_ACCURACY, "TestllVecNorm vector check fail on y component"); + Assert.AreEqual(vecNorm.z, vecNormCheck.z, VECTOR_COMPONENT_ACCURACY, "TestllVecNorm vector check fail on z component"); + } } } -- cgit v1.1