Thanks, M. Igarashi & nlin, for a patch that implements unary minus operator

for Vector3 type. Fix issue 1872.
0.6.0-stable
Mike Mazur 2008-07-31 09:34:13 +00:00
parent 2270b25265
commit ddf126321c
2 changed files with 14 additions and 2 deletions

View File

@ -126,6 +126,11 @@ namespace OpenSim.Region.ScriptEngine.Common
return (x == vector.x && x == vector.x && z == vector.z); return (x == vector.x && x == vector.x && z == vector.z);
} }
public static Vector3 operator -(Vector3 vector)
{
return new Vector3(-vector.x, -vector.y, -vector.z);
}
#endregion #endregion
#region Vector & Vector Math #region Vector & Vector Math

View File

@ -29,6 +29,7 @@ using System.Collections.Generic;
using NUnit.Framework; using NUnit.Framework;
using OpenSim.Tests.Common; using OpenSim.Tests.Common;
using OpenSim.Region.ScriptEngine.Common; using OpenSim.Region.ScriptEngine.Common;
using vector = OpenSim.Region.ScriptEngine.Common.LSL_Types.Vector3;
namespace OpenSim.Region.ScriptEngine.Common.Tests namespace OpenSim.Region.ScriptEngine.Common.Tests
{ {
@ -39,7 +40,6 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests
/// Tests for Vector3 /// Tests for Vector3
/// </summary> /// </summary>
[Test] [Test]
public void TestDotProduct() public void TestDotProduct()
{ {
// The numbers we test for. // The numbers we test for.
@ -54,9 +54,16 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests
foreach (KeyValuePair<string, double> ex in expectsSet) foreach (KeyValuePair<string, double> ex in expectsSet)
{ {
parts = ex.Key.Split(delim, System.StringSplitOptions.None); parts = ex.Key.Split(delim, System.StringSplitOptions.None);
result = new LSL_Types.Vector3(parts[0]) * new LSL_Types.Vector3(parts[1]); result = new vector(parts[0]) * new vector(parts[1]);
Assert.AreEqual(ex.Value, result); Assert.AreEqual(ex.Value, result);
} }
} }
[Test]
public void TestUnaryMinusOperator()
{
Assert.AreEqual(new vector(-1, -1, -1), - (new vector(1, 1, 1)));
Assert.AreEqual(new vector(0, 0, 0), - (new vector(0, 0, 0)));
}
} }
} }