[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Vector2.cs
1 /*
2  * Copyright(c) 2018 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System;
18 using Tizen.NUI.Binding;
19
20 namespace Tizen.NUI
21 {
22
23     /// <summary>
24     /// A two-dimensional vector.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     [TypeConverter(typeof(Vector2TypeConverter))]
28     public class Vector2 : Disposable
29     {
30         /// <summary>
31         /// swigCMemOwn.
32         /// </summary>
33         /// <since_tizen> 3 </since_tizen>
34         protected bool swigCMemOwn;
35
36         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
37
38         /// <summary>
39         /// The default constructor initializes the vector to 0.
40         /// </summary>
41         /// <since_tizen> 3 </since_tizen>
42         public Vector2() : this(Interop.Vector2.new_Vector2__SWIG_0(), true)
43         {
44             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
45         }
46
47         /// <summary>
48         /// The constructor.
49         /// </summary>
50         /// <param name="x">The x or width component.</param>
51         /// <param name="y">The y or height component.</param>
52         /// <since_tizen> 3 </since_tizen>
53         public Vector2(float x, float y) : this(Interop.Vector2.new_Vector2__SWIG_1(x, y), true)
54         {
55             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
56         }
57
58         /// <summary>
59         /// The conversion constructor from an array of two floats.
60         /// </summary>
61         /// <param name="array">The array of xy.</param>
62         /// <since_tizen> 3 </since_tizen>
63         public Vector2(float[] array) : this(Interop.Vector2.new_Vector2__SWIG_2(array), true)
64         {
65             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
66         }
67
68         /// <summary>
69         /// The constructor.
70         /// </summary>
71         /// <param name="vec3">Vector3 to create this vector from.</param>
72         /// <since_tizen> 3 </since_tizen>
73         public Vector2(Vector3 vec3) : this(Interop.Vector2.new_Vector2__SWIG_3(Vector3.getCPtr(vec3)), true)
74         {
75             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
76         }
77
78         /// <summary>
79         /// The constructor.
80         /// </summary>
81         /// <param name="vec4">Vector4 to create this vector from.</param>
82         /// <since_tizen> 3 </since_tizen>
83         public Vector2(Vector4 vec4) : this(Interop.Vector2.new_Vector2__SWIG_4(Vector4.getCPtr(vec4)), true)
84         {
85             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
86         }
87
88         internal Vector2(global::System.IntPtr cPtr, bool cMemoryOwn)
89         {
90             swigCMemOwn = cMemoryOwn;
91             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
92         }
93
94         /// <summary>
95         /// (1.0f,1.0f).
96         /// </summary>
97         /// <since_tizen> 3 </since_tizen>
98         public static Vector2 One
99         {
100             get
101             {
102                 global::System.IntPtr cPtr = Interop.Vector2.Vector2_ONE_get();
103                 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
104                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
105                 return ret;
106             }
107         }
108
109         /// <summary>
110         /// The vector representing the x-axis.
111         /// </summary>
112         /// <since_tizen> 3 </since_tizen>
113         public static Vector2 XAxis
114         {
115             get
116             {
117                 global::System.IntPtr cPtr = Interop.Vector2.Vector2_XAXIS_get();
118                 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
119                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
120                 return ret;
121             }
122         }
123
124         /// <summary>
125         /// The vector representing the y-axis.
126         /// </summary>
127         /// <since_tizen> 3 </since_tizen>
128         public static Vector2 YAxis
129         {
130             get
131             {
132                 global::System.IntPtr cPtr = Interop.Vector2.Vector2_YAXIS_get();
133                 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
134                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
135                 return ret;
136             }
137         }
138
139         /// <summary>
140         /// The vector representing the negative x-axis.
141         /// </summary>
142         /// <since_tizen> 3 </since_tizen>
143         public static Vector2 NegativeXAxis
144         {
145             get
146             {
147                 global::System.IntPtr cPtr = Interop.Vector2.Vector2_NEGATIVE_XAXIS_get();
148                 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
149                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
150                 return ret;
151             }
152         }
153
154         /// <summary>
155         /// The vector representing the negative y-axis.
156         /// </summary>
157         /// <since_tizen> 3 </since_tizen>
158         public static Vector2 NegativeYAxis
159         {
160             get
161             {
162                 global::System.IntPtr cPtr = Interop.Vector2.Vector2_NEGATIVE_YAXIS_get();
163                 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
164                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
165                 return ret;
166             }
167         }
168
169         /// <summary>
170         /// (0.0f, 0.0f).
171         /// </summary>
172         /// <since_tizen> 3 </since_tizen>
173         public static Vector2 Zero
174         {
175             get
176             {
177                 global::System.IntPtr cPtr = Interop.Vector2.Vector2_ZERO_get();
178                 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
179                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
180                 return ret;
181             }
182         }
183
184         /// <summary>
185         /// The x component.
186         /// </summary>
187         /// <since_tizen> 3 </since_tizen>
188         public float X
189         {
190             set
191             {
192                 Interop.Vector2.Vector2_X_set(swigCPtr, value);
193                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194             }
195             get
196             {
197                 float ret = Interop.Vector2.Vector2_X_get(swigCPtr);
198                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199                 return ret;
200             }
201         }
202
203         /// <summary>
204         /// The width.
205         /// </summary>
206         /// <since_tizen> 3 </since_tizen>
207         public float Width
208         {
209             set
210             {
211                 Interop.Vector2.Vector2_Width_set(swigCPtr, value);
212                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213             }
214             get
215             {
216                 float ret = Interop.Vector2.Vector2_Width_get(swigCPtr);
217                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
218                 return ret;
219             }
220         }
221
222         /// <summary>
223         /// The y component.
224         /// </summary>
225         /// <since_tizen> 3 </since_tizen>
226         public float Y
227         {
228             set
229             {
230                 Interop.Vector2.Vector2_Y_set(swigCPtr, value);
231                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
232             }
233             get
234             {
235                 float ret = Interop.Vector2.Vector2_Y_get(swigCPtr);
236                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237                 return ret;
238             }
239         }
240
241         /// <summary>
242         /// The height.
243         /// </summary>
244         /// <since_tizen> 3 </since_tizen>
245         public float Height
246         {
247             set
248             {
249                 Interop.Vector2.Vector2_Height_set(swigCPtr, value);
250                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
251             }
252             get
253             {
254                 float ret = Interop.Vector2.Vector2_Height_get(swigCPtr);
255                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256                 return ret;
257             }
258         }
259
260         /// <summary>
261         /// The array subscript operator overload.
262         /// </summary>
263         /// <param name="index">The subscript index.</param>
264         /// <returns>The float at the given index.</returns>
265         /// <since_tizen> 3 </since_tizen>
266         public float this[uint index]
267         {
268             get
269             {
270                 return ValueOfIndex(index);
271             }
272         }
273
274         /// <summary>
275         /// The addition operator.
276         /// </summary>
277         /// <param name="arg1">The first value.</param>
278         /// <param name="arg2">The second value.</param>
279         /// <returns>The vector containing the result of the addition.</returns>
280         /// <since_tizen> 3 </since_tizen>
281         public static Vector2 operator +(Vector2 arg1, Vector2 arg2)
282         {
283             return arg1.Add(arg2);
284         }
285
286         /// <summary>
287         /// The subtraction operator.
288         /// </summary>
289         /// <param name="arg1">The first value.</param>
290         /// <param name="arg2">The second value.</param>
291         /// <returns>The vector containing the result of the subtraction.</returns>
292         /// <since_tizen> 3 </since_tizen>
293         public static Vector2 operator -(Vector2 arg1, Vector2 arg2)
294         {
295             return arg1.Subtract(arg2);
296         }
297
298         /// <summary>
299         /// The unary negation operator.
300         /// </summary>
301         /// <param name="arg1">The target value.</param>
302         /// <returns>The vector containing the negation.</returns>
303         /// <since_tizen> 3 </since_tizen>
304         public static Vector2 operator -(Vector2 arg1)
305         {
306             return arg1.Subtract();
307         }
308
309         /// <summary>
310         /// The multiplication operator.
311         /// </summary>
312         /// <param name="arg1">The first value.</param>
313         /// <param name="arg2">The second value.</param>
314         /// <returns>The vector containing the result of the multiplication.</returns>
315         /// <since_tizen> 3 </since_tizen>
316         public static Vector2 operator *(Vector2 arg1, Vector2 arg2)
317         {
318             return arg1.Multiply(arg2);
319         }
320
321         /// <summary>
322         /// Th multiplication operator.
323         /// </summary>
324         /// <param name="arg1">The first value.</param>
325         /// <param name="arg2">The float value to scale the vector.</param>
326         /// <returns>The vector containing the result of the scaling.</returns>
327         /// <since_tizen> 3 </since_tizen>
328         public static Vector2 operator *(Vector2 arg1, float arg2)
329         {
330             return arg1.Multiply(arg2);
331         }
332
333         /// <summary>
334         /// The division operator.
335         /// </summary>
336         /// <param name="arg1">The first value.</param>
337         /// <param name="arg2">The second value.</param>
338         /// <returns>The vector containing the result of the division.</returns>
339         /// <since_tizen> 3 </since_tizen>
340         public static Vector2 operator /(Vector2 arg1, Vector2 arg2)
341         {
342             return arg1.Divide(arg2);
343         }
344
345         /// <summary>
346         /// Th division operator.
347         /// </summary>
348         /// <param name="arg1">The first value.</param>
349         /// <param name="arg2">The float value to scale the vector by.</param>
350         /// <returns>The vector containing the result of the scaling.</returns>
351         /// <since_tizen> 3 </since_tizen>
352         public static Vector2 operator /(Vector2 arg1, float arg2)
353         {
354             return arg1.Divide(arg2);
355         }
356
357         /// <summary>
358         /// Determines whether the specified object is equal to the current object.
359         /// </summary>
360         /// <param name="obj">The object to compare with the current object.</param>
361         /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
362         public override bool Equals(System.Object obj)
363         {
364             Vector2 vector2 = obj as Vector2;
365             bool equal = false;
366             if (X == vector2?.X && Y == vector2?.Y)
367             {
368                 equal = true;
369             }
370             return equal;
371         }
372
373         /// <summary>
374         /// Gets the the hash code of this Vector2.
375         /// </summary>
376         /// <returns>The Hash Code.</returns>
377         /// <since_tizen> 6 </since_tizen>
378         public override int GetHashCode()
379         {
380             return swigCPtr.Handle.GetHashCode();
381         }
382
383         /// <summary>
384         /// Returns the length of the vector.
385         /// </summary>
386         /// <returns>The length of the vector.</returns>
387         /// <since_tizen> 3 </since_tizen>
388         public float Length()
389         {
390             float ret = Interop.Vector2.Vector2_Length(swigCPtr);
391             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
392             return ret;
393         }
394
395         /// <summary>
396         /// Returns the length of the vector squared.<br />
397         /// This is more efficient than Length() for threshold
398         /// testing as it avoids the use of a square root.<br />
399         /// </summary>
400         /// <returns>The length of the vector squared</returns>
401         /// <since_tizen> 3 </since_tizen>
402         public float LengthSquared()
403         {
404             float ret = Interop.Vector2.Vector2_LengthSquared(swigCPtr);
405             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
406             return ret;
407         }
408
409         /// <summary>
410         /// Sets the vector to be the unit length, whilst maintaining its direction.
411         /// </summary>
412         /// <since_tizen> 3 </since_tizen>
413         public void Normalize()
414         {
415             Interop.Vector2.Vector2_Normalize(swigCPtr);
416             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
417         }
418
419         /// <summary>
420         /// Clamps the vector between minimum and maximum vectors.
421         /// </summary>
422         /// <param name="min">The minimum vector.</param>
423         /// <param name="max">The maximum vector.</param>
424         /// <since_tizen> 3 </since_tizen>
425         public void Clamp(Vector2 min, Vector2 max)
426         {
427             Interop.Vector2.Vector2_Clamp(swigCPtr, Vector2.getCPtr(min), Vector2.getCPtr(max));
428             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
429         }
430
431         internal static Vector2 GetVector2FromPtr(global::System.IntPtr cPtr)
432         {
433             Vector2 ret = new Vector2(cPtr, false);
434             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
435             return ret;
436         }
437
438         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Vector2 obj)
439         {
440             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
441         }
442
443         internal SWIGTYPE_p_float AsFloat()
444         {
445             global::System.IntPtr cPtr = Interop.Vector2.Vector2_AsFloat__SWIG_0(swigCPtr);
446             SWIGTYPE_p_float ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_float(cPtr, false);
447             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
448             return ret;
449         }
450
451         /// <summary>
452         /// Dispose.
453         /// </summary>
454         /// <param name="type">The dispose type</param>
455         /// <since_tizen> 3 </since_tizen>
456         protected override void Dispose(DisposeTypes type)
457         {
458             if (disposed)
459             {
460                 return;
461             }
462
463             //Release your own unmanaged resources here.
464             //You should not access any managed member here except static instance.
465             //because the execution order of Finalizes is non-deterministic.
466
467             if (swigCPtr.Handle != global::System.IntPtr.Zero)
468             {
469                 if (swigCMemOwn)
470                 {
471                     swigCMemOwn = false;
472                     Interop.Vector2.delete_Vector2(swigCPtr);
473                 }
474                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
475             }
476             base.Dispose(type);
477         }
478
479         private Vector2 Add(Vector2 rhs)
480         {
481             Vector2 ret = new Vector2(Interop.Vector2.Vector2_Add(swigCPtr, Vector2.getCPtr(rhs)), true);
482             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
483             return ret;
484         }
485
486         private Vector2 AddAssign(Vector2 rhs)
487         {
488             Vector2 ret = new Vector2(Interop.Vector2.Vector2_AddAssign(swigCPtr, Vector2.getCPtr(rhs)), false);
489             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
490             return ret;
491         }
492
493         private Vector2 Subtract(Vector2 rhs)
494         {
495             Vector2 ret = new Vector2(Interop.Vector2.Vector2_Subtract__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
496             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
497             return ret;
498         }
499
500         private Vector2 SubtractAssign(Vector2 rhs)
501         {
502             Vector2 ret = new Vector2(Interop.Vector2.Vector2_SubtractAssign(swigCPtr, Vector2.getCPtr(rhs)), false);
503             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
504             return ret;
505         }
506
507         private Vector2 Multiply(Vector2 rhs)
508         {
509             Vector2 ret = new Vector2(Interop.Vector2.Vector2_Multiply__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
510             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
511             return ret;
512         }
513
514         private Vector2 Multiply(float rhs)
515         {
516             Vector2 ret = new Vector2(Interop.Vector2.Vector2_Multiply__SWIG_1(swigCPtr, rhs), true);
517             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
518             return ret;
519         }
520
521         private Vector2 MultiplyAssign(Vector2 rhs)
522         {
523             Vector2 ret = new Vector2(Interop.Vector2.Vector2_MultiplyAssign__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), false);
524             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
525             return ret;
526         }
527
528         private Vector2 MultiplyAssign(float rhs)
529         {
530             Vector2 ret = new Vector2(Interop.Vector2.Vector2_MultiplyAssign__SWIG_1(swigCPtr, rhs), false);
531             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
532             return ret;
533         }
534
535         private Vector2 Divide(Vector2 rhs)
536         {
537             Vector2 ret = new Vector2(Interop.Vector2.Vector2_Divide__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), true);
538             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
539             return ret;
540         }
541
542         private Vector2 Divide(float rhs)
543         {
544             Vector2 ret = new Vector2(Interop.Vector2.Vector2_Divide__SWIG_1(swigCPtr, rhs), true);
545             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
546             return ret;
547         }
548
549         private Vector2 DivideAssign(Vector2 rhs)
550         {
551             Vector2 ret = new Vector2(Interop.Vector2.Vector2_DivideAssign__SWIG_0(swigCPtr, Vector2.getCPtr(rhs)), false);
552             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
553             return ret;
554         }
555
556         private Vector2 DivideAssign(float rhs)
557         {
558             Vector2 ret = new Vector2(Interop.Vector2.Vector2_DivideAssign__SWIG_1(swigCPtr, rhs), false);
559             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
560             return ret;
561         }
562
563         private Vector2 Subtract()
564         {
565             Vector2 ret = new Vector2(Interop.Vector2.Vector2_Subtract__SWIG_1(swigCPtr), true);
566             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
567             return ret;
568         }
569
570         private bool EqualTo(Vector2 rhs)
571         {
572             bool ret = Interop.Vector2.Vector2_EqualTo(swigCPtr, Vector2.getCPtr(rhs));
573             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
574             return ret;
575         }
576
577         private bool NotEqualTo(Vector2 rhs)
578         {
579             bool ret = Interop.Vector2.Vector2_NotEqualTo(swigCPtr, Vector2.getCPtr(rhs));
580             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
581             return ret;
582         }
583
584         private float ValueOfIndex(uint index)
585         {
586             float ret = Interop.Vector2.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
587             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
588             return ret;
589         }
590
591     }
592
593 }