From ddf126321cd05228a377e49ca23c16c4f0cfe25f Mon Sep 17 00:00:00 2001 From: Mike Mazur Date: Thu, 31 Jul 2008 09:34:13 +0000 Subject: [PATCH] Thanks, M. Igarashi & nlin, for a patch that implements unary minus operator for Vector3 type. Fix issue 1872. --- OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | 5 +++++ .../ScriptEngine/Common/LSL_TypesTestVector3.cs | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs index 21acac2f6d..4fff717e31 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs @@ -126,6 +126,11 @@ namespace OpenSim.Region.ScriptEngine.Common 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 #region Vector & Vector Math diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestVector3.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestVector3.cs index cadee9348d..0a41f92c2e 100644 --- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestVector3.cs +++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestVector3.cs @@ -29,6 +29,7 @@ using System.Collections.Generic; using NUnit.Framework; using OpenSim.Tests.Common; using OpenSim.Region.ScriptEngine.Common; +using vector = OpenSim.Region.ScriptEngine.Common.LSL_Types.Vector3; namespace OpenSim.Region.ScriptEngine.Common.Tests { @@ -39,7 +40,6 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests /// Tests for Vector3 /// [Test] - public void TestDotProduct() { // The numbers we test for. @@ -54,9 +54,16 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests foreach (KeyValuePair ex in expectsSet) { 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); } } + + [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))); + } } }