From 99cc386cf3cf58c516d45c6bd76b8ceaed3d8b32 Mon Sep 17 00:00:00 2001 From: Woochan Lee Date: Wed, 8 Jan 2025 21:11:37 +0900 Subject: [PATCH] [NUI] remove unnecessary PInvoke calls related with axis --- .../src/public/Common/NUIConstants.cs | 79 ++++----------- src/Tizen.NUI/src/public/Common/Position.cs | 90 ++--------------- src/Tizen.NUI/src/public/Common/Vector2.cs | 72 +++----------- src/Tizen.NUI/src/public/Common/Vector3.cs | 97 ++++--------------- src/Tizen.NUI/src/public/Common/Vector4.cs | 61 ++---------- 5 files changed, 68 insertions(+), 331 deletions(-) diff --git a/src/Tizen.NUI/src/public/Common/NUIConstants.cs b/src/Tizen.NUI/src/public/Common/NUIConstants.cs index 58cb76e2eb1..1b9b3f37908 100755 --- a/src/Tizen.NUI/src/public/Common/NUIConstants.cs +++ b/src/Tizen.NUI/src/public/Common/NUIConstants.cs @@ -1616,96 +1616,55 @@ public static Position BottomRight } } } + /// /// PositionAxis constants. /// /// 3 public struct PositionAxis { + private static readonly Position xaxis = new Position(1.0f, 0.0f, 0.0f); + private static readonly Position yaxis = new Position(0.0f, 1.0f, 0.0f); + private static readonly Position zaxis = new Position(0.0f, 0.0f, 1.0f); + private static readonly Position negativeXaxis = new Position(-1.0f, 0.0f, 0.0f); + private static readonly Position negativeYaxis = new Position(0.0f, -1.0f, 0.0f); + private static readonly Position negativeZaxis = new Position(0.0f, 0.0f, -1.0f); + /// /// The X axis /// /// 3 - public static Position X - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.XaxisGet(); - Position ret = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Position X => xaxis; + /// /// The Y axis /// /// 3 - public static Position Y - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.YaxisGet(); - Position ret = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Position Y => yaxis; + /// /// The Z axis /// /// 3 - public static Position Z - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.ZaxisGet(); - Position ret = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Position Z => zaxis; + /// /// The Negative X axis /// /// 3 - public static Position NegativeX - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.NegativeXaxisGet(); - Position ret = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Position NegativeX => negativeXaxis; + /// /// The Negative Y axis /// /// 3 - public static Position NegativeY - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.NegativeYaxisGet(); - Position ret = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Position NegativeY => negativeYaxis; + /// /// The Negative Z axis /// /// 3 - public static Position NegativeZ - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.NegativeZaxisGet(); - Position ret = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Position NegativeZ => negativeZaxis; } /// diff --git a/src/Tizen.NUI/src/public/Common/Position.cs b/src/Tizen.NUI/src/public/Common/Position.cs index 02a31f4f1dc..b82d16bfc3f 100755 --- a/src/Tizen.NUI/src/public/Common/Position.cs +++ b/src/Tizen.NUI/src/public/Common/Position.cs @@ -29,6 +29,8 @@ namespace Tizen.NUI [Tizen.NUI.Binding.TypeConverter(typeof(PositionTypeConverter))] public class Position : Disposable, ICloneable { + private static readonly Position one = new Position(1.0f, 1.0f, 1.0f); + private static readonly Position zero = new Position(0.0f, 0.0f, 0.0f); /// /// The constructor. @@ -491,31 +493,13 @@ public static Position PivotPointBottomRight /// Constant ( 1.0f, 1.0f, 1.0f ). /// /// 3 - public static Position One - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.OneGet(); - Position ret = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Position One => one; /// /// Constant ( 0.0f, 0.0f, 0.0f ). /// /// 3 - public static Position Zero - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.ZeroGet(); - Position ret = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Position Zero => zero; /// /// The x component. @@ -616,71 +600,17 @@ public float Z } } - internal static Position XAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.XaxisGet(); - Position ret = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - } + internal static Position XAxis => PositionAxis.X; - internal static Position YAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.YaxisGet(); - Position ret = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - } + internal static Position YAxis => PositionAxis.Y; - internal static Position ZAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.ZaxisGet(); - Position ret = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - } + internal static Position ZAxis => PositionAxis.Z; - internal static Position NegativeXAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.NegativeXaxisGet(); - Position ret = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - } + internal static Position NegativeXAxis => PositionAxis.NegativeX; - internal static Position NegativeYAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.NegativeYaxisGet(); - Position ret = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - } + internal static Position NegativeYAxis => PositionAxis.NegativeY; - internal static Position NegativeZAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.NegativeZaxisGet(); - Position ret = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - } + internal static Position NegativeZAxis => PositionAxis.NegativeZ; /// /// The const array subscript operator overload. Should be 0, 1, or 2. diff --git a/src/Tizen.NUI/src/public/Common/Vector2.cs b/src/Tizen.NUI/src/public/Common/Vector2.cs index bb76d1ebd15..e18cca5efe1 100755 --- a/src/Tizen.NUI/src/public/Common/Vector2.cs +++ b/src/Tizen.NUI/src/public/Common/Vector2.cs @@ -28,6 +28,12 @@ namespace Tizen.NUI [Binding.TypeConverter(typeof(Vector2TypeConverter))] public class Vector2 : Disposable, ICloneable { + private static readonly Vector2 one = new Vector2(1.0f, 1.0f); + private static readonly Vector2 zero = new Vector2(0.0f, 0.0f); + private static readonly Vector2 xaxis = new Vector2(1.0f, 0.0f); + private static readonly Vector2 yaxis = new Vector2(0.0f, 1.0f); + private static readonly Vector2 negativeXaxis = new Vector2(-1.0f, 0.0f); + private static readonly Vector2 negativeYaxis = new Vector2(0.0f, -1.0f); /// /// The default constructor initializes the vector to 0. @@ -111,92 +117,38 @@ internal Vector2(Vector2ChangedCallback cb, Vector2 other) : this(cb, other.X, o /// Actual value is (1.0f,1.0f). /// /// 3 - public static Vector2 One - { - get - { - global::System.IntPtr cPtr = Interop.Vector2.OneGet(); - Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Vector2 One => one; /// /// The vector representing the x-axis. /// /// 3 - public static Vector2 XAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector2.XaxisGet(); - Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Vector2 XAxis => xaxis; /// /// The vector representing the y-axis. /// /// 3 - public static Vector2 YAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector2.YaxisGet(); - Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Vector2 YAxis => yaxis; /// /// The vector representing the negative x-axis. /// /// 3 - public static Vector2 NegativeXAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector2.NegativeXaxisGet(); - Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Vector2 NegativeXAxis => negativeXaxis; /// /// The vector representing the negative y-axis. /// /// 3 - public static Vector2 NegativeYAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector2.NegativeYaxisGet(); - Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Vector2 NegativeYAxis => negativeYaxis; /// /// A Vector2 object representing the zero vector. /// Actual value is (0.0f, 0.0f). /// /// 3 - public static Vector2 Zero - { - get - { - global::System.IntPtr cPtr = Interop.Vector2.ZeroGet(); - Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Vector2 Zero => zero; /// /// The x component. diff --git a/src/Tizen.NUI/src/public/Common/Vector3.cs b/src/Tizen.NUI/src/public/Common/Vector3.cs index 6cf28940be8..41cc4fe5a95 100755 --- a/src/Tizen.NUI/src/public/Common/Vector3.cs +++ b/src/Tizen.NUI/src/public/Common/Vector3.cs @@ -28,6 +28,15 @@ namespace Tizen.NUI [Binding.TypeConverter(typeof(Vector3TypeConverter))] public class Vector3 : Disposable, ICloneable { + private static readonly Vector3 one = new Vector3(1.0f, 1.0f, 1.0f); + private static readonly Vector3 zero = new Vector3(0.0f, 0.0f, 0.0f); + private static readonly Vector3 xaxis = new Vector3(1.0f, 0.0f, 0.0f); + private static readonly Vector3 yaxis = new Vector3(0.0f, 1.0f, 0.0f); + private static readonly Vector3 zaxis = new Vector3(0.0f, 0.0f, 1.0f); + private static readonly Vector3 negativeXaxis = new Vector3(-1.0f, 0.0f, 0.0f); + private static readonly Vector3 negativeYaxis = new Vector3(0.0f, -1.0f, 0.0f); + private static readonly Vector3 negativeZaxis = new Vector3(0.0f, 0.0f, -1.0f); + /// /// The default constructor of Vector3 class. /// @@ -96,122 +105,50 @@ internal Vector3(Vector3ChangedCallback cb, float x, float y, float z) : this(In /// Actual value is (1.0f,1.0f,1.0f). /// /// 3 - public static Vector3 One - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.OneGet(); - Vector3 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector3(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Vector3 One => one; /// /// The vector representing the x-axis. /// /// 3 - public static Vector3 XAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.XaxisGet(); - Vector3 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector3(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Vector3 XAxis => xaxis; /// /// The vector representing the y-axis. /// /// 3 - public static Vector3 YAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.YaxisGet(); - Vector3 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector3(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Vector3 YAxis => yaxis; /// /// The vector representing the z-axis. /// /// 3 - public static Vector3 ZAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.ZaxisGet(); - Vector3 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector3(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Vector3 ZAxis => zaxis; /// /// The vector representing the negative x-axis. /// /// 3 - public static Vector3 NegativeXAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.NegativeXaxisGet(); - Vector3 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector3(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Vector3 NegativeXAxis => negativeXaxis; /// /// Th vector representing the negative y-axis. /// /// 3 - public static Vector3 NegativeYAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.NegativeYaxisGet(); - Vector3 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector3(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Vector3 NegativeYAxis => negativeYaxis; /// /// The vector representing the negative z-axis. /// /// 3 - public static Vector3 NegativeZAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.NegativeZaxisGet(); - Vector3 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector3(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Vector3 NegativeZAxis => negativeZaxis; /// /// A Vector2 object representing the zero vector. /// Actual value is (0.0f, 0.0f, 0.0f). /// /// 3 - public static Vector3 Zero - { - get - { - global::System.IntPtr cPtr = Interop.Vector3.ZeroGet(); - Vector3 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector3(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Vector3 Zero => zero; /// /// The x component. diff --git a/src/Tizen.NUI/src/public/Common/Vector4.cs b/src/Tizen.NUI/src/public/Common/Vector4.cs index 325a46332e3..e9b78718d12 100755 --- a/src/Tizen.NUI/src/public/Common/Vector4.cs +++ b/src/Tizen.NUI/src/public/Common/Vector4.cs @@ -28,6 +28,11 @@ namespace Tizen.NUI [Binding.TypeConverter(typeof(Vector4TypeConverter))] public class Vector4 : Disposable, ICloneable { + private static readonly Vector4 one = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); + private static readonly Vector4 zero = new Vector4(0.0f, 0.0f, 0.0f, 0.0f); + private static readonly Vector4 xaxis = new Vector4(1.0f, 0.0f, 0.0f, 0.0f); + private static readonly Vector4 yaxis = new Vector4(0.0f, 1.0f, 0.0f, 0.0f); + private static readonly Vector4 zaxis = new Vector4(0.0f, 0.0f, 1.0f, 0.0f); /// /// The default constructor initializes the vector to 0. @@ -98,80 +103,34 @@ internal Vector4(Vector4ChangedCallback cb, float x, float y, float z, float w) /// Actual value is (1.0f,1.0f,1.0f,1.0f). /// /// 3 - public static Vector4 One - { - get - { - global::System.IntPtr cPtr = Interop.Vector4.OneGet(); - Vector4 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector4(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Vector4 One => one; /// /// The vector representing the x-axis. /// Actual value is (1.0f,0.0f,0.0f,0.0f). /// /// 3 - public static Vector4 XAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector4.XaxisGet(); - Vector4 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector4(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Vector4 XAxis => xaxis; /// /// The vector representing the y-axis. /// Actual value is (0.0f,1.0f,0.0f,0.0f). /// /// 3 - public static Vector4 YAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector4.YaxisGet(); - Vector4 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector4(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Vector4 YAxis => yaxis; /// /// The vector representing the z-axis. /// Actual value is (0.0f,0.0f,1.0f,0.0f). /// /// 3 - public static Vector4 ZAxis - { - get - { - global::System.IntPtr cPtr = Interop.Vector4.ZaxisGet(); - Vector4 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector4(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } - + public static Vector4 ZAxis => zaxis; /// /// A Vector2 object representing the zero vector. /// Actual value is (0.0f, 0.0f, 0.0f, 0.0f). /// /// 3 - public static Vector4 Zero - { - get - { - global::System.IntPtr cPtr = Interop.Vector4.ZeroGet(); - Vector4 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector4(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return ret; - } - } + public static Vector4 Zero => zero; /// /// The x component.