[NUI] VectorGraphics.PathCommand: Use IEnumerable<> type
authorJunsuChoi <jsuya.choi@samsung.com>
Fri, 20 Aug 2021 03:15:46 +0000 (12:15 +0900)
committerJunsuChoi <junduru019@gmail.com>
Tue, 24 Aug 2021 05:09:56 +0000 (14:09 +0900)
DO NOT use ArrayList or List in public APIs.
https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/guidelines-for-collections

src/Tizen.NUI/src/internal/Interop/Interop.Shape.cs
src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/PathCommands.cs
src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/Shape.cs
src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/VectorGraphicsConstants.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/CanvasViewSamsple.cs

index a8b842b..0abff18 100755 (executable)
@@ -50,7 +50,7 @@ namespace Tizen.NUI
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Shape_AddPath")]
             [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
-            public static extern void AddPath(global::System.Runtime.InteropServices.HandleRef pShape, [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)] BaseComponents.VectorGraphics.PathCommands.PathCommandType[] commands, uint commandCount, [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)] float[] points, uint pointCount);
+            public static extern void AddPath(global::System.Runtime.InteropServices.HandleRef pShape, [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)] BaseComponents.VectorGraphics.PathCommandType[] commands, uint commandCount, [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)] float[] points, uint pointCount);
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Shape_Close")]
             [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
index a5b459f..111b3d2 100755 (executable)
@@ -16,6 +16,7 @@
 */
 
 using System;
+using System.Collections.Generic;
 using System.ComponentModel;
 
 namespace Tizen.NUI.BaseComponents.VectorGraphics
@@ -27,21 +28,17 @@ namespace Tizen.NUI.BaseComponents.VectorGraphics
     [EditorBrowsable(EditorBrowsableState.Never)]
     public class PathCommands
     {
-        private PathCommandType[] commands; //The array of commands.
-        private uint commandCount; //The number of commands.
-        private float[] points; //The array of points.
-        private uint pointCount; //The number of points.
+        private IEnumerable<PathCommandType> commands; //The array of commands.
+        private IEnumerable<float> points; //The array of points.
 
         /// <summary>
         /// Initialize PathCommands.
         /// </summary>
         /// <param name="commands">The array of commands.</param>
-        /// <param name="commandCount">The number of commands.</param>
         /// <param name="points">The array of points.</param>
-        /// <param name="pointCount">The number of points.</param>
         /// <exception cref="ArgumentNullException"> Thrown when commands or points are null. </exception>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public PathCommands(PathCommandType[] commands, uint commandCount, float[] points, uint pointCount)
+        public PathCommands(IEnumerable<PathCommandType> commands, IEnumerable<float> points)
         {
             if (commands == null)
             {
@@ -52,74 +49,49 @@ namespace Tizen.NUI.BaseComponents.VectorGraphics
                 throw new ArgumentNullException(nameof(points));
             }
             this.commands = commands;
-            this.commandCount = commandCount;
             this.points = points;
-            this.pointCount = pointCount;
-        }
-
-        /// <summary>
-        /// Enumeration specifying the values of the path commands.
-        /// Not to be confused with the path commands from the svg path element (like M, L, Q, H and many others).
-        /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public enum PathCommandType
-        {
-            /// <summary>
-            /// Ends the current sub-path and connects it with its initial point. This command doesn't expect any points.
-            /// </summary>
-            Close = 0,
-            /// <summary>
-            /// Sets a new initial point of the sub-path and a new current point. This command expects 1 point: the starting position.
-            /// </summary>
-            MoveTo,
-            /// <summary>
-            /// Draws a line from the current point to the given point and sets a new value of the current point. This command expects 1 point: the end-position of the line.
-            /// </summary>
-            LineTo,
-            /// <summary>
-            /// Draws a cubic Bezier curve from the current point to the given point using two given control points and sets a new value of the current point. This command expects 3 points: the 1st control-point, the 2nd control-point, the end-point of the curve.
-            /// </summary>
-            CubicTo
         }
 
         /// <summary>
         /// The commands array.
         /// </summary>
-        /// <returns>The array of commands.</returns>
+        /// <exception cref="ArgumentNullException"> Thrown when commands is null. </exception>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public PathCommandType[] GetCommands()
+        public IEnumerable<PathCommandType> Commands
         {
-            return commands;
-        }
-
-        /// <summary>
-        /// The number of commands.
-        /// </summary>
-        /// <returns>The number of commands.</returns>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public uint GetCommandCount()
-        {
-            return commandCount;
+            get
+            {
+                return commands;
+            }
+            set
+            {
+                if (value == null)
+                {
+                    throw new ArgumentNullException(nameof(value));
+                }
+                commands = value;
+            }
         }
 
         /// <summary>
         /// The points array
         /// </summary>
-        /// <returns>The array of points.</returns>
+        /// <exception cref="ArgumentNullException"> Thrown when points is null. </exception>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public float[] GetPoints()
+        public IEnumerable<float> Points
         {
-            return points;
-        }
-
-        /// <summary>
-        /// The number of points.
-        /// </summary>
-        /// <returns>The number of points.</returns>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public uint GetPointCount()
-        {
-            return pointCount;
+            get
+            {
+                return points;
+            }
+            set
+            {
+                if (value == null)
+                {
+                    throw new ArgumentNullException(nameof(value));
+                }
+                points = value;
+            }
         }
     }
 }
