[NUI] Bind Dot3 / Length3 / LengthSquared3 / Normalize3
authorEunki, Hong <eunkiki.hong@samsung.com>
Thu, 15 May 2025 11:07:03 +0000 (20:07 +0900)
committerWoochan <48237284+lwc0917@users.noreply.github.com>
Thu, 22 May 2025 05:52:09 +0000 (14:52 +0900)
Let we make new API for Vector4 class's length calculation logic
which only using xyz components.

Relative TCT changed:

https://review.tizen.org/gerrit/c/test/tct/csharp/api/+/324327

Relative dali patches:

https://review.tizen.org/gerrit/c/platform/core/uifw/dali-core/+/324234

https://review.tizen.org/gerrit/c/platform/core/uifw/dali-csharp-binder/+/324301

Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
src/Tizen.NUI/src/internal/Interop/Interop.Vector4.cs
src/Tizen.NUI/src/public/Common/Vector4.cs
test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/testcase/public/Common/TSVector4.cs [new file with mode: 0644]

index 44edf543ffeb4fda59b07445049e6c6546887e35..0bfc9e240e830b39d4af3c6a2ccc05ce42a43b50 100755 (executable)
@@ -93,6 +93,9 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Vector4_Dot__SWIG_1")]
             public static extern float Dot(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Vector4_Dot3")]
+            public static extern float Dot3(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Vector4_Dot4")]
             public static extern float Dot4(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
 
@@ -102,12 +105,21 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Vector4_Length")]
             public static extern float Length(global::System.Runtime.InteropServices.HandleRef jarg1);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Vector4_Length3")]
+            public static extern float Length3(global::System.Runtime.InteropServices.HandleRef jarg1);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Vector4_LengthSquared")]
             public static extern float LengthSquared(global::System.Runtime.InteropServices.HandleRef jarg1);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Vector4_LengthSquared3")]
+            public static extern float LengthSquared3(global::System.Runtime.InteropServices.HandleRef jarg1);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Vector4_Normalize")]
             public static extern void Normalize(global::System.Runtime.InteropServices.HandleRef jarg1);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Vector4_Normalize3")]
+            public static extern void Normalize3(global::System.Runtime.InteropServices.HandleRef jarg1);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Vector4_Clamp")]
             public static extern void Clamp(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2, global::System.Runtime.InteropServices.HandleRef jarg3);
 
index 8e8556421d2fcca98d8419b4422023ac91cd75d5..f2dc3c9dd4642b8394dba25e8f96b362b6b526f6 100755 (executable)
@@ -679,6 +679,18 @@ namespace Tizen.NUI
             return ret;
         }
 
+        /// <summary>
+        /// Returns the length of the xyz components of vector.
+        /// </summary>
+        /// <returns>The length of xyz components.</returns>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public float Length3()
+        {
+            float ret = Interop.Vector4.Length3(SwigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
         /// <summary>
         /// Returns the length of the vector squared.<br />
         /// This is faster than using Length() when performing
@@ -693,6 +705,20 @@ namespace Tizen.NUI
             return ret;
         }
 
+        /// <summary>
+        /// Returns the length of the vector squared.<br />
+        /// This is faster than using Length() when performing
+        /// threshold checks as it avoids use of the square root.<br />
+        /// </summary>
+        /// <returns>The length of xyz components vector squared.</returns>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public float LengthSquared3()
+        {
+            float ret = Interop.Vector4.LengthSquared3(SwigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
         /// <summary>
         /// Normalizes the vector.<br />
         /// Sets the vector to unit length whilst maintaining its direction.<br />
@@ -704,6 +730,17 @@ namespace Tizen.NUI
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
+        /// <summary>
+        /// Normalizes the vector of xyz components.<br />
+        /// Sets the vector to unit length whilst maintaining its direction.<br />
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void Normalize3()
+        {
+            Interop.Vector4.Normalize3(SwigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
         /// <summary>
         /// Clamps the vector between minimum and maximum vectors.
         /// </summary>
@@ -746,9 +783,15 @@ namespace Tizen.NUI
             return ret;
         }
 
+        [Obsolete("Do not use this, that will be deprecated. Use Vector4.Dot() instead.")]
         internal float Dot4(Vector4 other)
         {
-            float ret = Interop.Vector4.Dot4(SwigCPtr, Vector4.getCPtr(other));
+            return Dot(other);
+        }
+
+        internal float Dot3(Vector4 other)
+        {
+            float ret = Interop.Vector4.Dot3(SwigCPtr, Vector4.getCPtr(other));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
diff --git a/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/testcase/public/Common/TSVector4.cs b/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/testcase/public/Common/TSVector4.cs
new file mode 100644 (file)
index 0000000..490dc11
--- /dev/null
@@ -0,0 +1,304 @@
+using global::System;
+using NUnit.Framework;
+using NUnit.Framework.TUnit;
+using Tizen.NUI;
+
+namespace Tizen.NUI.Devel.Tests
+{
+    using tlog = Tizen.Log;
+
+    [TestFixture]
+    [Description("public/Common/Vector4")]
+    public class Vector4Test
+    {
+        private const string tag = "NUITEST";
+
+        private const float c_epsilon = 0.0001f;
+
+        [SetUp]
+        public void Init()
+        {
+            tlog.Info(tag, "Init() is called!");
+        }
+
+        [TearDown]
+        public void Destroy()
+        {
+            tlog.Info(tag, "Destroy() is called!");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Vector4 constructor. With float")]
+        [Property("SPEC", "Tizen.NUI.Matrix.Vector4 C")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "CONSTR")]
+        [Property("AUTHOR", "Eunki Hong, eunkiki.hong@samsung.com")]
+        public void Vector4ConstructorWithSingleFloat()
+        {
+            tlog.Debug(tag, $"Vector4ConstructorWithSingleFloat START");
+
+            float testingValue = 1.0f;
+            Vector4 testingTarget = testingValue;
+            Assert.IsNotNull(testingTarget, "Can't create success object Vector4.");
+            Assert.IsInstanceOf<Vector4>(testingTarget, "Should return Vector4 instance.");
+
+            Assert.AreEqual(testingTarget.X, testingValue, c_epsilon, "Value should be equal");
+            Assert.AreEqual(testingTarget.Y, testingValue, c_epsilon, "Value should be equal");
+            Assert.AreEqual(testingTarget.Z, testingValue, c_epsilon, "Value should be equal");
+            Assert.AreEqual(testingTarget.W, testingValue, c_epsilon, "Value should be equal");
+
+            testingTarget.Dispose();
+            tlog.Debug(tag, $"Vector4ConstructorWithSingleFloat END (OK)");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Vector4 Length.")]
+        [Property("SPEC", "Tizen.NUI.Vector4.Length M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("AUTHOR", "Eunki Hong, eunkiki.hong@samsung.com")]
+        public void Vector4LengthV2()
+        {
+            tlog.Debug(tag, $"Vector4LengthV2 START");
+
+            var testingTarget = new Vector4(1.0f, 2.0f, 3.0f, 4.0f);
+            Assert.IsNotNull(testingTarget, "Can't create success object Vector4.");
+            Assert.IsInstanceOf<Vector4>(testingTarget, "Should return Vector4 instance.");
+
+            float targetLengthSquared = 1.0f * 1.0f + 2.0f * 2.0f + 3.0f * 3.0f + 4.0f * 4.0f;
+
+            Assert.AreEqual(testingTarget.Length(), (float)Math.Sqrt(targetLengthSquared), c_epsilon, "Value should be equal");
+
+            testingTarget.Dispose();
+            tlog.Debug(tag, $"Vector4LengthV2 END (OK)");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Vector4 Length3.")]
+        [Property("SPEC", "Tizen.NUI.Vector4.Length3 M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("AUTHOR", "Eunki Hong, eunkiki.hong@samsung.com")]
+        public void Vector4Length3()
+        {
+            tlog.Debug(tag, $"Vector4Length3 START");
+
+            var testingTarget = new Vector4(1.0f, 2.0f, 3.0f, 4.0f);
+            Assert.IsNotNull(testingTarget, "Can't create success object Vector4.");
+            Assert.IsInstanceOf<Vector4>(testingTarget, "Should return Vector4 instance.");
+
+            float targetLengthSquared = 1.0f * 1.0f + 2.0f * 2.0f + 3.0f * 3.0f;
+
+            Assert.AreEqual(testingTarget.Length3(), (float)Math.Sqrt(targetLengthSquared), c_epsilon, "Value should be equal");
+
+            testingTarget.Dispose();
+            tlog.Debug(tag, $"Vector4Length3 END (OK)");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Vector4 LengthSquared.")]
+        [Property("SPEC", "Tizen.NUI.Vector4.LengthSquared M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("AUTHOR", "Eunki Hong, eunkiki.hong@samsung.com")]
+        public void Vector4LengthSquaredV2()
+        {
+            tlog.Debug(tag, $"Vector4LengthSquaredV2 START");
+
+            var testingTarget = new Vector4(1.0f, 2.0f, 3.0f, 4.0f);
+            Assert.IsNotNull(testingTarget, "Can't create success object Vector4.");
+            Assert.IsInstanceOf<Vector4>(testingTarget, "Should return Vector4 instance.");
+
+            float targetLengthSquared = 1.0f * 1.0f + 2.0f * 2.0f + 3.0f * 3.0f + 4.0f * 4.0f;
+
+            Assert.AreEqual(testingTarget.LengthSquared(), targetLengthSquared, c_epsilon, "Value should be equal");
+
+            testingTarget.Dispose();
+            tlog.Debug(tag, $"Vector4LengthSquaredV2 END (OK)");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Vector4 LengthSquared3.")]
+        [Property("SPEC", "Tizen.NUI.Vector4.LengthSquared3 M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("AUTHOR", "Eunki Hong, eunkiki.hong@samsung.com")]
+        public void Vector4LengthSquared3()
+        {
+            tlog.Debug(tag, $"Vector4LengthSquared3 START");
+
+            var testingTarget = new Vector4(1.0f, 2.0f, 3.0f, 4.0f);
+            Assert.IsNotNull(testingTarget, "Can't create success object Vector4.");
+            Assert.IsInstanceOf<Vector4>(testingTarget, "Should return Vector4 instance.");
+
+            float targetLengthSquared = 1.0f * 1.0f + 2.0f * 2.0f + 3.0f * 3.0f;
+
+            Assert.AreEqual(testingTarget.LengthSquared3(), targetLengthSquared, c_epsilon, "Value should be equal");
+
+            testingTarget.Dispose();
+            tlog.Debug(tag, $"Vector4LengthSquared3 END (OK)");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Vector4 Normalize.")]
+        [Property("SPEC", "Tizen.NUI.Vector4.Normalize M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("AUTHOR", "Eunki Hong, eunkiki.hong@samsung.com")]
+        public void Vector4NormalizeV2()
+        {
+            tlog.Debug(tag, $"Vector4NormalizeV2 START");
+
+            var testingTarget = new Vector4(1.0f, 2.0f, 3.0f, 4.0f);
+            Assert.IsNotNull(testingTarget, "Can't create success object Vector4.");
+            Assert.IsInstanceOf<Vector4>(testingTarget, "Should return Vector4 instance.");
+
+            float targetLengthSquared = 1.0f * 1.0f + 2.0f * 2.0f + 3.0f * 3.0f + 4.0f * 4.0f;
+            float targetLength = (float)Math.Sqrt(targetLengthSquared);
+
+            try
+            {
+                testingTarget.Normalize();
+            }
+            catch (Exception e)
+            {
+                tlog.Debug(tag, e.Message.ToString());
+                Assert.Fail("Caught Exception : Failed!");
+            }
+
+            Assert.AreEqual(testingTarget.X, 1.0f / targetLength, c_epsilon, "Value should be equal");
+            Assert.AreEqual(testingTarget.Y, 2.0f / targetLength, c_epsilon, "Value should be equal");
+            Assert.AreEqual(testingTarget.Z, 3.0f / targetLength, c_epsilon, "Value should be equal");
+            Assert.AreEqual(testingTarget.W, 4.0f / targetLength, c_epsilon, "Value should be equal");
+
+            testingTarget.Dispose();
+            tlog.Debug(tag, $"Vector4NormalizeV2 END (OK)");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Vector4 Normalize3.")]
+        [Property("SPEC", "Tizen.NUI.Vector4.Normalize3 M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("AUTHOR", "Eunki Hong, eunkiki.hong@samsung.com")]
+        public void Vector4Normalize3()
+        {
+            tlog.Debug(tag, $"Vector4Normalize3 START");
+
+            var testingTarget = new Vector4(1.0f, 2.0f, 3.0f, 4.0f);
+            Assert.IsNotNull(testingTarget, "Can't create success object Vector4.");
+            Assert.IsInstanceOf<Vector4>(testingTarget, "Should return Vector4 instance.");
+
+            float targetLengthSquared = 1.0f * 1.0f + 2.0f * 2.0f + 3.0f * 3.0f;
+            float targetLength = (float)Math.Sqrt(targetLengthSquared);
+
+            try
+            {
+                testingTarget.Normalize3();
+            }
+            catch (Exception e)
+            {
+                tlog.Debug(tag, e.Message.ToString());
+                Assert.Fail("Caught Exception : Failed!");
+            }
+
+            Assert.AreEqual(testingTarget.X, 1.0f / targetLength, c_epsilon, "Value should be equal");
+            Assert.AreEqual(testingTarget.Y, 2.0f / targetLength, c_epsilon, "Value should be equal");
+            Assert.AreEqual(testingTarget.Z, 3.0f / targetLength, c_epsilon, "Value should be equal");
+            Assert.AreEqual(testingTarget.W, 4.0f, c_epsilon, "Value should be equal");
+
+            testingTarget.Dispose();
+            tlog.Debug(tag, $"Vector4Normalize3 END (OK)");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Vector4 Dot.")]
+        [Property("SPEC", "Tizen.NUI.Vector4.Dot M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("AUTHOR", "Eunki Hong, eunkiki.hong@samsung.com")]
+        public void Vector4Dot()
+        {
+            tlog.Debug(tag, $"Vector4Dot START");
+
+            var testingTarget1 = new Vector4(1.0f, 2.0f, 3.0f, 4.0f);
+            var testingTarget2 = new Vector4(5.0f, 6.0f, 7.0f, 8.0f);
+            Assert.IsNotNull(testingTarget1, "Can't create success object Vector4.");
+            Assert.IsInstanceOf<Vector4>(testingTarget1, "Should return Vector4 instance.");
+            Assert.IsNotNull(testingTarget2, "Can't create success object Vector4.");
+            Assert.IsInstanceOf<Vector4>(testingTarget2, "Should return Vector4 instance.");
+
+            float targetValue = 1.0f * 5.0f + 2.0f * 6.0f + 3.0f * 7.0f + 4.0f * 8.0f;
+
+            Assert.AreEqual(testingTarget1.Dot(testingTarget2), targetValue, c_epsilon, "Value should be equal");
+            Assert.AreEqual(testingTarget2.Dot(testingTarget1), targetValue, c_epsilon, "Value should be equal");
+
+            testingTarget1.Dispose();
+            testingTarget2.Dispose();
+            tlog.Debug(tag, $"Vector4Dot END (OK)");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Vector4 Dot. With Vector3")]
+        [Property("SPEC", "Tizen.NUI.Vector4.Dot M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("AUTHOR", "Eunki Hong, eunkiki.hong@samsung.com")]
+        public void Vector4DotWithVector3()
+        {
+            tlog.Debug(tag, $"Vector4DotWithVector3 START");
+
+            var testingTarget1 = new Vector4(1.0f, 2.0f, 3.0f, 4.0f);
+            var testingTarget2 = new Vector3(5.0f, 6.0f, 7.0f);
+            Assert.IsNotNull(testingTarget1, "Can't create success object Vector4.");
+            Assert.IsInstanceOf<Vector4>(testingTarget1, "Should return Vector4 instance.");
+            Assert.IsNotNull(testingTarget2, "Can't create success object Vector3.");
+            Assert.IsInstanceOf<Vector3>(testingTarget2, "Should return Vector3 instance.");
+
+            float targetValue = 1.0f * 5.0f + 2.0f * 6.0f + 3.0f * 7.0f;
+
+            Assert.AreEqual(testingTarget1.Dot(testingTarget2), targetValue, c_epsilon, "Value should be equal");
+
+            testingTarget1.Dispose();
+            testingTarget2.Dispose();
+            tlog.Debug(tag, $"Vector4DotWithVector3 END (OK)");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Vector4 Dot3.")]
+        [Property("SPEC", "Tizen.NUI.Vector4.Dot3 M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("AUTHOR", "Eunki Hong, eunkiki.hong@samsung.com")]
+        public void Vector4Dot3()
+        {
+            tlog.Debug(tag, $"Vector4Dot3 START");
+
+            var testingTarget1 = new Vector4(1.0f, 2.0f, 3.0f, 4.0f);
+            var testingTarget2 = new Vector4(5.0f, 6.0f, 7.0f, 8.0f);
+            Assert.IsNotNull(testingTarget1, "Can't create success object Vector4.");
+            Assert.IsInstanceOf<Vector4>(testingTarget1, "Should return Vector4 instance.");
+            Assert.IsNotNull(testingTarget2, "Can't create success object Vector4.");
+            Assert.IsInstanceOf<Vector4>(testingTarget2, "Should return Vector4 instance.");
+
+            float targetValue = 1.0f * 5.0f + 2.0f * 6.0f + 3.0f * 7.0f;
+
+            Assert.AreEqual(testingTarget1.Dot3(testingTarget2), targetValue, c_epsilon, "Value should be equal");
+            Assert.AreEqual(testingTarget2.Dot3(testingTarget1), targetValue, c_epsilon, "Value should be equal");
+
+            testingTarget1.Dispose();
+            testingTarget2.Dispose();
+            tlog.Debug(tag, $"Vector4Dot3 END (OK)");
+        }
+    }
+}