diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index d4911d7ff5..aa22b2b1c2 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -5721,13 +5721,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (remain < 7) return; - LSL_Types.LSLInteger flexi = new LSL_Types.LSLInteger(rules.Data[idx++].ToString()); - int softness = Convert.ToInt32(rules.Data[idx++]); - float gravity = (float)Convert.ToDouble(rules.Data[idx++]); - float friction = (float)Convert.ToDouble(rules.Data[idx++]); - float wind = (float)Convert.ToDouble(rules.Data[idx++]); - float tension = (float)Convert.ToDouble(rules.Data[idx++]); - LSL_Types.Vector3 force =new LSL_Types.Vector3(rules.Data[idx++].ToString()); + bool flexi = (LSL_Types.LSLInteger)rules.Data[idx++]; + int softness = (LSL_Types.LSLInteger)rules.Data[idx++]; + float gravity = (float)(LSL_Types.LSLFloat)rules.Data[idx++]; + float friction = (float)(LSL_Types.LSLFloat)rules.Data[idx++]; + float wind = (float)(LSL_Types.LSLFloat)rules.Data[idx++]; + float tension = (float)(LSL_Types.LSLFloat)rules.Data[idx++]; + LSL_Types.Vector3 force = (LSL_Types.Vector3)rules.Data[idx++]; SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force); diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index 3e63808912..85abdb0bac 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs @@ -1569,9 +1569,14 @@ namespace OpenSim.Region.ScriptEngine.Shared #region Operators + static public explicit operator float(LSLFloat f) + { + return (float)f.value; + } + static public explicit operator int(LSLFloat f) { - return (int)f.value; + return (int)f.value; } static public explicit operator uint(LSLFloat f) diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs index c021963f7a..272d06c1f3 100644 --- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs +++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs @@ -395,6 +395,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests } } + /// + /// Tests LSLFloat is correctly cast explicitly to float + /// + [Test] + public void TestExplicitCastLSLFloatToFloat() + { + float testFloat; + float numberAsFloat; + LSL_Types.LSLFloat testLSLFloat; + foreach (double number in m_doubleList) + { + testLSLFloat = new LSL_Types.LSLFloat(number); + numberAsFloat = (float)number; + testFloat = (float)testLSLFloat; + + Assert.That((double)testFloat, new DoubleToleranceConstraint((double)numberAsFloat, _lowPrecisionTolerance)); + } + } + + /// /// Tests the equality (==) operator. /// diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestList.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestList.cs index c1c9ef77c1..9e8d7169f6 100644 --- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestList.cs +++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestList.cs @@ -84,18 +84,79 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests [Test] public void TestConcatenateDouble() { - LSL_Types.list testList = new LSL_Types.list(1, 'a', "test"); - testList += 2.0; + LSL_Types.list testList = new LSL_Types.list(1, 'a', "test"); + testList += 2.0; - Assert.AreEqual(4, testList.Length); - Assert.AreEqual(2.0, testList.Data[3]); - Assert.AreEqual(typeof(double), testList.Data[3].GetType()); + Assert.AreEqual(4, testList.Length); + Assert.AreEqual(2.0, testList.Data[3]); + Assert.AreEqual(typeof(double), testList.Data[3].GetType()); - LSL_Types.list secondTestList = testList + 0.04; + LSL_Types.list secondTestList = testList + 0.04; - Assert.AreEqual(5, secondTestList.Length); - Assert.AreEqual(0.04, secondTestList.Data[4]); - Assert.AreEqual(typeof(double), secondTestList.Data[4].GetType()); + Assert.AreEqual(5, secondTestList.Length); + Assert.AreEqual(0.04, secondTestList.Data[4]); + Assert.AreEqual(typeof(double), secondTestList.Data[4].GetType()); } + + /// + /// Tests casting LSLInteger item to LSLInteger. + /// + [Test] + public void TestCastLSLIntegerItemToLSLInteger() + { + LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(123); + LSL_Types.list testList = new LSL_Types.list(testValue); + + Assert.AreEqual(testValue, (LSL_Types.LSLInteger)testList.Data[0]); + } + + /// + /// Tests casting LSLFloat item to LSLFloat. + /// + [Test] + public void TestCastLSLFloatItemToLSLFloat() + { + LSL_Types.LSLFloat testValue = new LSL_Types.LSLFloat(123.45678987); + LSL_Types.list testList = new LSL_Types.list(testValue); + + Assert.AreEqual(testValue, (LSL_Types.LSLFloat)testList.Data[0]); + } + + /// + /// Tests casting LSLString item to LSLString. + /// + [Test] + public void TestCastLSLStringItemToLSLString() + { + LSL_Types.LSLString testValue = new LSL_Types.LSLString("hello there"); + LSL_Types.list testList = new LSL_Types.list(testValue); + + Assert.AreEqual(testValue, (LSL_Types.LSLString)testList.Data[0]); + } + + /// + /// Tests casting Vector3 item to Vector3. + /// + [Test] + public void TestCastVector3ItemToVector3() + { + LSL_Types.Vector3 testValue = new LSL_Types.Vector3(12.34, 56.987654, 0.00987); + LSL_Types.list testList = new LSL_Types.list(testValue); + + Assert.AreEqual(testValue, (LSL_Types.Vector3)testList.Data[0]); + } + /// + /// Tests casting Quaternion item to Quaternion. + /// + [Test] + public void TestCastQuaternionItemToQuaternion() + { + LSL_Types.Quaternion testValue = new LSL_Types.Quaternion(12.34, 56.44323, 765.983421, 0.00987); + LSL_Types.list testList = new LSL_Types.list(testValue); + + Assert.AreEqual(testValue, (LSL_Types.Quaternion)testList.Data[0]); + } + + } }