index 769b7ca..5f7cbe4 100755 (executable)
@@ -19,6 +19,7 @@ using System;
 using System.ComponentModel;
 using System.Collections.ObjectModel;
 using System.Collections.Generic;
+using System.Linq;
 
 namespace Tizen.NUI.BaseComponents.VectorGraphics
 {
@@ -415,7 +416,27 @@ namespace Tizen.NUI.BaseComponents.VectorGraphics
                 throw new ArgumentNullException(nameof(pathCommands));
             }
 
-            Interop.Shape.AddPath(BaseHandle.getCPtr(this), pathCommands.GetCommands(), pathCommands.GetCommandCount(), pathCommands.GetPoints(), pathCommands.GetPointCount());
+            PathCommandType[] commands = null;
+            if (pathCommands.Commands is PathCommandType[] commandArray)
+            {
+                commands = commandArray;
+            }
+            else
+            {
+                commands = pathCommands.Commands.ToArray();        
+            }
+
+            float[] points = null;            
+            if (pathCommands.Points is float[] pointArray)
+            {
+                points = pointArray;
+            }
+            else
+            {
+                points = pathCommands.Points.ToArray();    
+            }
+            
+            Interop.Shape.AddPath(BaseHandle.getCPtr(this), commands, (uint)commands.Length, points, (uint)points.Length);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
index f16146a..6b1ce39 100755 (executable)
@@ -15,8 +15,8 @@
 *
 */
 using System;
-using System.ComponentModel;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.Diagnostics.CodeAnalysis;
 
 namespace Tizen.NUI.BaseComponents.VectorGraphics
@@ -111,5 +111,30 @@ namespace Tizen.NUI.BaseComponents.VectorGraphics
         /// The gradient pattern is repeated continuously beyond the gradient area until the expected region is filled.
         /// </summary>
         Repeat
-    };
+    }
+
+    /// <summary>
+    /// Enumeration specifying the values of the path commands.
+    /// Not to be confused with the path commands from the svg path element (like M, L, Q, H and many others).
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public enum PathCommandType
+    {
+        /// <summary>
+        /// Ends the current sub-path and connects it with its initial point. This command doesn't expect any points.
+        /// </summary>
+        Close = 0,
+        /// <summary>
+        /// Sets a new initial point of the sub-path and a new current point. This command expects 1 point: the starting position.
+        /// </summary>
+        MoveTo,
+        /// <summary>
+        /// Draws a line from the current point to the given point and sets a new value of the current point. This command expects 1 point: the end-position of the line.
+        /// </summary>
+        LineTo,
+        /// <summary>
+        /// Draws a cubic Bezier curve from the current point to the given point using two given control points and sets a new value of the current point. This command expects 3 points: the 1st control-point, the 2nd control-point, the end-point of the curve.
+        /// </summary>
+        CubicTo
+    }
 }
index ab9f4e6..5adf6a7 100644 (file)
@@ -111,19 +111,17 @@ namespace Tizen.NUI.Samples
             shape.Scale(0.5f);
             shape.Translate(350.0f, 300.0f);
 
-            shape.AddPath(new PathCommands(new PathCommands.PathCommandType[] { PathCommands.PathCommandType.MoveTo,
-                                                                                PathCommands.PathCommandType.LineTo,
-                                                                                PathCommands.PathCommandType.LineTo,
-                                                                                PathCommands.PathCommandType.LineTo,
-                                                                                PathCommands.PathCommandType.LineTo,
-                                                                                PathCommands.PathCommandType.Close },
-                                            6,
+            shape.AddPath(new PathCommands(new PathCommandType[] { PathCommandType.MoveTo,
+                                                                   PathCommandType.LineTo,
+                                                                   PathCommandType.LineTo,
+                                                                   PathCommandType.LineTo,
+                                                                   PathCommandType.LineTo,
+                                                                   PathCommandType.Close },
                                             new float[] {0.0f, -160.0f,
                                                         125.0f, 160.0f,
                                                         -180.0f, -45.0f,
                                                         180.0f, -45.0f,
-                                                        -125.0f, 160.0f },
-                                            10));
+                                                        -125.0f, 160.0f }));
 
             canvasView.AddDrawable(shape);